summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStefan Bühler <stbuehler@web.de>2015-07-19 10:03:12 +0000
committerStefan Bühler <stbuehler@web.de>2015-07-19 10:03:12 +0000
commitdef17b2925f5e8db74a7dbd93448726adac41e0c (patch)
tree46cdb291eea49bd5b469db1f42cd2dbad020e855 /src
parent4a87f75fcf72746c8881fa49328aacdef89b9bd6 (diff)
downloadlighttpd-git-def17b2925f5e8db74a7dbd93448726adac41e0c.tar.gz
[configfile] fix reading uninitialized variable (found by Willian B.)
- stream_open()-ing an empty file shouldn't return an error (and didn't on my system) - don't try to handle empty file as non-error in config_parse_file; this fixes the read of an potentially unitialized variable - stream_open()-ing an empty file doesn't try to map the file anymore and should not result in any errors; return an empty stream instead. - stream_open(): make sure the returned stream is always initialized correctly, and can always be used with stream_close(), whether opening was successful or not - stream_close(): also reset the size member From: Stefan Bühler <stbuehler@web.de> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3003 152afb58-edef-0310-8abb-c4023f1b3aa9
Diffstat (limited to 'src')
-rw-r--r--src/configfile.c11
-rw-r--r--src/stream.c16
2 files changed, 15 insertions, 12 deletions
diff --git a/src/configfile.c b/src/configfile.c
index 929d292d..17f67ae7 100644
--- a/src/configfile.c
+++ b/src/configfile.c
@@ -996,14 +996,9 @@ int config_parse_file(server *srv, config_t *context, const char *fn) {
}
if (0 != stream_open(&s, filename)) {
- if (s.size == 0) {
- /* the file was empty, nothing to parse */
- ret = 0;
- } else {
- log_error_write(srv, __FILE__, __LINE__, "sbss",
- "opening configfile ", filename, "failed:", strerror(errno));
- ret = -1;
- }
+ log_error_write(srv, __FILE__, __LINE__, "sbss",
+ "opening configfile ", filename, "failed:", strerror(errno));
+ ret = -1;
} else {
tokenizer_init(&t, filename, s.start, s.size);
ret = config_parse(srv, context, &t);
diff --git a/src/stream.c b/src/stream.c
index c29a5ca6..30112caf 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -22,23 +22,28 @@ int stream_open(stream *f, buffer *fn) {
#endif
f->start = NULL;
+ f->size = 0;
if (-1 == stat(fn->ptr, &st)) {
return -1;
}
- f->size = st.st_size;
+ if (0 == st.st_size) {
+ /* empty file doesn't need a mapping */
+ return 0;
+ }
#ifdef HAVE_MMAP
if (-1 == (fd = open(fn->ptr, O_RDONLY | O_BINARY))) {
return -1;
}
- f->start = mmap(NULL, f->size, PROT_READ, MAP_SHARED, fd, 0);
+ f->start = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
close(fd);
if (MAP_FAILED == f->start) {
+ f->start = NULL;
return -1;
}
@@ -56,8 +61,8 @@ int stream_open(stream *f, buffer *fn) {
mh = CreateFileMapping( fh,
NULL,
PAGE_READONLY,
- (sizeof(off_t) > 4) ? f->size >> 32 : 0,
- f->size & 0xffffffff,
+ (sizeof(off_t) > 4) ? st.st_size >> 32 : 0,
+ st.st_size & 0xffffffff,
NULL);
if (!mh) {
@@ -88,6 +93,8 @@ int stream_open(stream *f, buffer *fn) {
# error no mmap found
#endif
+ f->size = st.st_size;
+
return 0;
}
@@ -99,6 +106,7 @@ int stream_close(stream *f) {
#endif
f->start = NULL;
+ f->size = 0;
return 0;
}