diff options
author | 2018-11-25 17:34:00 +0000 | |
---|---|---|
committer | 2018-11-25 17:34:00 +0000 | |
commit | 9e5602cf3b1aba2170176c41e53668f01956a527 (patch) | |
tree | 9239fc12adb6f26cd8d9ca91f1947abd57ba5ae9 | |
parent | Remove (unused) FS_BOOT training wheels. If you are allowed to newfs a (diff) | |
download | wireguard-openbsd-9e5602cf3b1aba2170176c41e53668f01956a527.tar.xz wireguard-openbsd-9e5602cf3b1aba2170176c41e53668f01956a527.zip |
fix mail.mda so it handles system() exit value correctly
issue reported and diff tested by florian@
-rw-r--r-- | usr.sbin/smtpd/mail.mda.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/usr.sbin/smtpd/mail.mda.c b/usr.sbin/smtpd/mail.mda.c index 64398c84f9c..f9fb32367a6 100644 --- a/usr.sbin/smtpd/mail.mda.c +++ b/usr.sbin/smtpd/mail.mda.c @@ -16,6 +16,7 @@ #include <sys/types.h> #include <sys/stat.h> +#include <sys/wait.h> #include <ctype.h> #include <err.h> @@ -26,12 +27,14 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sysexits.h> #include <unistd.h> int main(int argc, char *argv[]) { int ch; + int ret; if (! geteuid()) errx(1, "mail.mda: may not be executed as root"); @@ -51,5 +54,15 @@ main(int argc, char *argv[]) if (argc > 1) errx(1, "mail.mda: only one command is supported"); - return system(argv[0]) == 0 ? 0 : 1; + /* could not obtain a shell or could not obtain wait status, + * tempfail */ + if ((ret = system(argv[0])) == -1) + errx(EX_TEMPFAIL, "%s", strerror(errno)); + + /* not exited properly but we have no details, + * tempfail */ + if (! WIFEXITED(ret)) + exit(EX_TEMPFAIL); + + exit(WEXITSTATUS(ret)); } |