subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From phi...@apache.org
Subject svn commit: r1460628 - in /subversion/trunk/subversion: libsvn_fs_base/lock.c libsvn_subr/hash.c
Date Mon, 25 Mar 2013 11:52:50 GMT
Author: philip
Date: Mon Mar 25 11:52:50 2013
New Revision: 1460628

URL: http://svn.apache.org/r1460628
Log:
Use svn_cstring_strtoui64 in place of strtoul and ULONG_MAX.  Also
don't serialise negative lengths as part of a hash since we are, and
always been, deserialising as unsigned.

* subversion/libsvn_fs_base/lock.c
  (svn_fs_base__get_locks): Use svn_cstring_strtoui64.

* subversion/libsvn_subr/hash.c
  (hash_read): svn_cstring_strtoui64.
  (hash_write): Don't write negative lengths.

Modified:
    subversion/trunk/subversion/libsvn_fs_base/lock.c
    subversion/trunk/subversion/libsvn_subr/hash.c

Modified: subversion/trunk/subversion/libsvn_fs_base/lock.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_fs_base/lock.c?rev=1460628&r1=1460627&r2=1460628&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_fs_base/lock.c (original)
+++ subversion/trunk/subversion/libsvn_fs_base/lock.c Mon Mar 25 11:52:50 2013
@@ -475,9 +475,11 @@ svn_fs_base__get_locks(svn_fs_t *fs,
   while (1)
     {
       apr_size_t len, skel_len;
-      char c, *end, *skel_buf;
+      char c, *skel_buf;
       svn_skel_t *lock_skel;
       svn_lock_t *lock;
+      apr_uint64_t ui64;
+      svn_error_t *err;
 
       svn_pool_clear(iterpool);
 
@@ -485,9 +487,10 @@ svn_fs_base__get_locks(svn_fs_t *fs,
       SVN_ERR(svn_stream_readline(stream, &buf, "\n", &eof, iterpool));
       if (eof)
         break;
-      skel_len = (size_t) strtoul(buf->data, &end, 10);
-      if (skel_len == (size_t) ULONG_MAX || *end != '\0')
-        return svn_error_create(SVN_ERR_MALFORMED_FILE, NULL, NULL);
+      err = svn_cstring_strtoui64(&ui64, buf->data, 0, APR_SIZE_MAX, 10);
+      if (err)
+        return svn_error_create(SVN_ERR_MALFORMED_FILE, err, NULL);
+      skel_len = (apr_size_t)ui64;
 
       /* Now read that much into a buffer. */
       skel_buf = apr_palloc(pool, skel_len + 1);

Modified: subversion/trunk/subversion/libsvn_subr/hash.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/hash.c?rev=1460628&r1=1460627&r2=1460628&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/hash.c (original)
+++ subversion/trunk/subversion/libsvn_subr/hash.c Mon Mar 25 11:52:50 2013
@@ -96,11 +96,14 @@ hash_read(apr_hash_t *hash, svn_stream_t
   svn_stringbuf_t *buf;
   svn_boolean_t eof;
   apr_size_t len, keylen, vallen;
-  char c, *end, *keybuf, *valbuf;
+  char c, *keybuf, *valbuf;
   apr_pool_t *iterpool = svn_pool_create(pool);
 
   while (1)
     {
+      svn_error_t *err;
+      apr_uint64_t ui64;
+
       svn_pool_clear(iterpool);
 
       /* Read a key length line.  Might be END, though. */
@@ -119,10 +122,12 @@ hash_read(apr_hash_t *hash, svn_stream_t
       if ((buf->len >= 3) && (buf->data[0] == 'K') && (buf->data[1]
== ' '))
         {
           /* Get the length of the key */
-          keylen = (size_t) strtoul(buf->data + 2, &end, 10);
-          if (keylen == (size_t) ULONG_MAX || *end != '\0')
-            return svn_error_create(SVN_ERR_MALFORMED_FILE, NULL,
+          err = svn_cstring_strtoui64(&ui64, buf->data + 2,
+                                      0, APR_SIZE_MAX, 10);
+          if (err)
+            return svn_error_create(SVN_ERR_MALFORMED_FILE, err,
                                     _("Serialized hash malformed"));
+          keylen = (apr_size_t)ui64;
 
           /* Now read that much into a buffer. */
           keybuf = apr_palloc(pool, keylen + 1);
@@ -141,10 +146,12 @@ hash_read(apr_hash_t *hash, svn_stream_t
 
           if ((buf->data[0] == 'V') && (buf->data[1] == ' '))
             {
-              vallen = (size_t) strtoul(buf->data + 2, &end, 10);
-              if (vallen == (size_t) ULONG_MAX || *end != '\0')
-                return svn_error_create(SVN_ERR_MALFORMED_FILE, NULL,
+              err = svn_cstring_strtoui64(&ui64, buf->data + 2,
+                                          0, APR_SIZE_MAX, 10);
+              if (err)
+                return svn_error_create(SVN_ERR_MALFORMED_FILE, err,
                                         _("Serialized hash malformed"));
+              vallen = (apr_size_t)ui64;
 
               valbuf = apr_palloc(iterpool, vallen + 1);
               SVN_ERR(svn_stream_read(stream, valbuf, &vallen));
@@ -169,10 +176,12 @@ hash_read(apr_hash_t *hash, svn_stream_t
                && (buf->data[0] == 'D') && (buf->data[1] == ' '))
         {
           /* Get the length of the key */
-          keylen = (size_t) strtoul(buf->data + 2, &end, 10);
-          if (keylen == (size_t) ULONG_MAX || *end != '\0')
-            return svn_error_create(SVN_ERR_MALFORMED_FILE, NULL,
+          err = svn_cstring_strtoui64(&ui64, buf->data + 2,
+                                      0, APR_SIZE_MAX, 10);
+          if (err)
+            return svn_error_create(SVN_ERR_MALFORMED_FILE, err,
                                     _("Serialized hash malformed"));
+          keylen = (apr_size_t)ui64;
 
           /* Now read that much into a buffer. */
           keybuf = apr_palloc(iterpool, keylen + 1);
@@ -230,11 +239,16 @@ hash_write(apr_hash_t *hash, apr_hash_t 
             continue;
         }
 
+      if (item->klen < 0)
+        return svn_error_create(SVN_ERR_MALFORMED_FILE, NULL,
+                                _("Cannot serialize negative length"));
+
       /* Write it out. */
       SVN_ERR(svn_stream_printf(stream, subpool,
-                                "K %" APR_SSIZE_T_FMT "\n%s\n"
+                                "K %" APR_SIZE_T_FMT "\n%s\n"
                                 "V %" APR_SIZE_T_FMT "\n",
-                                item->klen, (const char *) item->key,
+                                (apr_size_t) item->klen,
+                                (const char *) item->key,
                                 valstr->len));
       len = valstr->len;
       SVN_ERR(svn_stream_write(stream, valstr->data, &len));



Mime
View raw message