diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2018-11-25 17:34:01 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2018-11-25 17:34:01 +0000 |
commit | c8dcf65f2c553ff370efcad5617cdb17bcbd62ee (patch) | |
tree | 128b3b368ff52a6d26f9a8f88c3191497a584a85 | |
parent | 174d29eb64eaaafcc08bf18502b3e72c8afffedc (diff) |
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)); } |