]> granicus.if.org Git - apache/commitdiff
ap_rgetline_core: insure that the output string is null terminated
authorGreg Ames <gregames@apache.org>
Thu, 22 Apr 2004 22:38:03 +0000 (22:38 +0000)
committerGreg Ames <gregames@apache.org>
Thu, 22 Apr 2004 22:38:03 +0000 (22:38 +0000)
when exiting with APR_ENOSPC

Submitted by: Tsurutani Naoki <turutani scphys.kyoto-u.ac.jp>

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

server/protocol.c

index 60203064b075611fb27eb5ddc6c42ab8614af6e9..fb53fadb636196b58dbf0bf059167c51755d040a 100644 (file)
@@ -251,6 +251,15 @@ AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,
             /* Would this overrun our buffer?  If so, we'll die. */
             if (n < bytes_handled + len) {
                 *read = bytes_handled;
+                if (*s) {
+                    /* ensure this string is terminated */
+                    if (bytes_handled < n) {
+                        (*s)[bytes_handled] = '\0';
+                    }
+                    else {
+                        (*s)[n-1] = '\0';
+                    }
+                }
                 return APR_ENOSPC;
             }
             
@@ -379,6 +388,8 @@ AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,
                 /* Do we have enough space? We may be full now. */
                 if (bytes_handled >= n) {
                     *read = n;
+                    /* ensure this string is terminated */
+                    (*s)[n-1] = '\0';
                     return APR_ENOSPC;
                 }
                 else {