From c8dcf65f2c553ff370efcad5617cdb17bcbd62ee Mon Sep 17 00:00:00 2001 From: Gilles Chehade Date: Sun, 25 Nov 2018 17:34:01 +0000 Subject: fix mail.mda so it handles system() exit value correctly issue reported and diff tested by florian@ --- usr.sbin/smtpd/mail.mda.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'usr.sbin') 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 #include +#include #include #include @@ -26,12 +27,14 @@ #include #include #include +#include #include 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)); } -- cgit v1.2.3