]> Savannah Git Hosting - gnulib.git/commitdiff
file-has-acl: minor ENOMEM fixes
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 7 Nov 2024 17:37:17 +0000 (09:37 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 7 Nov 2024 19:45:02 +0000 (11:45 -0800)
* lib/file-has-acl.c: Include limits.h.
(get_aclinfo): Use a saturating add rather than reporting
overflow, in the very unlikely case that the size overflows.
This is simpler and is good enough here.
Also, defend against implausible system that fails with ERANGE
even when the buffer size is SSIZE_MAX.
(file_has_aclinfo): Since we already assume elsewhere that
malloc sets errno, rely on that here too.
* modules/file-has-acl (Depends-on): Add limits.h.
Also add malloc-posix, since we rely on malloc errno.

ChangeLog
lib/file-has-acl.c
modules/file-has-acl

index 2bcee7d3f61a7997011cb66399bb628248243479..e881e194dcddbb4d842a622763722d310dc87d2e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2024-11-07  Paul Eggert  <eggert@cs.ucla.edu>
 
+       file-has-acl: minor ENOMEM fixes
+       * lib/file-has-acl.c: Include limits.h.
+       (get_aclinfo): Use a saturating add rather than reporting
+       overflow, in the very unlikely case that the size overflows.
+       This is simpler and is good enough here.
+       Also, defend against implausible system that fails with ERANGE
+       even when the buffer size is SSIZE_MAX.
+       * modules/file-has-acl (Depends-on): Add limits.h.
+       Also add malloc-posix, since we rely on malloc errno.
+
        file-has-acl: remove __gl_acl_alloc member
        It may have been needed in earlier versions of this code,
        but it is no longer needed.
index a436793388357190f2ebba79aefab12fe5e45042..980c20249ae05ea1e2fb1512d41e12a229331b49 100644 (file)
@@ -28,6 +28,7 @@
 #include "acl.h"
 
 #include <dirent.h>
+#include <limits.h>
 
 #include "acl-internal.h"
 #include "attribute.h"
@@ -125,7 +126,7 @@ get_aclinfo (char const *name, struct aclinfo *ai, int flags)
       if (0 < ai->size)
         break;
       ai->u.err = ai->size < 0 ? errno : 0;
-      if (! (ai->size < 0 && ai->u.err == ERANGE))
+      if (! (ai->size < 0 && ai->u.err == ERANGE && acl_alloc < SSIZE_MAX))
         break;
 
       /* The buffer was too small.  Find how large it should have been.  */
@@ -146,10 +147,7 @@ get_aclinfo (char const *name, struct aclinfo *ai, int flags)
           ai->buf = ai->u.__gl_acl_ch;
         }
       if (ckd_add (&acl_alloc, acl_alloc, acl_alloc >> 1))
-        {
-          ai->u.err = ENOMEM;
-          break;
-        }
+        acl_alloc = SSIZE_MAX;
       if (acl_alloc < size)
         acl_alloc = size;
       if (SIZE_MAX < acl_alloc)
@@ -543,10 +541,7 @@ file_has_aclinfo (MAYBE_UNUSED char const *restrict name,
                 entries = malloced =
                   (aclent_t *) malloc (alloc * sizeof (aclent_t));
                 if (entries == NULL)
-                  {
-                    errno = ENOMEM;
-                    return -1;
-                  }
+                  return -1;
                 continue;
               }
             break;
@@ -616,10 +611,7 @@ file_has_aclinfo (MAYBE_UNUSED char const *restrict name,
                 alloc = 2 * alloc; /* <= alloc_max */
                 entries = malloced = (ace_t *) malloc (alloc * sizeof (ace_t));
                 if (entries == NULL)
-                  {
-                    errno = ENOMEM;
-                    return -1;
-                  }
+                  return -1;
                 continue;
               }
             break;
@@ -773,10 +765,7 @@ file_has_aclinfo (MAYBE_UNUSED char const *restrict name,
             free (acl);
           acl = malloc (aclsize);
           if (acl == NULL)
-            {
-              errno = ENOMEM;
-              return -1;
-            }
+            return -1;
         }
 
       if (type.u64 == ACL_AIXC)
index b5821dab005505fdd6c66fc66fc1b98c29ba2898..2fac2027da93099b6e921ff5fcbc60b27650809a 100644 (file)
@@ -16,6 +16,8 @@ errno
 extern-inline
 minmax
 free-posix
+limits-h
+malloc-posix
 ssize_t
 stat
 stdbool