X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=list.c;h=e0736d39fa28b929db455dcbb4a43cd987562399;hp=15f5cee20937de5031b1a186a0d9bc78a49a947a;hb=3010d66d9bf05c41787d589e6a9584dbbded8206;hpb=83a4ca758c4dccd313f23f9d736f43c34e16e08a diff --git a/list.c b/list.c index 15f5cee2..e0736d39 100644 --- a/list.c +++ b/list.c @@ -1,11 +1,11 @@ -const char list_rcs[] = "$Id: list.c,v 1.25 2011/09/04 11:10:56 fabiankeil Exp $"; +const char list_rcs[] = "$Id: list.c,v 1.32 2014/11/14 10:39:49 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/list.c,v $ * * Purpose : Declares functions to handle lists. * - * Copyright : Written by and Copyright (C) 2001-2007 the SourceForge + * Copyright : Written by and Copyright (C) 2001-2007 members of the * Privoxy team. http://www.privoxy.org/ * * Based on the Internet Junkbuster originally written @@ -351,7 +351,7 @@ jb_err enlist_unique(struct list *the_list, const char *str, { for (cur_entry = the_list->first; cur_entry != NULL; cur_entry = cur_entry->next) { - if ( (cur_entry->str != NULL) + if ((cur_entry->str != NULL) && (0 == strncmp(str, cur_entry->str, num_significant_chars))) { /* Already there */ @@ -364,7 +364,7 @@ jb_err enlist_unique(struct list *the_list, const char *str, /* Test whole string */ for (cur_entry = the_list->first; cur_entry != NULL; cur_entry = cur_entry->next) { - if ( (cur_entry->str != NULL) && (0 == strcmp(str, cur_entry->str))) + if ((cur_entry->str != NULL) && (0 == strcmp(str, cur_entry->str))) { /* Already there */ return JB_ERR_OK; @@ -415,8 +415,24 @@ jb_err enlist_unique_header(struct list *the_list, const char *name, if (NULL != header) { const size_t bytes_to_compare = strlen(name) + 2; + char *p = header; snprintf(header, header_size, "%s: %s", name, value); + /* + * The trailing "\r\n" is added by list_to_text(), + * if the caller passed them anyway, cut the header + * at the first one or dump core if this is a debug + * build. + */ + do + { + if ((*p == '\r') || (*p == '\n')) + { + assert(*p != '\r'); + assert(*p != '\n'); + *p = '\0'; + } + } while (*p++); result = enlist_unique(the_list, header, bytes_to_compare); free(header); assert(list_is_valid(the_list)); @@ -860,15 +876,24 @@ int list_contains_item(const struct list *the_list, const char *str) * Function : new_map * * Description : Create a new, empty map. + * Causes program exit if the memory allocation fails. * * Parameters : N/A * - * Returns : A new, empty map, or NULL if out of memory. + * Returns : A new, empty map * *********************************************************************/ struct map *new_map(void) { - return (struct map *) zalloc(sizeof(struct map)); + struct map *empty_map = zalloc(sizeof(struct map)); + + if (NULL == empty_map) + { + exit(1); + } + + return empty_map; + } @@ -877,7 +902,7 @@ struct map *new_map(void) * Function : free_map * * Description : Free the memory occupied by a map and its - * depandant strings + * dependent strings * * Parameters : * 1 : the_map = map to be freed. May be NULL. @@ -963,7 +988,7 @@ jb_err map(struct map *the_map, if ( (NULL == value) || (NULL == name) - || (NULL == (new_entry = zalloc(sizeof(*new_entry)))) ) + || (NULL == (new_entry = zalloc(sizeof(*new_entry))))) { if ((name != NULL) && (!name_needs_copying)) { @@ -1039,7 +1064,7 @@ jb_err unmap(struct map *the_map, const char *name) assert(the_map); assert(name); - last_entry = the_map->first; + last_entry = NULL; for (cur_entry = the_map->first; cur_entry != NULL; cur_entry = cur_entry->next) { @@ -1071,7 +1096,11 @@ jb_err unmap(struct map *the_map, const char *name) freez(cur_entry->name); freez(cur_entry->value); freez(cur_entry); - + if (last_entry == NULL) + { + /* The map only had a single entry which has just been removed. */ + break; + } cur_entry = last_entry; } else