diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2020-12-27 22:34:38 -0500 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2020-12-27 22:35:48 -0500 |
commit | 37ae942346dca72b89ceada9a3bb999c77df44f8 (patch) | |
tree | 93040da3041bf923b09bab5784e739d681a9a7fb | |
parent | 5ec5e124c1697f71d714f631a762ccbf3f168023 (diff) | |
download | lighttpd-git-37ae942346dca72b89ceada9a3bb999c77df44f8.tar.gz |
[core] fix bug in read retry found by coverity
read retry loop needs separate var for result and data size to read
rename 'toSend' variable to 'len' (of chunk)
-rw-r--r-- | src/chunk.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/chunk.c b/src/chunk.c index 8c688f69..4d05a1b4 100644 --- a/src/chunk.c +++ b/src/chunk.c @@ -906,8 +906,8 @@ static int chunk_open_file_chunk(chunk * const restrict c, log_error_st * const } const off_t offset = c->offset; - const off_t toSend = c->file.length - c->offset; - if (offset > st.st_size || toSend > st.st_size || offset > st.st_size - toSend) { + const off_t len = c->file.length - c->offset; + if (offset > st.st_size || len > st.st_size || offset > st.st_size - len) { log_error(errh, __FILE__, __LINE__, "file shrunk: %s", c->mem->ptr); return -1; } @@ -1154,25 +1154,26 @@ chunkqueue_peek_data (chunkqueue * const cq, case FILE_CHUNK: if (c->file.fd >= 0 || 0 == chunk_open_file_chunk(c, errh)) { off_t offset = c->offset; - off_t toSend = c->file.length - c->offset; - if (toSend > (off_t)space) - toSend = (off_t)space; + off_t len = c->file.length - c->offset; + if (len > (off_t)space) + len = (off_t)space; if (-1 == lseek(c->file.fd, offset, SEEK_SET)) { log_perror(errh, __FILE__, __LINE__, "lseek(\"%s\")", c->mem->ptr); return -1; } + ssize_t rd; do { - toSend = read(c->file.fd, data_in + *dlen, (size_t)toSend); - } while (-1 == toSend && errno == EINTR); - if (toSend <= 0) { /* -1 error; 0 EOF (unexpected) */ + rd = read(c->file.fd, data_in + *dlen, (size_t)len); + } while (-1 == rd && errno == EINTR); + if (rd <= 0) { /* -1 error; 0 EOF (unexpected) */ log_perror(errh, __FILE__, __LINE__, "read(\"%s\")", c->mem->ptr); return -1; } - *dlen += (uint32_t)toSend; + *dlen += (uint32_t)rd; break; } return -1; |