=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mg/dired.c,v retrieving revision 1.94 retrieving revision 1.95 diff -u -r1.94 -r1.95 --- src/usr.bin/mg/dired.c 2021/02/24 13:58:46 1.94 +++ src/usr.bin/mg/dired.c 2021/02/26 01:17:21 1.95 @@ -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 @@ 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 @@ 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 @@ 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 @@ topath = adjustname(toname, TRUE); } } + if (topath == NULL) + return (FALSE); if (strcmp(frname, topath) == 0) { ewprintf("Cannot move to same file: %s", frname); return (TRUE);