Date: Tue, 5 Dec 2000 09:45:13 -0500 From: Chris Faulhaber <jedgar@fxp.org> To: freebsd-audit@FreeBSD.org Subject: ar(1) patch Message-ID: <20001205094513.A47743@peitho.fxp.org>
next in thread | raw e-mail | index | archive | help
The following patch fixes a few calls in ar(1) (based on will's usr.bin patchset): - malloc()/strcpy() -> asprintf() - sprintf() -> snprintf() - strcpy() -> strlcpy() For more patches up for review, see: http://www.fxp.org/~jedgar/FreeBSD/diffs/ -- Chris D. Faulhaber - jedgar@fxp.org - jedgar@FreeBSD.org -------------------------------------------------------- FreeBSD: The Power To Serve - http://www.FreeBSD.org Index: ar.c =================================================================== RCS file: /home/ncvs/src/usr.bin/ar/ar.c,v retrieving revision 1.8 diff -u -r1.8 ar.c --- ar.c 1999/08/28 00:59:07 1.8 +++ ar.c 2000/12/05 14:37:42 @@ -92,10 +92,8 @@ * Fix it, if necessary. */ if (*argv[1] != '-') { - if (!(p = malloc((u_int)(strlen(argv[1]) + 2)))) + if ((asprintf(&p, "-%s", argv[1])) == -1) err(1, NULL); - *p = '-'; - (void)strcpy(p + 1, argv[1]); argv[1] = p; } Index: archive.c =================================================================== RCS file: /home/ncvs/src/usr.bin/ar/archive.c,v retrieving revision 1.10 diff -u -r1.10 archive.c --- archive.c 1998/12/06 07:36:44 1.10 +++ archive.c 2000/12/05 14:37:42 @@ -225,18 +225,18 @@ name, OLDARMAXNAME, name); (void)fflush(stderr); } - (void)sprintf(hb, HDR3, name, + (void)snprintf(hb, sizeof(hb), HDR3, name, (long)sb->st_mtimespec.tv_sec, sb->st_uid, sb->st_gid, sb->st_mode, sb->st_size, ARFMAG); lname = 0; } else if (lname > sizeof(hdr->ar_name) || strchr(name, ' ')) - (void)sprintf(hb, HDR1, AR_EFMT1, lname, + (void)snprintf(hb, sizeof(hb), HDR1, AR_EFMT1, lname, (long)sb->st_mtimespec.tv_sec, sb->st_uid, sb->st_gid, sb->st_mode, sb->st_size + lname, ARFMAG); else { lname = 0; - (void)sprintf(hb, HDR2, name, + (void)snprintf(hb, sizeof(hb), HDR2, name, (long)sb->st_mtimespec.tv_sec, sb->st_uid, sb->st_gid, sb->st_mode, sb->st_size, ARFMAG); } Index: misc.c =================================================================== RCS file: /home/ncvs/src/usr.bin/ar/misc.c,v retrieving revision 1.6 diff -u -r1.6 misc.c --- misc.c 1998/12/06 07:36:44 1.6 +++ misc.c 2000/12/05 14:37:42 @@ -70,9 +70,9 @@ } if (envtmp) - (void)sprintf(path, "%s/%s", envtmp, _NAME_ARTMP); + (void)snprintf(path, sizeof(path), "%s/%s", envtmp, _NAME_ARTMP); else - strcpy(path, _PATH_ARTMP); + strlcpy(path, _PATH_ARTMP, sizeof(path)); sigfillset(&set); (void)sigprocmask(SIG_BLOCK, &set, &oset); To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20001205094513.A47743>