From bad55634165b116a64244e1ecd91bcdda5a2d2b2 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Thu, 17 Apr 2008 14:40:49 +0000 Subject: [PATCH] Provide get_http_time() with the buffer size so it doesn't have to blindly assume that the buffer is big enough. --- cgi.c | 27 +++++++++++++++------------ cgi.h | 8 ++++++-- cgisimple.c | 7 +++++-- parsers.c | 8 ++++++-- parsers.h | 8 ++++++-- 5 files changed, 38 insertions(+), 20 deletions(-) diff --git a/cgi.c b/cgi.c index 91717379..65b68104 100644 --- a/cgi.c +++ b/cgi.c @@ -1,4 +1,4 @@ -const char cgi_rcs[] = "$Id: cgi.c,v 1.103 2008/03/21 11:13:57 fabiankeil Exp $"; +const char cgi_rcs[] = "$Id: cgi.c,v 1.104 2008/03/26 18:07:06 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/cgi.c,v $ @@ -38,6 +38,9 @@ const char cgi_rcs[] = "$Id: cgi.c,v 1.103 2008/03/21 11:13:57 fabiankeil Exp $" * * Revisions : * $Log: cgi.c,v $ + * Revision 1.104 2008/03/26 18:07:06 fabiankeil + * Add hostname directive. Closes PR#1918189. + * * Revision 1.103 2008/03/21 11:13:57 fabiankeil * Only gather host information if it's actually needed. * Also move the code out of accept_connection() so it's less likely @@ -1929,19 +1932,18 @@ char *add_help_link(const char *item, * HTTP header - e.g.: * "Sun, 06 Nov 1994 08:49:37 GMT" * - * XXX: Should probably get a third parameter for - * the buffer size. - * * Parameters : * 1 : time_offset = Time returned will be current time * plus this number of seconds. - * 2 : buf = Destination for result. Must be long enough - * to hold 29 characters plus a trailing zero. + * 2 : buf = Destination for result. + * 3 : buffer_size = Size of the buffer above. Must be big + * enough to hold 29 characters plus a + * trailing zero. * * Returns : N/A * *********************************************************************/ -void get_http_time(int time_offset, char *buf) +void get_http_time(int time_offset, char *buf, size_t buffer_size) { static const char day_names[7][4] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; @@ -1962,6 +1964,7 @@ void get_http_time(int time_offset, char *buf) #endif assert(buf); + assert(buffer_size > 29); time(¤t_time); /* get current time */ @@ -1981,7 +1984,7 @@ void get_http_time(int time_offset, char *buf) } /* Format: "Sun, 06 Nov 1994 08:49:37 GMT" */ - snprintf(buf, 30, + snprintf(buf, buffer_size, "%s, %02d %s %4d %02d:%02d:%02d GMT", day_names[t->tm_wday], t->tm_mday, @@ -2093,7 +2096,7 @@ struct http_response *finish_http_response(const struct client_state *csp, struc if (!err) { - get_http_time(0, buf); + get_http_time(0, buf, sizeof(buf)); err = enlist_unique_header(rsp->headers, "Date", buf); } @@ -2102,13 +2105,13 @@ struct http_response *finish_http_response(const struct client_state *csp, struc if (!err) { - get_http_time(10 * 60, buf); /* 10 * 60sec = 10 minutes */ + get_http_time(10 * 60, buf, sizeof(buf)); /* 10 * 60sec = 10 minutes */ err = enlist_unique_header(rsp->headers, "Expires", buf); } } else if (!strncmpic(rsp->status, "302", 3)) { - get_http_time(0, buf); + get_http_time(0, buf, sizeof(buf)); if (!err) err = enlist_unique_header(rsp->headers, "Date", buf); } else @@ -2134,7 +2137,7 @@ struct http_response *finish_http_response(const struct client_state *csp, struc */ if (!err) err = enlist_unique_header(rsp->headers, "Cache-Control", "no-cache"); - get_http_time(0, buf); + get_http_time(0, buf, sizeof(buf)); if (!err) err = enlist_unique_header(rsp->headers, "Date", buf); if (!strncmpic(rsp->status, "403", 3) || !strncmpic(rsp->status, "404", 3) diff --git a/cgi.h b/cgi.h index 73442cf1..c73ca201 100644 --- a/cgi.h +++ b/cgi.h @@ -1,6 +1,6 @@ #ifndef CGI_H_INCLUDED #define CGI_H_INCLUDED -#define CGI_H_VERSION "$Id: cgi.h,v 1.32 2006/12/17 17:53:39 fabiankeil Exp $" +#define CGI_H_VERSION "$Id: cgi.h,v 1.33 2007/01/28 13:41:17 fabiankeil Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/cgi.h,v $ @@ -38,6 +38,10 @@ * * Revisions : * $Log: cgi.h,v $ + * Revision 1.33 2007/01/28 13:41:17 fabiankeil + * - Add HEAD support to finish_http_response. + * - Add error favicon to internal HTML error messages. + * * Revision 1.32 2006/12/17 17:53:39 fabiankeil * Suppress the toggle link if remote toggling is disabled. * @@ -248,7 +252,7 @@ extern char get_char_param(const struct map *parameters, /* * Text generators */ -extern void get_http_time(int time_offset, char * buf); +extern void get_http_time(int time_offset, char *buf, size_t buffer_size); extern char *add_help_link(const char *item, struct configuration_spec *config); extern char *make_menu(const char *self, const unsigned feature_flags); extern char *dump_map(const struct map *the_map); diff --git a/cgisimple.c b/cgisimple.c index 5eb89314..373cb978 100644 --- a/cgisimple.c +++ b/cgisimple.c @@ -1,4 +1,4 @@ -const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.67 2008/03/27 17:00:05 fabiankeil Exp $"; +const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.68 2008/03/27 18:27:21 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/cgisimple.c,v $ @@ -36,6 +36,9 @@ const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.67 2008/03/27 17:00:05 fabian * * Revisions : * $Log: cgisimple.c,v $ + * Revision 1.68 2008/03/27 18:27:21 fabiankeil + * Remove kill-popups action. + * * Revision 1.67 2008/03/27 17:00:05 fabiankeil * Turn the favicon blobs into locals. * @@ -1795,7 +1798,7 @@ jb_err cgi_robots_txt(struct client_state *csp, rsp->is_static = 1; - get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */ + get_http_time(7 * 24 * 60 * 60, buf, sizeof(buf)); /* 7 days into future */ if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf); return (err ? JB_ERR_MEMORY : JB_ERR_OK); diff --git a/parsers.c b/parsers.c index 10033023..f3f5c86b 100644 --- a/parsers.c +++ b/parsers.c @@ -1,4 +1,4 @@ -const char parsers_rcs[] = "$Id: parsers.c,v 1.123 2008/03/29 12:13:46 fabiankeil Exp $"; +const char parsers_rcs[] = "$Id: parsers.c,v 1.124 2008/04/16 16:38:21 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/parsers.c,v $ @@ -44,6 +44,10 @@ const char parsers_rcs[] = "$Id: parsers.c,v 1.123 2008/03/29 12:13:46 fabiankei * * Revisions : * $Log: parsers.c,v $ + * Revision 1.124 2008/04/16 16:38:21 fabiankeil + * Don't pass the whole csp structure to flush_socket() + * when it only needs a file descriptor and a buffer. + * * Revision 1.123 2008/03/29 12:13:46 fabiankeil * Remove send-wafer and send-vanilla-wafer actions. * @@ -2582,7 +2586,7 @@ static jb_err server_last_modified(struct client_state *csp, char **header) /* * Setting Last-Modified Header to now. */ - get_http_time(0, buf); + get_http_time(0, buf, sizeof(buf)); freez(*header); *header = strdup("Last-Modified: "); string_append(header, buf); diff --git a/parsers.h b/parsers.h index 0ddccf8a..161a9d65 100644 --- a/parsers.h +++ b/parsers.h @@ -1,6 +1,6 @@ #ifndef PARSERS_H_INCLUDED #define PARSERS_H_INCLUDED -#define PARSERS_H_VERSION "$Id: parsers.h,v 1.40 2007/08/11 14:47:26 fabiankeil Exp $" +#define PARSERS_H_VERSION "$Id: parsers.h,v 1.41 2008/04/16 16:38:21 fabiankeil Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/parsers.h,v $ @@ -43,6 +43,10 @@ * * Revisions : * $Log: parsers.h,v $ + * Revision 1.41 2008/04/16 16:38:21 fabiankeil + * Don't pass the whole csp structure to flush_socket() + * when it only needs a file descriptor and a buffer. + * * Revision 1.40 2007/08/11 14:47:26 fabiankeil * Remove the prototypes for functions that are only * used in parsers.c and thus should be static. @@ -267,7 +271,7 @@ extern jb_err decompress_iob(struct client_state *csp); extern char *get_header(struct client_state *csp); extern char *get_header_value(const struct list *header_list, const char *header_name); extern jb_err sed(const struct parsers pats[], const add_header_func_ptr more_headers[], struct client_state *csp); -extern void get_http_time(int time_offset, char *buf); +extern void get_http_time(int time_offset, char *buf, size_t buffer_size); extern jb_err get_destination_from_headers(const struct list *headers, struct http_request *http); #ifdef FEATURE_FORCE_LOAD -- 2.39.2