]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
mod_negotiation: simplify type-map body tag lookup, and be safe
authorYann Ylavic <ylavic@apache.org>
Wed, 2 Sep 2015 16:42:06 +0000 (16:42 +0000)
committerYann Ylavic <ylavic@apache.org>
Wed, 2 Sep 2015 16:42:06 +0000 (16:42 +0000)
should it contain a NUL byte.

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

modules/mappers/mod_negotiation.c

index a68281a8418e6c5347676ca105c84bc9238f0568..84ce114ec38eca10dd3c5dbd9d37ff65816758e2 100644 (file)
@@ -828,33 +828,27 @@ static apr_off_t get_body(char *buffer, apr_size_t *len, const char *tag,
                           apr_file_t *map)
 {
     char *endbody;
-    int bodylen;
-    int taglen;
+    apr_size_t bodylen;
     apr_off_t pos;
 
-    taglen = strlen(tag);
-    *len -= taglen;
 
     /* We are at the first character following a body:tag\n entry
      * Suck in the body, then backspace to the first char after the
      * closing tag entry.  If we fail to read, find the tag or back
      * up then we have a hosed file, so give up already
      */
+    --*len; /* Reserve space for '\0' */
     if (apr_file_read(map, buffer, len) != APR_SUCCESS) {
         return -1;
     }
+    buffer[*len] = '\0';
 
-    /* put a copy of the tag *after* the data read from the file
-     * so that strstr() will find something with no reliance on
-     * terminating '\0'
-     */
-    memcpy(buffer + *len, tag, taglen);
-    endbody = strstr(buffer, tag);
-    if (endbody == buffer + *len) {
+    endbody = ap_strstr(buffer, tag);
+    if (!endbody) {
         return -1;
     }
     bodylen = endbody - buffer;
-    endbody += taglen;
+    endbody += strlen(tag);
     /* Skip all the trailing cruft after the end tag to the next line */
     while (*endbody) {
         if (*endbody == '\n') {