Date: Thu, 4 Apr 2024 11:39:05 GMT From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= <des@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 8934e4a17e94 - stable/13 - install: Prefer strsnvis() to strsvis(). Message-ID: <202404041139.434Bd5ew060244@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=8934e4a17e945fbd37b4e97fc42f83d000b74d9a commit 8934e4a17e945fbd37b4e97fc42f83d000b74d9a Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2024-03-27 10:03:59 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2024-04-04 09:51:06 +0000 install: Prefer strsnvis() to strsvis(). MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: allanjude Differential Revision: https://reviews.freebsd.org/D44514 (cherry picked from commit 2cab4be46b0eeb64b8ade010bc16245151af5ccd) --- usr.bin/xinstall/xinstall.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c index 3bcc44d08b81..f1fe1a969377 100644 --- a/usr.bin/xinstall/xinstall.c +++ b/usr.bin/xinstall/xinstall.c @@ -1507,15 +1507,18 @@ metadata_log(const char *path, const char *type, struct timespec *ts, static const char extra[] = { ' ', '\t', '\n', '\\', '#', '\0' }; const char *p; char *buf; - size_t destlen; + size_t buflen, destlen; struct flock metalog_lock; if (!metafp) return; - /* Buffer for strsvis(3). */ - buf = (char *)malloc(4 * strlen(path) + 1); - if (buf == NULL) { - warnx("%s", strerror(ENOMEM)); + /* Buffer for strsnvis(3), used for both path and slink. */ + buflen = strlen(path); + if (slink && strlen(slink) > buflen) + buflen = strlen(slink); + buflen = 4 * buflen + 1; + if ((buf = malloc(buflen)) == NULL) { + warn(NULL); return; } @@ -1540,7 +1543,7 @@ metadata_log(const char *path, const char *type, struct timespec *ts, } while (*p && *p == '/') p++; - strsvis(buf, p, VIS_OCTAL, extra); + strsnvis(buf, buflen, p, VIS_OCTAL, extra); p = buf; /* Print details. */ fprintf(metafp, ".%s%s type=%s", *p ? "/" : "", p, type); @@ -1550,14 +1553,14 @@ metadata_log(const char *path, const char *type, struct timespec *ts, fprintf(metafp, " gname=%s", group); fprintf(metafp, " mode=%#o", mode); if (slink) { - strsvis(buf, slink, VIS_CSTYLE, extra); /* encode link */ + strsnvis(buf, buflen, slink, VIS_CSTYLE, extra); fprintf(metafp, " link=%s", buf); } if (*type == 'f') /* type=file */ fprintf(metafp, " size=%lld", (long long)size); if (ts != NULL && dopreserve) fprintf(metafp, " time=%lld.%09ld", - (long long)ts[1].tv_sec, ts[1].tv_nsec); + (long long)ts[1].tv_sec, ts[1].tv_nsec); if (digestresult && digest) fprintf(metafp, " %s=%s", digest, digestresult); if (fflags)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202404041139.434Bd5ew060244>