From da0575f3a383237dc9192d1c7ea54c7df9a8c8a6 Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 17 May 2004 09:09:52 +0000 Subject: add stampfilefd() to avoid race condition git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1998 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- util/bbsmail.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'util') diff --git a/util/bbsmail.c b/util/bbsmail.c index a58d5763..2ca997b8 100644 --- a/util/bbsmail.c +++ b/util/bbsmail.c @@ -78,7 +78,7 @@ void str_decode_M3(unsigned char *str); int mail2bbs(char *userid) { - int uid; + int uid, fd; fileheader_t mymail; char genbuf[512], title[512], sender[512], filename[512], *ip, *ptr; time_t tmp_time; @@ -156,9 +156,6 @@ int mail2bbs(char *userid) if( strchr(sender, '@') == NULL ) /* ¥Ñ local host ±H«H */ strcat(sender, "@" MYHOSTNAME); -/* allocate a file for the new mail */ - stampfile(filename, &mymail); - #ifdef HMM_USE_ANTI_SPAM for (n = 0; notitle[n]; n++) if (strstr(title, notitle[n])) @@ -178,11 +175,9 @@ int mail2bbs(char *userid) } #endif - if ((fout = fopen(filename, "w")) == NULL) - { - printf("Cannot open %s\n", filename); + if( (fd = stampfilefd(filename, &mymail)) == -1 || + (fout = fdopen(fd, "wt")) == NULL ) return -1; - } if (!title[0]) sprintf(title, "¨Ó¦Û %.64s", sender); -- cgit v1.2.3