]> Savannah Git Hosting - gnulib.git/commitdiff
canonicalize: fix size overflow treatment
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 30 Dec 2020 03:34:59 +0000 (19:34 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 30 Dec 2020 03:35:40 +0000 (19:35 -0800)
This also has some minor cleanups.
* lib/canonicalize-lgpl.c, lib/canonicalize.c: No need to include
stddef.h, since the code no longer refers directly to ptrdiff_t.
* lib/canonicalize-lgpl.c (realpath_stk):
* lib/canonicalize.c (canonicalize_filename_mode_stk):
Treat size overflow like other out-of-memory.
* lib/canonicalize.c: No need to include stdlib.h, since
the code no longer refers to stdlib.h functions (other
than those that canonicalize.h must declare).
* lib/canonicalize.c (canonicalize_filename_mode_stk):
Do not bother terminating the string result on error.

ChangeLog
lib/canonicalize-lgpl.c
lib/canonicalize.c

index cca14c910415e17f376d0325565567bcc3efa69d..2af7a42c79001724f04a59abfd3fd7e6aadd2769 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2020-12-29  Paul Eggert  <eggert@cs.ucla.edu>
+
+       canonicalize: fix size overflow treatment
+       This also has some minor cleanups.
+       * lib/canonicalize-lgpl.c, lib/canonicalize.c: No need to include
+       stddef.h, since the code no longer refers directly to ptrdiff_t.
+       * lib/canonicalize-lgpl.c (realpath_stk):
+       * lib/canonicalize.c (canonicalize_filename_mode_stk):
+       Treat size overflow like other out-of-memory.
+       * lib/canonicalize.c: No need to include stdlib.h, since
+       the code no longer refers to stdlib.h functions (other
+       than those that canonicalize.h must declare).
+       * lib/canonicalize.c (canonicalize_filename_mode_stk):
+       Do not bother terminating the string result on error.
+
 2020-12-29  Bruno Haible  <bruno@clisp.org>
 
        list-c++, [o]map-c++, [o]set-c++: Fix conflict with 'free-posix' module.
index e8b10f0e7d150bf7ce054f21c648fce681f8b6f9..01b06322dde9f0196a043150ec9594774e1f56ed 100644 (file)
@@ -32,7 +32,6 @@
 #include <fcntl.h>
 #include <limits.h>
 #include <stdbool.h>
-#include <stddef.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -345,10 +344,7 @@ realpath_stk (const char *name, char *resolved,
                 end_idx = end - extra_buf;
               size_t len = strlen (end);
               if (NARROW_ADDRESSES && INT_ADD_OVERFLOW (len, n))
-                {
-                  __set_errno (ENOMEM);
-                  goto error;
-                }
+                goto error_nomem;
               while (extra_buffer.length <= len + n)
                 {
                   if (!scratch_buffer_grow_preserve (&extra_buffer))
index eee3dbee6e062562c6e9fbb88a7867dda9ab5853..26066831c7415d4add40b8480172d12fcb9adfa1 100644 (file)
@@ -21,8 +21,6 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <stdbool.h>
-#include <stddef.h>
-#include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -396,10 +394,7 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
                 end_idx = end - extra_buf;
               size_t len = strlen (end);
               if (NARROW_ADDRESSES && INT_ADD_OVERFLOW (len, n))
-                {
-                  errno = ENOMEM;
-                  goto error;
-                }
+                xalloc_die ();
               while (extra_buffer.length <= len + n)
                 {
                   if (!scratch_buffer_grow_preserve (&extra_buffer))
@@ -461,7 +456,6 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
   failed = false;
 
 error:
-  *dest++ = '\0';
   if (ht)
     hash_free (ht);
   scratch_buffer_free (&extra_buffer);
@@ -473,6 +467,7 @@ error:
       return NULL;
     }
 
+  *dest++ = '\0';
   char *result = scratch_buffer_dupfree (rname_buf, dest - rname);
   if (!result)
     xalloc_die ();