You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2010/09/10 20:59:48 UTC
svn commit: r995932 - in /subversion/trunk/subversion: libsvn_fs_fs/fs_fs.c
libsvn_subr/io.c libsvn_subr/svn_string.c
Author: stsp
Date: Fri Sep 10 18:59:48 2010
New Revision: 995932
URL: http://svn.apache.org/viewvc?rev=995932&view=rev
Log:
Tighten input validation of the svn_cstring number conversion API.
Before this change, input such as "42foo" was converted to the number 42.
Now, only the NUL-terminated string "42" will convert to 42.
Strings like "42foo" are rejected with an error. Adjust a few callers who
were expecting the number conversion API to accept numbers with trailing
characters, such as newlines.
* subversion/libsvn_subr/svn_string.c
(svn_cstring_strtoui64, svn_cstring_strtoi64): Improve input verification,
reject strings don't parse as a valid number.
If apr_strtoi64() sets errno to indicate overflow, return an "out of range"
error message, rather than "could not convert into number".
* subversion/libsvn_subr/io.c
(svn_io_read_version_file): NUL-terminate string for svn_cstring_atoi().
* subversion/libsvn_fs_fs/fs_fs.c
(get_root_changes_offset): NUL-terminate strings for svn_cstring_atoi64().
Modified:
subversion/trunk/subversion/libsvn_fs_fs/fs_fs.c
subversion/trunk/subversion/libsvn_subr/io.c
subversion/trunk/subversion/libsvn_subr/svn_string.c
Modified: subversion/trunk/subversion/libsvn_fs_fs/fs_fs.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_fs_fs/fs_fs.c?rev=995932&r1=995931&r2=995932&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_fs_fs/fs_fs.c (original)
+++ subversion/trunk/subversion/libsvn_fs_fs/fs_fs.c Fri Sep 10 18:59:48 2010
@@ -2615,6 +2615,7 @@ get_root_changes_offset(apr_off_t *root_
apr_off_t rev_offset;
char buf[64];
int i, num_bytes;
+ const char *str;
apr_size_t len;
apr_seek_where_t seek_relative;
@@ -2681,14 +2682,7 @@ get_root_changes_offset(apr_off_t *root_
}
i++;
-
- if (root_offset)
- {
- apr_int64_t val;
-
- SVN_ERR(svn_cstring_atoi64(&val, &buf[i]));
- *root_offset = rev_offset + (apr_off_t)val;
- }
+ str = &buf[i];
/* find the next space */
for ( ; i < (num_bytes - 2) ; i++)
@@ -2699,16 +2693,29 @@ get_root_changes_offset(apr_off_t *root_
return svn_error_create(SVN_ERR_FS_CORRUPT, NULL,
_("Final line in revision file missing space"));
+ if (root_offset)
+ {
+ apr_int64_t val;
+
+ buf[i] = '\0';
+ SVN_ERR(svn_cstring_atoi64(&val, str));
+ *root_offset = rev_offset + (apr_off_t)val;
+ }
+
i++;
+ str = &buf[i];
+
+ /* find the next newline */
+ for ( ; i < num_bytes; i++)
+ if (buf[i] == '\n')
+ break;
- /* note that svn_cstring_atoi64() (actually, apr_atoi64()) will stop
- * reading as soon as it encounters the final newline.
- * ### Is it OK to rely on this APR implementation detail? */
if (changes_offset)
{
apr_int64_t val;
- SVN_ERR(svn_cstring_atoi64(&val, &buf[i]));
+ buf[i] = '\0';
+ SVN_ERR(svn_cstring_atoi64(&val, str));
*changes_offset = rev_offset + (apr_off_t)val;
}
Modified: subversion/trunk/subversion/libsvn_subr/io.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/io.c?rev=995932&r1=995931&r2=995932&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/io.c (original)
+++ subversion/trunk/subversion/libsvn_subr/io.c Fri Sep 10 18:59:48 2010
@@ -3477,7 +3477,10 @@ svn_io_read_version_file(int *version,
char c = buf[i];
if (i > 0 && (c == '\r' || c == '\n'))
- break;
+ {
+ buf[i] = '\0';
+ break;
+ }
if (! svn_ctype_isdigit(c))
return svn_error_createf
(SVN_ERR_BAD_VERSION_FILE_FORMAT, NULL,
Modified: subversion/trunk/subversion/libsvn_subr/svn_string.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/svn_string.c?rev=995932&r1=995931&r2=995932&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/svn_string.c (original)
+++ subversion/trunk/subversion/libsvn_subr/svn_string.c Fri Sep 10 18:59:48 2010
@@ -622,14 +622,15 @@ svn_cstring_strtoui64(apr_uint64_t *n, c
errno = 0; /* APR-0.9 doesn't always set errno */
/* ### We're throwing away half the number range here.
- * ### Maybe implement our own number parser? */
+ * ### APR needs a apr_strtoui64() function. */
val = apr_strtoi64(str, &endptr, base);
- if (errno != 0 || endptr == str)
+ if (endptr == str || str[0] == '\0' || *endptr != '\0')
return svn_error_return(
svn_error_createf(SVN_ERR_INCORRECT_PARAMS, NULL,
_("Could not convert '%s' into a number"),
str));
- if (val < 0 || (apr_uint64_t)val < minval || (apr_uint64_t)val > maxval)
+ if ((errno == ERANGE && (val == APR_INT64_MIN || val == APR_INT64_MAX)) ||
+ val < 0 || (apr_uint64_t)val < minval || (apr_uint64_t)val > maxval)
return svn_error_return(
svn_error_createf(SVN_ERR_INCORRECT_PARAMS, NULL,
_("Number '%s' is out of range"), str));
@@ -666,12 +667,13 @@ svn_cstring_strtoi64(apr_int64_t *n, con
errno = 0; /* APR-0.9 doesn't always set errno */
val = apr_strtoi64(str, &endptr, base);
- if (errno != 0 || endptr == str)
+ if (endptr == str || str[0] == '\0' || *endptr != '\0')
return svn_error_return(
svn_error_createf(SVN_ERR_INCORRECT_PARAMS, NULL,
_("Could not convert '%s' into a number"),
str));
- if (val < minval || val > maxval)
+ if ((errno == ERANGE && (val == APR_INT64_MIN || val == APR_INT64_MAX)) ||
+ val < minval || val > maxval)
return svn_error_return(
svn_error_createf(SVN_ERR_INCORRECT_PARAMS, NULL,
_("Number '%s' is out of range"), str));