From: Graham Leggett Date: Mon, 29 Jun 2020 14:08:01 +0000 (+0000) Subject: Make sure the get and restore the file offset when conputing the ETag. Be defensive X-Git-Tag: 2.5.0-alpha2-ci-test-only~1323 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a1ffe6bfede1f31cce12527e1c7a62642beafc6e;p=thirdparty%2Fapache%2Fhttpd.git Make sure the get and restore the file offset when conputing the ETag. Be defensive when opening the file. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1879332 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/server/util_etag.c b/server/util_etag.c index bc2f9861e0d..bf4ce3b0a6d 100644 --- a/server/util_etag.c +++ b/server/util_etag.c @@ -152,13 +152,16 @@ AP_DECLARE(char *) ap_make_etag_ex(request_rec *r, etag_rec *er) apr_file_t *fd = NULL; apr_size_t nbytes; - apr_off_t offset = 0L; + apr_off_t offset; if (er->fd) { fd = er->fd; } else if (er->pathname) { - apr_file_open(&fd, er->pathname, APR_READ | APR_BINARY, 0, r->pool); + if (apr_file_open(&fd, er->pathname, APR_READ | APR_BINARY, + 0, r->pool) != APR_SUCCESS) { + return ""; + } } if (!fd) { return ""; @@ -167,6 +170,10 @@ AP_DECLARE(char *) ap_make_etag_ex(request_rec *r, etag_rec *er) etag = apr_palloc(r->pool, weak_len + sizeof("\"\"") + 4*(APR_SHA1_DIGESTSIZE/3) + vlv_len + 4); + if (apr_file_seek(fd, APR_CUR, &offset) != APR_SUCCESS) { + return ""; + } + apr_sha1_init(&context); nbytes = sizeof(buf); while (apr_file_read(fd, buf, &nbytes) == APR_SUCCESS) {