From 779c686861cb2c8d4183c2a362b5856dd8b56f27 Mon Sep 17 00:00:00 2001 From: robertabcd Date: Sun, 5 Oct 2014 06:53:14 +0000 Subject: 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 --- pttbbs/daemon/boardd/boardd.c | 8 +++++--- 1 file 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) { -- cgit v1.2.3