You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by mi...@apache.org on 2020/06/29 14:08:01 UTC

svn commit: r1879332 - /httpd/httpd/trunk/server/util_etag.c

Author: minfrin
Date: Mon Jun 29 14:08:01 2020
New Revision: 1879332

URL: http://svn.apache.org/viewvc?rev=1879332&view=rev
Log:
Make sure the get and restore the file offset when conputing the ETag. Be defensive
when opening the file.

Modified:
    httpd/httpd/trunk/server/util_etag.c

Modified: httpd/httpd/trunk/server/util_etag.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/util_etag.c?rev=1879332&r1=1879331&r2=1879332&view=diff
==============================================================================
--- httpd/httpd/trunk/server/util_etag.c (original)
+++ httpd/httpd/trunk/server/util_etag.c Mon Jun 29 14:08:01 2020
@@ -152,13 +152,16 @@ AP_DECLARE(char *) ap_make_etag_ex(reque
         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(reque
         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) {