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.
#include "acl.h"
#include <dirent.h>
+#include <limits.h>
#include "acl-internal.h"
#include "attribute.h"
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. */
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)
entries = malloced =
(aclent_t *) malloc (alloc * sizeof (aclent_t));
if (entries == NULL)
- {
- errno = ENOMEM;
- return -1;
- }
+ return -1;
continue;
}
break;
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;
free (acl);
acl = malloc (aclsize);
if (acl == NULL)
- {
- errno = ENOMEM;
- return -1;
- }
+ return -1;
}
if (type.u64 == ACL_AIXC)