summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2009-06-28 01:37:42 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2009-06-28 01:37:42 +0800
commit47a9337aac10dd9be48f4ec37f3f10ebc74b96fa (patch)
treed0acbb452d58167aedae2684c46fd1453c875ab7
parent9e8fcaa18fd12dc07c641899d4617fc527d16963 (diff)
downloadpttbbs-47a9337aac10dd9be48f4ec37f3f10ebc74b96fa.tar
pttbbs-47a9337aac10dd9be48f4ec37f3f10ebc74b96fa.tar.gz
pttbbs-47a9337aac10dd9be48f4ec37f3f10ebc74b96fa.tar.bz2
pttbbs-47a9337aac10dd9be48f4ec37f3f10ebc74b96fa.tar.lz
pttbbs-47a9337aac10dd9be48f4ec37f3f10ebc74b96fa.tar.xz
pttbbs-47a9337aac10dd9be48f4ec37f3f10ebc74b96fa.tar.zst
pttbbs-47a9337aac10dd9be48f4ec37f3f10ebc74b96fa.zip
* make Rename() return real status result when SIGCHLD was set to SIG_IGN.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk@4706 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--pttbbs/common/sys/file.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/pttbbs/common/sys/file.c b/pttbbs/common/sys/file.c
index 9e993905..b86899dd 100644
--- a/pttbbs/common/sys/file.c
+++ b/pttbbs/common/sys/file.c
@@ -198,26 +198,35 @@ int copy_file(const char *src, const char *dst)
return copy_file_to_file(src, dst);
}
+#include <signal.h>
int
Rename(const char *src, const char *dst)
{
+ pid_t pid;
+ sig_t s;
+ int ret = -1;
+
if (rename(src, dst) == 0)
return 0;
- if (!strchr(src, ';') && !strchr(dst, ';'))
+
+ // prevent malicious shell escapes
+ if (strchr(src, ';') || !strchr(dst, ';'))
+ return -1;
+
+ // because we need the return value, override the signal handler
+ s = signal(SIGCHLD, NULL);
+ pid = fork();
+
+ if (pid == 0)
+ execl("/bin/mv", "mv", "-f", src, dst, (char *)NULL);
+ else if (pid > 0)
{
- pid_t pid = fork();
- if (pid == 0)
- execl("/bin/mv", "mv", "-f", src, dst, (char *)NULL);
- else if (pid > 0)
- {
- int status = -1;
- waitpid(pid, &status, 0);
- return WEXITSTATUS(status) == 0 ? 0 : -1;
- }
- else
- return -1;
+ waitpid(pid, &ret, 0);
+ ret = WEXITSTATUS(ret) == 0 ? 0 : -1;
}
- return -1;
+
+ signal(SIGCHLD, s);
+ return ret;
}
int