]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Make sure the get and restore the file offset when conputing the ETag. Be defensive
authorGraham Leggett <minfrin@apache.org>
Mon, 29 Jun 2020 14:08:01 +0000 (14:08 +0000)
committerGraham Leggett <minfrin@apache.org>
Mon, 29 Jun 2020 14:08:01 +0000 (14:08 +0000)
when opening the file.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1879332 13f79535-47bb-0310-9956-ffa450edef68

server/util_etag.c

index bc2f9861e0d5f3aa23ccb904fd3b368d11d526f0..bf4ce3b0a6d98e038d48e2a4d6c8d6df842dbf93 100644 (file)
@@ -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) {