From: Fabian Keil Date: Mon, 19 May 2008 17:18:04 +0000 (+0000) Subject: Wrap memmove() calls in string_move() X-Git-Tag: v_3_0_9~93 X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=commitdiff_plain;h=50466af8d124eb564f6171ea68fcaecd0ef6ed16 Wrap memmove() calls in string_move() to document the purpose in one place. --- diff --git a/parsers.c b/parsers.c index aa0cd169..e64d93d9 100644 --- a/parsers.c +++ b/parsers.c @@ -1,4 +1,4 @@ -const char parsers_rcs[] = "$Id: parsers.c,v 1.128 2008/05/16 16:39:03 fabiankeil Exp $"; +const char parsers_rcs[] = "$Id: parsers.c,v 1.129 2008/05/17 14:02:07 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/parsers.c,v $ @@ -44,6 +44,9 @@ const char parsers_rcs[] = "$Id: parsers.c,v 1.128 2008/05/16 16:39:03 fabiankei * * Revisions : * $Log: parsers.c,v $ + * Revision 1.129 2008/05/17 14:02:07 fabiankeil + * Normalize linear header white space. + * * Revision 1.128 2008/05/16 16:39:03 fabiankeil * If a header is split across multiple lines, * merge them to a single line before parsing them. @@ -1441,6 +1444,31 @@ jb_err decompress_iob(struct client_state *csp) #endif /* defined(FEATURE_ZLIB) */ +/********************************************************************* + * + * Function : string_move + * + * Description : memmove wrapper to move the last part of a string + * towards the beginning, overwriting the part in + * the middle. strlcpy() can't be used here as the + * strings overlap. + * + * Parameters : + * 1 : dst = Destination to overwrite + * 2 : src = Source to move. + * + * Returns : N/A + * + *********************************************************************/ +static void string_move(char *dst, char *src) +{ + assert(dst < src); + + /* +1 to copy the terminating nul as well. */ + memmove(dst, src, strlen(src)+1); +} + + /********************************************************************* * * Function : normalize_lws @@ -1473,7 +1501,7 @@ static void normalize_lws(char *header) q++; } log_error(LOG_LEVEL_HEADER, "Reducing white space in '%s'", header); - memmove(p+1, q, strlen(q)+1); + string_move(p+1, q); } if (*p == '\t') @@ -1507,7 +1535,7 @@ static void normalize_lws(char *header) * There's still space before the colon. * We don't want it. */ - memmove(p-1, p, strlen(p)+1); + string_move(p-1, p); } } @@ -3978,7 +4006,7 @@ static jb_err server_set_cookie(struct client_state *csp, char **header) */ log_error(LOG_LEVEL_ERROR, "Can't parse \'%s\', send by %s. Unsupported time format?", cur_tag, csp->http->url); - memmove(cur_tag, next_tag, strlen(next_tag) + 1); + string_move(cur_tag, next_tag); changed = 1; } else @@ -4029,12 +4057,8 @@ static jb_err server_set_cookie(struct client_state *csp, char **header) /* * Still valid, delete expiration date by copying * the rest of the string over it. - * - * (Note that we cannot just use "strcpy(cur_tag, next_tag)", - * since the behaviour of strcpy is undefined for overlapping - * strings.) */ - memmove(cur_tag, next_tag, strlen(next_tag) + 1); + string_move(cur_tag, next_tag); /* That changed the header, need to issue a log message */ changed = 1;