X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=cgi.c;h=dd94e14b7281559a9ae559ad91c86dfa9cf73c05;hp=fac49bda9d904a5dccbdc5cde5c55e465b18789b;hb=7f467813470e68568251847f70c1ba6c65c732c7;hpb=1a81e0e172a47ea908b244a9c3068c88c3cce9c6 diff --git a/cgi.c b/cgi.c index fac49bda..dd94e14b 100644 --- a/cgi.c +++ b/cgi.c @@ -1,4 +1,4 @@ -const char cgi_rcs[] = "$Id: cgi.c,v 1.95 2007/02/10 17:01:37 fabiankeil Exp $"; +const char cgi_rcs[] = "$Id: cgi.c,v 1.97 2007/04/09 18:11:35 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/cgi.c,v $ @@ -38,6 +38,12 @@ const char cgi_rcs[] = "$Id: cgi.c,v 1.95 2007/02/10 17:01:37 fabiankeil Exp $"; * * Revisions : * $Log: cgi.c,v $ + * Revision 1.97 2007/04/09 18:11:35 fabiankeil + * Don't mistake VC++'s _snprintf() for a snprintf() replacement. + * + * Revision 1.96 2007/03/08 17:41:05 fabiankeil + * Use sizeof() more often. + * * Revision 1.95 2007/02/10 17:01:37 fabiankeil * Don't overlook map result for the forwarding-type. * @@ -580,10 +586,6 @@ const char cgi_rcs[] = "$Id: cgi.c,v 1.95 2007/02/10 17:01:37 fabiankeil Exp $"; #include #include -#ifdef _WIN32 -#define snprintf _snprintf -#endif /* def _WIN32 */ - #include "project.h" #include "cgi.h" #include "list.h" @@ -1636,6 +1638,7 @@ jb_err cgi_error_no_template(struct client_state *csp, ").

\r\n" "\r\n" "\r\n"; + const size_t body_size = strlen(body_prefix) + strlen(template_name) + strlen(body_suffix) + 1; assert(csp); assert(rsp); @@ -1649,14 +1652,14 @@ jb_err cgi_error_no_template(struct client_state *csp, rsp->head_length = 0; rsp->is_static = 0; - rsp->body = malloc(strlen(body_prefix) + strlen(template_name) + strlen(body_suffix) + 1); + rsp->body = malloc(body_size); if (rsp->body == NULL) { return JB_ERR_MEMORY; } - strcpy(rsp->body, body_prefix); - strcat(rsp->body, template_name); - strcat(rsp->body, body_suffix); + strlcpy(rsp->body, body_prefix, body_size); + strlcat(rsp->body, template_name, body_size); + strlcat(rsp->body, body_suffix, body_size); rsp->status = strdup(status); if (rsp->status == NULL) @@ -1716,6 +1719,11 @@ jb_err cgi_error_unknown(struct client_state *csp, "\r\n" "\r\n"; char errnumbuf[30]; + /* + * Due to sizeof(errnumbuf), body_size will be slightly + * bigger than necessary but it doesn't really matter. + */ + const size_t body_size = strlen(body_prefix) + sizeof(errnumbuf) + strlen(body_suffix) + 1; assert(csp); assert(rsp); @@ -1730,14 +1738,14 @@ jb_err cgi_error_unknown(struct client_state *csp, snprintf(errnumbuf, sizeof(errnumbuf), "%d", error_to_report); - rsp->body = malloc(strlen(body_prefix) + strlen(errnumbuf) + strlen(body_suffix) + 1); + rsp->body = malloc(body_size); if (rsp->body == NULL) { return JB_ERR_MEMORY; } - strcpy(rsp->body, body_prefix); - strcat(rsp->body, errnumbuf); - strcat(rsp->body, body_suffix); + strlcpy(rsp->body, body_prefix, body_size); + strlcat(rsp->body, errnumbuf, body_size); + strlcat(rsp->body, body_suffix, body_size); rsp->status = strdup(status); if (rsp->status == NULL)