diff options
-rw-r--r-- | src/or/config.c | 35 | ||||
-rw-r--r-- | src/or/routerlist.c | 23 | ||||
-rw-r--r-- | src/or/routerparse.c | 46 |
3 files changed, 45 insertions, 59 deletions
diff --git a/src/or/config.c b/src/or/config.c index e88c03e6e..fba4adef3 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -154,7 +154,8 @@ static int config_compare(struct config_line_t *c, const char *key, config_type_ case CONFIG_TYPE_CSV: if(*(smartlist_t**)arg == NULL) *(smartlist_t**)arg = smartlist_create(); - smartlist_split_string(*(smartlist_t**)arg, c->value, ",", 1); + smartlist_split_string(*(smartlist_t**)arg, c->value, ",", + SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0); break; case CONFIG_TYPE_LINELIST: /* Note: this reverses the order that the lines appear in. That's @@ -980,9 +981,7 @@ config_parse_exit_policy(struct config_line_t *cfg, struct exit_policy_t **dest) { struct exit_policy_t **nextp; - char *e, *s; - int last=0; - char line[1024]; + smartlist_t *entries; if (!cfg) return; @@ -990,30 +989,22 @@ config_parse_exit_policy(struct config_line_t *cfg, while (*nextp) nextp = &((*nextp)->next); + entries = smartlist_create(); for (; cfg; cfg = cfg->next) { - s = cfg->value; - for (;;) { - e = strchr(s,','); - if(!e) { - last = 1; - strncpy(line,s,1023); - } else { - memcpy(line,s, ((e-s)<1023)?(e-s):1023); - line[e-s] = 0; - } - line[1023]=0; - log_fn(LOG_DEBUG,"Adding new entry '%s'",line); - *nextp = router_parse_exit_policy_from_string(line); + smartlist_split_string(entries,cfg->value,",",SPLIT_SKIP_SPACE,0); + SMARTLIST_FOREACH(entries, const char *, ent, { + log_fn(LOG_DEBUG,"Adding new entry '%s'",ent); + *nextp = router_parse_exit_policy_from_string(ent); if(*nextp) { nextp = &((*nextp)->next); } else { - log_fn(LOG_WARN,"Malformed exit policy %s; skipping.", line); + log_fn(LOG_WARN,"Malformed exit policy %s; skipping.", ent); } - if (last) - break; - s = e+1; - } + }); + SMARTLIST_FOREACH(entries, char *, ent, tor_free(ent)); + smartlist_clear(entries); } + smartlist_free(entries); } void exit_policy_free(struct exit_policy_t *p) { diff --git a/src/or/routerlist.c b/src/or/routerlist.c index ed932dc41..4b10b3c90 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -155,25 +155,22 @@ int all_directory_servers_down(void) { void add_nickname_list_to_smartlist(smartlist_t *sl, const char *list, int warn_if_down) { - const char *start,*end; - char nick[MAX_HEX_NICKNAME_LEN+1]; routerinfo_t *router; + smartlist_t *nickname_list; tor_assert(sl); tor_assert(list); - while(isspace((int)*list) || *list==',') list++; + nickname_list = smartlist_create(); - start = list; - while(*start) { - end=start; while(*end && !isspace((int)*end) && *end != ',') end++; - if (end-start > MAX_HEX_NICKNAME_LEN) { + smartlist_split_string(nickname_list, list, ",", + SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0); + + SMARTLIST_FOREACH(nickname_list, const char *, nick, { + if (strlen(nick) > MAX_HEX_NICKNAME_LEN) { log_fn(LOG_WARN,"Nickname too long; skipping"); - start = end; continue; } - memcpy(nick,start,end-start); - nick[end-start] = 0; /* null terminate it */ router = router_get_by_nickname(nick); if (router) { if (router->is_running) @@ -184,9 +181,9 @@ add_nickname_list_to_smartlist(smartlist_t *sl, const char *list, int warn_if_do } else log_fn(has_fetched_directory ? LOG_WARN : LOG_INFO, "Nickname list includes '%s' which isn't a known router.",nick); - while(isspace((int)*end) || *end==',') end++; - start = end; - } + }); + SMARTLIST_FOREACH(nickname_list, char *, nick, tor_free(nick)); + smartlist_free(nickname_list); } /** Add every router from our routerlist that is currently running to diff --git a/src/or/routerparse.c b/src/or/routerparse.c index c12d07f61..c970851b9 100644 --- a/src/or/routerparse.c +++ b/src/or/routerparse.c @@ -172,7 +172,7 @@ get_recommended_software_from_directory(const char *str) const char *cp = str, *eol; int len = strlen(REC); cp = str; - if (strncmp(str, REC, len)==0) { + if (strcmpstart(str, REC)==0) { cp += len; } else { cp = strstr(str, "\n"REC); @@ -196,10 +196,10 @@ get_recommended_software_from_directory(const char *str) /* static */ int is_obsolete_version(const char *myversion, const char *versionlist) { const char *vl; - char *version, *comma, *cp; tor_version_t mine, other; - int found_newer = 0, r; + int found_newer = 0, r, ret; static int warned_too_new=0; + smartlist_t *version_sl; vl = versionlist; @@ -209,14 +209,11 @@ get_recommended_software_from_directory(const char *str) log_fn(LOG_ERR, "I couldn't parse my own version (%s)", myversion); tor_assert(0); } + version_sl = smartlist_create(); + smartlist_split_string(version_sl, versionlist, ",", SPLIT_SKIP_SPACE, 0); - for(;;) { - comma = strchr(vl, ','); - version = tor_strndup(vl, comma?(comma-vl):strlen(vl)); - cp = version; - while (isspace((int)*cp)) - ++cp; - if (!strncmp(cp, "Tor ", 4)) + SMARTLIST_FOREACH(version_sl, const char *, cp, { + if (!strcmpstart(cp, "Tor ")) cp += 4; if (tor_version_parse(cp, &other)) { @@ -224,28 +221,29 @@ get_recommended_software_from_directory(const char *str) } else { r = tor_version_compare(&mine, &other); if (r==0) { - tor_free(version); - return 0; /* It's a match. */ + ret = 0; + goto done; } else if (r<0) { found_newer = 1; } } - tor_free(version); - if (comma) - vl = comma+1; - else - break; - } + }); + if (!found_newer) { if (!warned_too_new) { log_fn(LOG_WARN, "This version of Tor (%s) is newer than any on the recommended list (%s)", myversion, versionlist); warned_too_new=1; } - return 0; + ret = 0; } else { - return 1; + ret = 1; } + + done: + SMARTLIST_FOREACH(version_sl, char *, version, tor_free(version)); + smartlist_free(version_sl); + return ret; } /* Return 0 if myversion is supported; else log a message and return @@ -1162,13 +1160,13 @@ get_next_token(const char **s, where_syntax where) { } } *s = eat_whitespace(*s); - if (strncmp(*s, "-----BEGIN ", 11)) { + if (strcmpstart(*s, "-----BEGIN ")) { goto done_tokenizing; } obstart = *s; *s += 11; /* length of "-----BEGIN ". */ next = strchr(*s, '\n'); - if (next-*s < 6 || strncmp(next-5, "-----\n", 6)) { + if (next-*s < 6 || strcmpstart(next-5, "-----\n")) { RET_ERR("Malformed object: bad begin line"); } tok->object_type = tor_strndup(*s, next-*s-5); @@ -1178,7 +1176,7 @@ get_next_token(const char **s, where_syntax where) { RET_ERR("Malformed object: missing end line"); } if (!strcmp(tok->object_type, "RSA PUBLIC KEY")) { - if (strncmp(next, "-----END RSA PUBLIC KEY-----\n", 29)) + if (strcmpstart(next, "-----END RSA PUBLIC KEY-----\n")) RET_ERR("Malformed object: mismatched end line"); next = strchr(next,'\n')+1; tok->key = crypto_new_pk_env(); @@ -1194,7 +1192,7 @@ get_next_token(const char **s, where_syntax where) { tok->object_size = i; *s = next + 9; /* length of "-----END ". */ i = strlen(tok->object_type); - if (strncmp(*s, tok->object_type, i) || strncmp(*s+i, "-----\n", 6)) { + if (strncmp(*s, tok->object_type, i) || strcmpstart(*s+i, "-----\n")) { RET_ERR("Malformed object: mismatched end tag"); } *s += i+6; |