From e0d419f0349b5eb17086e511bacf57b604e96f9f Mon Sep 17 00:00:00 2001 From: Jia Zhouyang Date: Sun, 4 Mar 2018 20:42:40 +0800 Subject: Add error handling for chdir When chdir fails, print error message and exit. --- local.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'local.c') diff --git a/local.c b/local.c index 46ac579..56d589d 100644 --- a/local.c +++ b/local.c @@ -426,7 +426,10 @@ localcgi_post(char *uri, char *qstr, FormList *request, char *referer) } #ifdef HAVE_CHDIR /* ifndef __EMX__ ? */ - chdir(cgi_dir); + if (chdir(cgi_dir) == -1) { + fprintf(stderr, "failed to chdir to %s: %s\n", cgi_dir, strerror(errno)); + exit(1); + } #endif execl(file, cgi_basename, NULL); fprintf(stderr, "execl(\"%s\", \"%s\", NULL): %s\n", -- cgit v1.2.3