From 7d6f6a3532997fc2d9ad9d113e8c210e05971801 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Sun, 15 Jul 2018 09:14:30 +0000 Subject: [PATCH] sh: Don't use padvance() for MAIL/MAILPATH Using padvance() requires undoing its append of '/' and prevents adjusting its '%' logic to allow most directories with '%' in PATH. No functional change is intended. --- bin/sh/mail.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/bin/sh/mail.c b/bin/sh/mail.c index 0a77bae7a808..194f654484db 100644 --- a/bin/sh/mail.c +++ b/bin/sh/mail.c @@ -43,7 +43,6 @@ __FBSDID("$FreeBSD$"); */ #include "shell.h" -#include "exec.h" /* defines padvance() */ #include "mail.h" #include "var.h" #include "output.h" @@ -72,9 +71,9 @@ void chkmail(int silent) { int i; - const char *mpath; + char *mpath; char *p; - char *q; + char *msg; struct stackmark smark; struct stat statb; @@ -83,22 +82,25 @@ chkmail(int silent) if (nmboxes == 0) return; setstackmark(&smark); - mpath = mpathset()? mpathval() : mailval(); + mpath = stsavestr(mpathset()? mpathval() : mailval()); for (i = 0 ; i < nmboxes ; i++) { - p = padvance(&mpath, ""); - if (p == NULL) - break; + p = mpath; if (*p == '\0') - continue; - for (q = p ; *q ; q++); - if (q[-1] != '/') - abort(); - q[-1] = '\0'; /* delete trailing '/' */ + break; + mpath = strchrnul(mpath, ':'); + if (*mpath != '\0') { + *mpath++ = '\0'; + if (p == mpath - 1) + continue; + } + msg = strchr(p, '%'); + if (msg != NULL) + *msg++ = '\0'; #ifdef notdef /* this is what the System V shell claims to do (it lies) */ if (stat(p, &statb) < 0) statb.st_mtime = 0; if (statb.st_mtime > mailtime[i] && ! silent) { - out2str(pathopt? pathopt : "you have mail"); + out2str(msg? msg : "you have mail"); out2c('\n'); } mailtime[i] = statb.st_mtime; @@ -106,7 +108,7 @@ chkmail(int silent) if (stat(p, &statb) < 0) statb.st_size = 0; if (statb.st_size > mailtime[i] && ! silent) { - out2str(pathopt? pathopt : "you have mail"); + out2str(msg? msg : "you have mail"); out2c('\n'); } mailtime[i] = statb.st_size;