diff options
Diffstat (limited to 'subversion/libsvn_subr')
-rw-r--r-- | subversion/libsvn_subr/auth.c | 4 | ||||
-rw-r--r-- | subversion/libsvn_subr/cache-membuffer.c | 37 | ||||
-rw-r--r-- | subversion/libsvn_subr/eol.c | 17 | ||||
-rw-r--r-- | subversion/libsvn_subr/gpg_agent.c | 38 | ||||
-rw-r--r-- | subversion/libsvn_subr/internal_statements.h | 2 | ||||
-rw-r--r-- | subversion/libsvn_subr/prompt.c | 3 | ||||
-rw-r--r-- | subversion/libsvn_subr/sqlite.c | 1 | ||||
-rw-r--r-- | subversion/libsvn_subr/string.c | 4 | ||||
-rw-r--r-- | subversion/libsvn_subr/utf_validate.c | 79 | ||||
-rw-r--r-- | subversion/libsvn_subr/version.c | 2 |
10 files changed, 60 insertions, 127 deletions
diff --git a/subversion/libsvn_subr/auth.c b/subversion/libsvn_subr/auth.c index 2cd83c4ca13a4..303c41e5cc05f 100644 --- a/subversion/libsvn_subr/auth.c +++ b/subversion/libsvn_subr/auth.c @@ -371,7 +371,9 @@ svn_auth_next_credentials(void **credentials, if (creds != NULL) { /* Put the creds in the cache */ - svn_hash_sets(auth_baton->creds_cache, state->cache_key, creds); + svn_hash_sets(auth_baton->creds_cache, + apr_pstrdup(auth_baton->pool, state->cache_key), + creds); break; } diff --git a/subversion/libsvn_subr/cache-membuffer.c b/subversion/libsvn_subr/cache-membuffer.c index 8aeaf775d7714..87ac96168b0fd 100644 --- a/subversion/libsvn_subr/cache-membuffer.c +++ b/subversion/libsvn_subr/cache-membuffer.c @@ -139,6 +139,10 @@ #endif /* For more efficient copy operations, let's align all data items properly. + * Since we can't portably align pointers, this is rather the item size + * granularity which ensures *relative* alignment within the cache - still + * giving us decent copy speeds on most machines. + * * Must be a power of 2. */ #define ITEM_ALIGNMENT 16 @@ -632,10 +636,6 @@ struct svn_membuffer_t */ #define ALIGN_VALUE(value) (((value) + ITEM_ALIGNMENT-1) & -ITEM_ALIGNMENT) -/* Align POINTER value to the next ITEM_ALIGNMENT boundary. - */ -#define ALIGN_POINTER(pointer) ((void*)ALIGN_VALUE((apr_size_t)(char*)(pointer))) - /* If locking is supported for CACHE, acquire a read lock for it. */ static svn_error_t * @@ -1643,28 +1643,6 @@ ensure_data_insertable_l1(svn_membuffer_t *cache, apr_size_t size) * right answer. */ } -/* Mimic apr_pcalloc in APR_POOL_DEBUG mode, i.e. handle failed allocations - * (e.g. OOM) properly: Allocate at least SIZE bytes from POOL and zero - * the content of the allocated memory if ZERO has been set. Return NULL - * upon failed allocations. - * - * Also, satisfy our buffer alignment needs for performance reasons. - */ -static void* secure_aligned_alloc(apr_pool_t *pool, - apr_size_t size, - svn_boolean_t zero) -{ - void* memory = apr_palloc(pool, size + ITEM_ALIGNMENT); - if (memory != NULL) - { - memory = ALIGN_POINTER(memory); - if (zero) - memset(memory, 0, size); - } - - return memory; -} - svn_error_t * svn_cache__membuffer_cache_create(svn_membuffer_t **cache, apr_size_t total_size, @@ -1822,10 +1800,11 @@ svn_cache__membuffer_cache_create(svn_membuffer_t **cache, c[seg].l2.last = NO_INDEX; c[seg].l2.next = NO_INDEX; c[seg].l2.start_offset = c[seg].l1.size; - c[seg].l2.size = data_size - c[seg].l1.size; + c[seg].l2.size = ALIGN_VALUE(data_size) - c[seg].l1.size; c[seg].l2.current_data = c[seg].l2.start_offset; - c[seg].data = secure_aligned_alloc(pool, (apr_size_t)data_size, FALSE); + /* This cast is safe because DATA_SIZE <= MAX_SEGMENT_SIZE. */ + c[seg].data = apr_palloc(pool, (apr_size_t)ALIGN_VALUE(data_size)); c[seg].data_used = 0; c[seg].max_entry_size = max_entry_size; @@ -2204,7 +2183,7 @@ membuffer_cache_get_internal(svn_membuffer_t *cache, } size = ALIGN_VALUE(entry->size) - entry->key.key_len; - *buffer = ALIGN_POINTER(apr_palloc(result_pool, size + ITEM_ALIGNMENT-1)); + *buffer = apr_palloc(result_pool, size); memcpy(*buffer, cache->data + entry->offset + entry->key.key_len, size); #ifdef SVN_DEBUG_CACHE_MEMBUFFER diff --git a/subversion/libsvn_subr/eol.c b/subversion/libsvn_subr/eol.c index 417d90aaae46e..e63cf1113577c 100644 --- a/subversion/libsvn_subr/eol.c +++ b/subversion/libsvn_subr/eol.c @@ -33,20 +33,7 @@ char * svn_eol__find_eol_start(char *buf, apr_size_t len) { -#if !SVN_UNALIGNED_ACCESS_IS_OK - - /* On some systems, we need to make sure that BUF is properly aligned - * for chunky data access. This overhead is still justified because - * only lines tend to be tens of chars long. - */ - for (; (len > 0) && ((apr_uintptr_t)buf) & (sizeof(apr_uintptr_t)-1) - ; ++buf, --len) - { - if (*buf == '\n' || *buf == '\r') - return buf; - } - -#endif +#if SVN_UNALIGNED_ACCESS_IS_OK /* Scan the input one machine word at a time. */ for (; len > sizeof(apr_uintptr_t) @@ -71,6 +58,8 @@ svn_eol__find_eol_start(char *buf, apr_size_t len) break; } +#endif + /* The remaining odd bytes will be examined the naive way: */ for (; len > 0; ++buf, --len) { diff --git a/subversion/libsvn_subr/gpg_agent.c b/subversion/libsvn_subr/gpg_agent.c index 96021c52ec854..d53eec44c28f2 100644 --- a/subversion/libsvn_subr/gpg_agent.c +++ b/subversion/libsvn_subr/gpg_agent.c @@ -103,6 +103,40 @@ escape_blanks(char *str) return str; } +#define is_hex(c) (((c) >= '0' && (c) <= '9') || ((c) >= 'A' && (c) <= 'F')) +#define hex_to_int(c) ((c) < '9' ? (c) - '0' : (c) - 'A' + 10) + +/* Modify STR in-place. '%', CR and LF are always percent escaped, + other characters may be percent escaped, always using uppercase + hex, see https://www.gnupg.org/documentation/manuals/assuan.pdf */ +static char * +unescape_assuan(char *str) +{ + char *s = str; + + while (s[0]) + { + if (s[0] == '%' && is_hex(s[1]) && is_hex(s[2])) + { + char *s2 = s; + char val = hex_to_int(s[1]) * 16 + hex_to_int(s[2]); + + s2[0] = val; + ++s2; + + while (s2[2]) + { + s2[0] = s2[2]; + ++s2; + } + s2[0] = '\0'; + } + ++s; + } + + return str; +} + /* Generate the string CACHE_ID_P based on the REALMSTRING allocated in * RESULT_POOL using SCRATCH_POOL for temporary allocations. This is similar * to other password caching mechanisms. */ @@ -379,7 +413,7 @@ password_get_gpg_agent(svn_boolean_t *done, apr_pool_t *pool) { int sd; - const char *p = NULL; + char *p = NULL; char *ep = NULL; char *buffer; const char *request = NULL; @@ -452,7 +486,7 @@ password_get_gpg_agent(svn_boolean_t *done, if (ep != NULL) *ep = '\0'; - *password = p; + *password = unescape_assuan(p); *done = TRUE; return SVN_NO_ERROR; diff --git a/subversion/libsvn_subr/internal_statements.h b/subversion/libsvn_subr/internal_statements.h index 3c8e4599c8da1..93251a47e997d 100644 --- a/subversion/libsvn_subr/internal_statements.h +++ b/subversion/libsvn_subr/internal_statements.h @@ -1,4 +1,4 @@ -/* This file is automatically generated from internal_statements.sql and .dist_sandbox/subversion-1.9.2/subversion/libsvn_subr/token-map.h. +/* This file is automatically generated from internal_statements.sql and .dist_sandbox/subversion-1.9.4/subversion/libsvn_subr/token-map.h. * Do not edit this file -- edit the source and rerun gen-make.py */ #define STMT_INTERNAL_SAVEPOINT_SVN 0 diff --git a/subversion/libsvn_subr/prompt.c b/subversion/libsvn_subr/prompt.c index e00fa0ce4f713..8f24b424042a2 100644 --- a/subversion/libsvn_subr/prompt.c +++ b/subversion/libsvn_subr/prompt.c @@ -831,9 +831,8 @@ plaintext_prompt_helper(svn_boolean_t *may_save_plaintext, { if (err->apr_err == SVN_ERR_CANCELLED) { - svn_error_clear(err); *may_save_plaintext = FALSE; - return SVN_NO_ERROR; + return err; } else return err; diff --git a/subversion/libsvn_subr/sqlite.c b/subversion/libsvn_subr/sqlite.c index 6dddc8dd22600..18d1c49285581 100644 --- a/subversion/libsvn_subr/sqlite.c +++ b/subversion/libsvn_subr/sqlite.c @@ -1171,6 +1171,7 @@ svn_sqlite__open(svn_sqlite__db_t **db, const char *path, affects application(read: Subversion) performance/behavior. */ "PRAGMA foreign_keys=OFF;" /* SQLITE_DEFAULT_FOREIGN_KEYS*/ "PRAGMA locking_mode = NORMAL;" /* SQLITE_DEFAULT_LOCKING_MODE */ + /* Testing shows TRUNCATE is faster than DELETE on Windows. */ "PRAGMA journal_mode = TRUNCATE;" ), *db); diff --git a/subversion/libsvn_subr/string.c b/subversion/libsvn_subr/string.c index 29176d6d5dc5e..43a1a4ec1802b 100644 --- a/subversion/libsvn_subr/string.c +++ b/subversion/libsvn_subr/string.c @@ -677,7 +677,7 @@ svn_stringbuf_remove(svn_stringbuf_t *str, { if (pos > str->len) pos = str->len; - if (pos + count > str->len) + if (count > str->len - pos) count = str->len - pos; memmove(str->data + pos, str->data + pos + count, str->len - pos - count + 1); @@ -705,7 +705,7 @@ svn_stringbuf_replace(svn_stringbuf_t *str, if (pos > str->len) pos = str->len; - if (pos + old_count > str->len) + if (old_count > str->len - pos) old_count = str->len - pos; if (old_count < new_count) diff --git a/subversion/libsvn_subr/utf_validate.c b/subversion/libsvn_subr/utf_validate.c index 90e529e2ffb2c..0aab81c9172e4 100644 --- a/subversion/libsvn_subr/utf_validate.c +++ b/subversion/libsvn_subr/utf_validate.c @@ -258,24 +258,7 @@ static const char machine [9][14] = { static const char * first_non_fsm_start_char(const char *data, apr_size_t max_len) { -#if !SVN_UNALIGNED_ACCESS_IS_OK - - /* On some systems, we need to make sure that buf is properly aligned - * for chunky data access. - */ - if ((apr_uintptr_t)data & (sizeof(apr_uintptr_t)-1)) - { - apr_size_t len = (~(apr_uintptr_t)data) & (sizeof(apr_uintptr_t)-1); - if (len > max_len) - len = max_len; - max_len -= len; - - for (; len > 0; ++data, --len) - if ((unsigned char)*data >= 0x80) - return data; - } - -#endif +#if SVN_UNALIGNED_ACCESS_IS_OK /* Scan the input one machine word at a time. */ for (; max_len > sizeof(apr_uintptr_t) @@ -283,55 +266,11 @@ first_non_fsm_start_char(const char *data, apr_size_t max_len) if (*(const apr_uintptr_t *)data & SVN__BIT_7_SET) break; - /* The remaining odd bytes will be examined the naive way: */ - for (; max_len > 0; ++data, --max_len) - if ((unsigned char)*data >= 0x80) - break; - - return data; -} - -/* Scan the C string in *DATA for chars that are not in the octet - * category 0 (FSM_START). Return the position of either the such - * char or of the terminating NUL. - */ -static const char * -first_non_fsm_start_char_cstring(const char *data) -{ - /* We need to make sure that BUF is properly aligned for chunky data - * access because we don't know the string's length. Unaligned chunk - * read access beyond the NUL terminator could therefore result in a - * segfault. - */ - for (; (apr_uintptr_t)data & (sizeof(apr_uintptr_t)-1); ++data) - if (*data == 0 || (unsigned char)*data >= 0x80) - return data; - - /* Scan the input one machine word at a time. */ -#ifndef SVN_UTF_NO_UNINITIALISED_ACCESS - /* This may read allocated but uninitialised bytes beyond the - terminating null. Any such bytes are always readable and this - code operates correctly whatever the uninitialised values happen - to be. However memory checking tools such as valgrind and GCC - 4.8's address santitizer will object so this bit of code can be - disabled at compile time. */ - for (; ; data += sizeof(apr_uintptr_t)) - { - /* Check for non-ASCII chars: */ - apr_uintptr_t chunk = *(const apr_uintptr_t *)data; - if (chunk & SVN__BIT_7_SET) - break; - - /* This is the well-known strlen test: */ - chunk |= (chunk & SVN__LOWER_7BITS_SET) + SVN__LOWER_7BITS_SET; - if ((chunk & SVN__BIT_7_SET) != SVN__BIT_7_SET) - break; - } #endif /* The remaining odd bytes will be examined the naive way: */ - for (; ; ++data) - if (*data == 0 || (unsigned char)*data >= 0x80) + for (; max_len > 0; ++data, --max_len) + if ((unsigned char)*data >= 0x80) break; return data; @@ -359,20 +298,10 @@ svn_utf__last_valid(const char *data, apr_size_t len) svn_boolean_t svn_utf__cstring_is_valid(const char *data) { - int state = FSM_START; - if (!data) return FALSE; - data = first_non_fsm_start_char_cstring(data); - - while (*data) - { - unsigned char octet = *data++; - int category = octet_category[octet]; - state = machine[state][category]; - } - return state == FSM_START; + return svn_utf__is_valid(data, strlen(data)); } svn_boolean_t diff --git a/subversion/libsvn_subr/version.c b/subversion/libsvn_subr/version.c index b10330e0b31e1..95cb4d3993795 100644 --- a/subversion/libsvn_subr/version.c +++ b/subversion/libsvn_subr/version.c @@ -136,7 +136,7 @@ svn_version_extended(svn_boolean_t verbose, info->build_time = __TIME__; info->build_host = SVN_BUILD_HOST; info->copyright = apr_pstrdup - (pool, _("Copyright (C) 2015 The Apache Software Foundation.\n" + (pool, _("Copyright (C) 2016 The Apache Software Foundation.\n" "This software consists of contributions made by many people;\n" "see the NOTICE file for more information.\n" "Subversion is open source software, see " |