From: Greg Ames Date: Thu, 22 Apr 2004 22:38:03 +0000 (+0000) Subject: ap_rgetline_core: insure that the output string is null terminated X-Git-Tag: pre_ajp_proxy~334 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e9b7d5fefe82fef8afb9e12094d5cf8426e514bb;p=apache ap_rgetline_core: insure that the output string is null terminated when exiting with APR_ENOSPC Submitted by: Tsurutani Naoki git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@103482 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/server/protocol.c b/server/protocol.c index 60203064b0..fb53fadb63 100644 --- a/server/protocol.c +++ b/server/protocol.c @@ -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 {