From 4656d4747c8743290bfbe910c64cd75eb4e4af8d Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 15 Nov 2010 20:03:27 -0800 Subject: 420 remove patch (sparse package) support from svr4 pkg 421 libpkg and libadm need to be lint clean Reviewed by: gwr@nexenta.com Reviewed by: peter.tribble@gmail.com Approved by: gwr@nexenta.com --- usr/src/lib/libpkg/common/ncgrpw.c | 40 ++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 21 deletions(-) (limited to 'usr/src/lib/libpkg/common/ncgrpw.c') 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); -- cgit v1.2.3