From: Brian Pane Date: Sat, 23 Mar 2002 06:03:37 +0000 (+0000) Subject: Eliminate an 8KB buffer from the stack in mod_info's handler function X-Git-Tag: 2.0.34~162 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0adefd48310d7046fb823fc6284a38979ea53a4a;p=apache Eliminate an 8KB buffer from the stack in mod_info's handler function git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@94145 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/generators/mod_info.c b/modules/generators/mod_info.c index e7f3cb6d7c..a91cf2f9e7 100644 --- a/modules/generators/mod_info.c +++ b/modules/generators/mod_info.c @@ -129,55 +129,39 @@ static void *merge_info_config(apr_pool_t *p, void *basev, void *overridesv) return new; } -static char *mod_info_html_cmd_string(const char *string, char *buf, size_t buf_len, int close) +static void mod_info_html_cmd_string(request_rec *r, const char *string, + int close) { const char *s; - char *t; - char *end_buf; s = string; - t = buf; /* keep space for \0 byte */ - end_buf = buf + buf_len - 1; - while ((*s) && (t < end_buf)) { + while (*s) { if (*s == '<') { if (close) { - strncpy(t, "</,", end_buf -t); - t += 5; + ap_rputs("</,", r); } else { - strncpy(t, "<", end_buf - t); - t += 4; + ap_rputs("<", r); } } else if (*s == '>') { - strncpy(t, ">", end_buf - t); - t += 4; + ap_rputs(">", r); } else if (*s == '&') { - strncpy(t, "&", end_buf - t); - t += 5; + ap_rputs("&", r); } else if (*s == ' ') { if (close) { - strncpy(t, ">", end_buf -t); - t += 4; + ap_rputs(">", r); break; } else { - *t++ = *s; + ap_rputc(*s, r); } } else { - *t++ = *s; + ap_rputc(*s, r); } s++; } - /* oops, overflowed... don't overwrite */ - if (t > end_buf) { - *end_buf = '\0'; - } - else { - *t = '\0'; - } - return (buf); } static void mod_info_module_cmds(request_rec * r, const command_rec * cmds, @@ -201,9 +185,9 @@ static void mod_info_module_cmds(request_rec * r, const command_rec * cmds, apr_snprintf(htmlstring, sizeof(htmlstring), "%s %s", tmptree->parent->directive, tmptree->parent->args); - ap_rprintf(r, "
%s
\n", - mod_info_html_cmd_string(htmlstring, buf, - sizeof(buf), 0)); + ap_rputs("
", r); + mod_info_html_cmd_string(r, htmlstring, 0); + ap_rputs("
\n", r); } if (nest == 2) { ap_rprintf(r, "
    %s " @@ -214,10 +198,9 @@ static void mod_info_module_cmds(request_rec * r, const command_rec * cmds, "
  %s %s
\n", tmptree->directive, tmptree->args); } else { - ap_rprintf(r, "
%s %s
\n", - mod_info_html_cmd_string(tmptree->directive, - buf, sizeof(buf), - 0), tmptree->args); + ap_rputs("
", r); + mod_info_html_cmd_string(r, tmptree->directive, 0); + ap_rprintf(r, " %s
\n", tmptree->args); } } ++cmd; @@ -232,9 +215,9 @@ static void mod_info_module_cmds(request_rec * r, const command_rec * cmds, apr_snprintf(htmlstring, sizeof(htmlstring), "%s %s", tmptree->parent->directive, tmptree->parent->args); - ap_rprintf(r, "
%s
\n", - mod_info_html_cmd_string(htmlstring, buf, - sizeof(buf), 1)); + ap_rputs("
", r); + mod_info_html_cmd_string(r, htmlstring, 1); + ap_rputs("
\n", r); block_start--; } if (tmptree->parent) { @@ -361,7 +344,6 @@ static const char *find_more_info(server_rec *s, const char *module_name) static int display_info(request_rec *r) { module *modp = NULL; - char buf[MAX_STRING_LEN]; const char *more_info; const command_rec *cmd = NULL; #ifdef NEVERMORE @@ -506,9 +488,9 @@ static int display_info(request_rec *r) ap_rputs("
Module Directives:
", r); while (cmd) { if (cmd->name) { - ap_rprintf(r, "
%s - ", - mod_info_html_cmd_string(cmd->name, - buf, sizeof(buf), 0)); + ap_rputs("
", r); + mod_info_html_cmd_string(r, cmd->name, 0); + ap_rputs(" - ", r); if (cmd->errmsg) { ap_rputs(cmd->errmsg, r); }