diff options
author | Mike Perry <mikeperry-git@fscked.org> | 2009-08-09 18:21:15 -0700 |
---|---|---|
committer | Mike Perry <mikeperry-git@fscked.org> | 2009-08-09 18:21:15 -0700 |
commit | 1060b4d82429c743b6209f7e0a5a2c6bca0a6450 (patch) | |
tree | 4949a8e67bef2caff55c236bd3f8f9621b39e31b /src/or/dirserv.c | |
parent | ca676c3924e58f5e07c749678d22315073dd0946 (diff) | |
download | tor-1060b4d82429c743b6209f7e0a5a2c6bca0a6450.tar.gz tor-1060b4d82429c743b6209f7e0a5a2c6bca0a6450.zip |
Fix issues found by Nick in code review.
Diffstat (limited to 'src/or/dirserv.c')
-rw-r--r-- | src/or/dirserv.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/src/or/dirserv.c b/src/or/dirserv.c index 1a47173686..32ddcd0b0a 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -1943,7 +1943,7 @@ routerstatus_format_entry(char *buf, size_t buf_len, if (format != NS_V2) { routerinfo_t* desc = router_get_by_digest(rs->identity_digest); - u_int32_t bw; + uint32_t bw; if (format != NS_CONTROL_PORT) { /* Blow up more or less nicely if we didn't get anything or not the @@ -2270,7 +2270,8 @@ measured_bw_line_parse(measured_bw_line_t *out, const char *orig_line) } do { - if (strncasecmp(cp, "bw=", strlen("bw=")) == 0) { + if (strcmpstart(cp, "bw=") == 0) { + int parse_ok = 0; char *endptr; if (got_bw) { log_warn(LD_DIRSERV, "Double bw= in bandwidth file line: %s", @@ -2279,17 +2280,16 @@ measured_bw_line_parse(measured_bw_line_t *out, const char *orig_line) return -1; } cp+=strlen("bw="); - errno=0; - out->bw = strtol(cp, &endptr, 0); - if (errno || endptr == cp || (*endptr && !TOR_ISSPACE(*endptr)) || - out->bw < 0) { + + out->bw = tor_parse_long(cp, 0, 0, LONG_MAX, &parse_ok, &endptr); + if (!parse_ok || (*endptr && !TOR_ISSPACE(*endptr))) { log_warn(LD_DIRSERV, "Invalid bandwidth in bandwidth file line: %s", escaped(orig_line)); tor_free(line); return -1; } got_bw=1; - } else if (strncasecmp(cp, "node_id=$", strlen("node_id=$")) == 0) { + } else if (strcmpstart(cp, "node_id=$") == 0) { if (got_node_id) { log_warn(LD_DIRSERV, "Double node_id= in bandwidth file line: %s", escaped(orig_line)); @@ -2367,9 +2367,8 @@ dirserv_read_measured_bandwidths(const char *from_file, return -1; } - fgets(line, sizeof(line), fp); - - if (line[strlen(line)-1] != '\n') { + if (!fgets(line, sizeof(line), fp) + || !strlen(line) || line[strlen(line)-1] != '\n') { log_warn(LD_DIRSERV, "Long or truncated time in bandwidth file: %s", escaped(line)); fclose(fp); @@ -2397,11 +2396,11 @@ dirserv_read_measured_bandwidths(const char *from_file, while (!feof(fp)) { measured_bw_line_t parsed_line; - fgets(line, sizeof(line), fp); - - if (measured_bw_line_parse(&parsed_line, line) != -1) { - if (measured_bw_line_apply(&parsed_line, routerstatuses) > 0) - applied_lines++; + if (fgets(line, sizeof(line), fp) && strlen(line)) { + if (measured_bw_line_parse(&parsed_line, line) != -1) { + if (measured_bw_line_apply(&parsed_line, routerstatuses) > 0) + applied_lines++; + } } } |