Commit 1060b4d8 authored by Mike Perry's avatar Mike Perry
Browse files

Fix issues found by Nick in code review.

parent ca676c39
Loading
Loading
Loading
Loading
+14 −15
Original line number Diff line number Diff line
@@ -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,13 +2396,13 @@ dirserv_read_measured_bandwidths(const char *from_file,

  while (!feof(fp)) {
    measured_bw_line_t parsed_line;
    fgets(line, sizeof(line), fp);

    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++;
      }
    }
  }

  fclose(fp);
  log_notice(LD_DIRSERV,
+3 −5
Original line number Diff line number Diff line
@@ -3544,11 +3544,9 @@ typedef struct measured_bw_line_t {
  long int bw;
} measured_bw_line_t;

int
measured_bw_line_parse(measured_bw_line_t *out, const char *line);
int measured_bw_line_parse(measured_bw_line_t *out, const char *line);

int
measured_bw_line_apply(measured_bw_line_t *parsed_line,
int measured_bw_line_apply(measured_bw_line_t *parsed_line,
                           smartlist_t *routerstatuses);
#endif