o acl_from_text.c:

- errno is already set to ENOMEM (as appropriate) when asprintf(),
    strdup(), or acl_init() fails
o acl_to_text.c:
  - the return value of the initial strdup() is not checked
  - errno is already set to ENOMEM (as appropriate) when asprintf
    and acl_init() fails
  - let the the default: case use 'goto error_label' for consistency

Submitted by:	jedgar
This commit is contained in:
Robert Watson 2001-01-09 05:45:03 +00:00
parent 5db6984b12
commit 2137646abe
4 changed files with 20 additions and 48 deletions

View File

@ -117,15 +117,12 @@ acl_from_text(const char *buf_p)
/* Local copy we can mess up. */
mybuf_p = strdup(buf_p);
if (!mybuf_p) {
errno = ENOMEM;
if (!mybuf_p)
return(0);
}
acl = acl_init(3);
if (!acl) {
free(mybuf_p);
errno = ENOMEM;
return(0);
}

View File

@ -60,6 +60,8 @@ acl_to_text(acl_t acl, ssize_t *len_p)
acl_perm_t ae_perm, effective_perm, mask_perm;
buf = strdup("");
if (!buf)
return(0);
mask_perm = ACL_PERM_BITS; /* effective is regular if no mask */
for (i = 0; i < acl->acl_cnt; i++)
@ -79,10 +81,8 @@ acl_to_text(acl_t acl, ssize_t *len_p)
goto error_label;
len = asprintf(&tmpbuf, "%suser::%s\n", buf,
perm_buf);
if (len == -1) {
errno = ENOMEM;
if (len == -1)
goto error_label;
}
free(buf);
buf = tmpbuf;
break;
@ -113,10 +113,8 @@ acl_to_text(acl_t acl, ssize_t *len_p)
len = asprintf(&tmpbuf, "%suser:%s:%s\n", buf,
name_buf, perm_buf);
}
if (len == -1) {
errno = ENOMEM;
if (len == -1)
goto error_label;
}
free(buf);
buf = tmpbuf;
break;
@ -141,10 +139,8 @@ acl_to_text(acl_t acl, ssize_t *len_p)
len = asprintf(&tmpbuf, "%sgroup::%s\n", buf,
perm_buf);
}
if (len == -1) {
errno = ENOMEM;
if (len == -1)
goto error_label;
}
free(buf);
buf = tmpbuf;
break;
@ -174,10 +170,8 @@ acl_to_text(acl_t acl, ssize_t *len_p)
len = asprintf(&tmpbuf, "%sgroup:%s:%s\n", buf,
name_buf, perm_buf);
}
if (len == -1) {
errno = ENOMEM;
if (len == -1)
goto error_label;
}
free(buf);
buf = tmpbuf;
break;
@ -190,10 +184,8 @@ acl_to_text(acl_t acl, ssize_t *len_p)
len = asprintf(&tmpbuf, "%smask::%s\n", buf,
perm_buf);
if (len == -1) {
errno = ENOMEM;
if (len == -1)
goto error_label;
}
free(buf);
buf = tmpbuf;
break;
@ -206,18 +198,15 @@ acl_to_text(acl_t acl, ssize_t *len_p)
len = asprintf(&tmpbuf, "%sother::%s\n", buf,
perm_buf);
if (len == -1) {
errno = ENOMEM;
if (len == -1)
goto error_label;
}
free(buf);
buf = tmpbuf;
break;
default:
free(buf);
errno = EINVAL;
return (0);
goto error_label;
}
}

View File

@ -117,15 +117,12 @@ acl_from_text(const char *buf_p)
/* Local copy we can mess up. */
mybuf_p = strdup(buf_p);
if (!mybuf_p) {
errno = ENOMEM;
if (!mybuf_p)
return(0);
}
acl = acl_init(3);
if (!acl) {
free(mybuf_p);
errno = ENOMEM;
return(0);
}

View File

@ -60,6 +60,8 @@ acl_to_text(acl_t acl, ssize_t *len_p)
acl_perm_t ae_perm, effective_perm, mask_perm;
buf = strdup("");
if (!buf)
return(0);
mask_perm = ACL_PERM_BITS; /* effective is regular if no mask */
for (i = 0; i < acl->acl_cnt; i++)
@ -79,10 +81,8 @@ acl_to_text(acl_t acl, ssize_t *len_p)
goto error_label;
len = asprintf(&tmpbuf, "%suser::%s\n", buf,
perm_buf);
if (len == -1) {
errno = ENOMEM;
if (len == -1)
goto error_label;
}
free(buf);
buf = tmpbuf;
break;
@ -113,10 +113,8 @@ acl_to_text(acl_t acl, ssize_t *len_p)
len = asprintf(&tmpbuf, "%suser:%s:%s\n", buf,
name_buf, perm_buf);
}
if (len == -1) {
errno = ENOMEM;
if (len == -1)
goto error_label;
}
free(buf);
buf = tmpbuf;
break;
@ -141,10 +139,8 @@ acl_to_text(acl_t acl, ssize_t *len_p)
len = asprintf(&tmpbuf, "%sgroup::%s\n", buf,
perm_buf);
}
if (len == -1) {
errno = ENOMEM;
if (len == -1)
goto error_label;
}
free(buf);
buf = tmpbuf;
break;
@ -174,10 +170,8 @@ acl_to_text(acl_t acl, ssize_t *len_p)
len = asprintf(&tmpbuf, "%sgroup:%s:%s\n", buf,
name_buf, perm_buf);
}
if (len == -1) {
errno = ENOMEM;
if (len == -1)
goto error_label;
}
free(buf);
buf = tmpbuf;
break;
@ -190,10 +184,8 @@ acl_to_text(acl_t acl, ssize_t *len_p)
len = asprintf(&tmpbuf, "%smask::%s\n", buf,
perm_buf);
if (len == -1) {
errno = ENOMEM;
if (len == -1)
goto error_label;
}
free(buf);
buf = tmpbuf;
break;
@ -206,18 +198,15 @@ acl_to_text(acl_t acl, ssize_t *len_p)
len = asprintf(&tmpbuf, "%sother::%s\n", buf,
perm_buf);
if (len == -1) {
errno = ENOMEM;
if (len == -1)
goto error_label;
}
free(buf);
buf = tmpbuf;
break;
default:
free(buf);
errno = EINVAL;
return (0);
goto error_label;
}
}