diff options
author | Mark Lumsden <lum@cvs.openbsd.org> | 2021-02-26 01:17:22 +0000 |
---|---|---|
committer | Mark Lumsden <lum@cvs.openbsd.org> | 2021-02-26 01:17:22 +0000 |
commit | 2eb31ecf7af1d6d16acafed12b303496100a959c (patch) | |
tree | c0546a369fa95dff839eff6df784f4e95767295a /usr.bin/mg | |
parent | ed597998317e49a2469994e25c9e81ff0177947b (diff) |
Some improvements from Joachim Wiberg's version of mg.
check value of adjustname()
use int for return value of snprintf
Diffstat (limited to 'usr.bin/mg')
-rw-r--r-- | usr.bin/mg/dired.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/usr.bin/mg/dired.c b/usr.bin/mg/dired.c index 90d9a638373..778a88d4da5 100644 --- a/usr.bin/mg/dired.c +++ b/usr.bin/mg/dired.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dired.c,v 1.94 2021/02/24 13:58:46 lum Exp $ */ +/* $OpenBSD: dired.c,v 1.95 2021/02/26 01:17:21 lum Exp $ */ /* This file is in the public domain. */ @@ -489,6 +489,8 @@ d_copy(int f, int n) topath = adjustname(toname, TRUE); } } + if (topath == NULL) + return (FALSE); if (strcmp(frname, topath) == 0) { ewprintf("Cannot copy to same file: %s", frname); return (TRUE); @@ -523,7 +525,7 @@ d_rename(int f, int n) off = strlcpy(toname, curbp->b_fname, sizeof(toname)); if (off >= sizeof(toname) - 1) { /* can't happen, really */ dobeep(); - ewprintf("Directory name too long"); + ewprintf("Name too long"); return (FALSE); } (void)xbasename(sname, frname, NFILEN); @@ -537,9 +539,9 @@ d_rename(int f, int n) topath = adjustname(toname, TRUE); if (stat(topath, &statbuf) == 0) { if (S_ISDIR(statbuf.st_mode)) { - off = snprintf(toname, sizeof(toname), "%s/%s", + ret = snprintf(toname, sizeof(toname), "%s/%s", topath, sname); - if (off < 0 || off >= sizeof(toname) - 1) { + if (ret < 0 || ret >= sizeof(toname) - 1) { dobeep(); ewprintf("Directory name too long"); return (FALSE); @@ -547,6 +549,8 @@ d_rename(int f, int n) topath = adjustname(toname, TRUE); } } + if (topath == NULL) + return (FALSE); if (strcmp(frname, topath) == 0) { ewprintf("Cannot move to same file: %s", frname); return (TRUE); |