diff options
author | robertabcd <robertabcd@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2014-10-05 14:53:14 +0800 |
---|---|---|
committer | robertabcd <robertabcd@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2014-10-05 14:53:14 +0800 |
commit | 779c686861cb2c8d4183c2a362b5856dd8b56f27 (patch) | |
tree | c47904f5a4b9e26c15061644587ec426e1590fbd | |
parent | 986f05e77b87e9ff84c9e905dd487e353e757850 (diff) | |
download | pttbbs-779c686861cb2c8d4183c2a362b5856dd8b56f27.tar pttbbs-779c686861cb2c8d4183c2a362b5856dd8b56f27.tar.gz pttbbs-779c686861cb2c8d4183c2a362b5856dd8b56f27.tar.bz2 pttbbs-779c686861cb2c8d4183c2a362b5856dd8b56f27.tar.lz pttbbs-779c686861cb2c8d4183c2a362b5856dd8b56f27.tar.xz pttbbs-779c686861cb2c8d4183c2a362b5856dd8b56f27.tar.zst pttbbs-779c686861cb2c8d4183c2a362b5856dd8b56f27.zip |
boardd: fix fd leak on certain conditions (eg. empty file)
git-svn-id: http://opensvn.csie.org/pttbbs/trunk@6076 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | pttbbs/daemon/boardd/boardd.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/pttbbs/daemon/boardd/boardd.c b/pttbbs/daemon/boardd/boardd.c index 17e065d8..fd4200d1 100644 --- a/pttbbs/daemon/boardd/boardd.c +++ b/pttbbs/daemon/boardd/boardd.c @@ -143,10 +143,12 @@ answer_key(struct evbuffer *buf, const char *key) int fd; setbfile(path, bptr->brdname, key + 8); - if ((fd = open(path, O_RDONLY)) < 0 || fstat(fd, &st) < 0) + if ((fd = open(path, O_RDONLY)) < 0) return; - - evbuffer_add_file(buf, fd, 0, st.st_size); + if (fstat(fd, &st) < 0 || + st.st_size == 0 || + evbuffer_add_file(buf, fd, 0, st.st_size) != 0) + close(fd); } else return; } else if (strncmp(key, "tobid.", 6) == 0) { |