summaryrefslogtreecommitdiff
path: root/usr/src/lib/libpkg/common/ncgrpw.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/lib/libpkg/common/ncgrpw.c')
-rw-r--r--usr/src/lib/libpkg/common/ncgrpw.c40
1 files changed, 19 insertions, 21 deletions
diff --git a/usr/src/lib/libpkg/common/ncgrpw.c b/usr/src/lib/libpkg/common/ncgrpw.c
index cf3151164e..52eb9f813b 100644
--- a/usr/src/lib/libpkg/common/ncgrpw.c
+++ b/usr/src/lib/libpkg/common/ncgrpw.c
@@ -595,15 +595,16 @@ clgrnam(char *nam)
struct group *gr;
char *instroot, *buf;
FILE *gr_ptr;
+ size_t bufsz;
if ((instroot = get_install_root()) != NULL) {
- if ((buf = (char *)malloc(strlen(instroot) +
- strlen(GROUP) + 1)) == NULL) {
+ bufsz = strlen(instroot) + strlen(GROUP) + 1;
+ if ((buf = (char *)malloc(bufsz)) == NULL) {
(void) fprintf(stderr,
- pkg_gt(ERR_MALLOC), "clgrnam()",
- strlen(instroot) + strlen(GROUP), "buf");
+ pkg_gt(ERR_MALLOC), "clgrnam()",
+ strlen(instroot) + strlen(GROUP), "buf");
}
- (void) sprintf(buf, "%s%s", instroot, GROUP);
+ (void) snprintf(buf, bufsz, "%s%s", instroot, GROUP);
if ((gr_ptr = fopen(buf, "r")) == NULL) {
free(buf);
return (NULL);
@@ -636,13 +637,12 @@ clpwnam(char *nam)
FILE *pw_ptr;
if ((instroot = get_install_root()) != NULL) {
- if ((buf = (char *)malloc(strlen(instroot) +
- strlen(PASSWD) + 1)) == NULL) {
+ if (asprintf(&buf, "%s%s", instroot, PASSWD) < 0) {
(void) fprintf(stderr,
- pkg_gt(ERR_MALLOC), "clpwnam()",
- strlen(instroot) + strlen(PASSWD), "buf");
+ pkg_gt(ERR_MALLOC), "clpwnam()",
+ strlen(instroot) + strlen(PASSWD), "buf");
+ return (NULL);
}
- (void) sprintf(buf, "%s%s", instroot, PASSWD);
if ((pw_ptr = fopen(buf, "r")) == NULL) {
free(buf);
return (NULL);
@@ -675,13 +675,13 @@ clgrgid(gid_t gid)
FILE *gr_ptr;
if ((instroot = get_install_root()) != NULL) {
- if ((buf = (char *)malloc(strlen(instroot) +
- strlen(GROUP) + 1)) == NULL) {
+ if (asprintf(&buf, "%s%s", instroot, GROUP) < 0) {
(void) fprintf(stderr,
- pkg_gt(ERR_MALLOC), "clgrgid()",
- strlen(instroot) + strlen(GROUP), "buf");
+ pkg_gt(ERR_MALLOC), "clgrgid()",
+ strlen(instroot) + strlen(GROUP), "buf");
+ return (NULL);
}
- (void) sprintf(buf, "%s%s", instroot, GROUP);
+
if ((gr_ptr = fopen(buf, "r")) == NULL) {
free(buf);
return (NULL);
@@ -714,13 +714,11 @@ clpwuid(uid_t uid)
FILE *pw_ptr;
if ((instroot = get_install_root()) != NULL) {
- if ((buf = (char *)malloc(strlen(instroot) +
- strlen(PASSWD) + 1)) == NULL) {
- (void) fprintf(stderr,
- pkg_gt(ERR_MALLOC), "clpwuid()",
- strlen(instroot) + strlen(PASSWD), "buf");
+ if (asprintf(&buf, "%s%s", instroot, PASSWD) < 0) {
+ (void) fprintf(stderr, pkg_gt(ERR_MALLOC), "clpwuid()",
+ strlen(instroot) + strlen(PASSWD), "buf");
+ return (NULL);
}
- (void) sprintf(buf, "%s%s", instroot, PASSWD);
if ((pw_ptr = fopen(buf, "r")) == NULL) {
free(buf);
return (NULL);