[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-c4023f1b3aa9svn/tags/lighttpd-1.4.36
parent
4a87f75fcf
commit
def17b2925
1
NEWS
1
NEWS
|
@ -28,6 +28,7 @@ NEWS
|
|||
* fix segfault when temp file for upload couldn't be created (found by coverity)
|
||||
* mime.conf: add some new mime types, remove .dat, .sha1, .md5, update .vcf
|
||||
* [mod_proxy] add unix domain socket support (fixes #2653)
|
||||
* [configfile] fix reading uninitialized variable (found by Willian B.)
|
||||
|
||||
- 1.4.35 - 2014-03-12
|
||||
* [network/ssl] fix build error if TLSEXT is disabled
|
||||
|
|
|
@ -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);
|
||||
|
|
16
src/stream.c
16
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue