Skip to content

Commit

Permalink
Detect an unlikely integer overflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmathewson committed Sep 27, 2018
1 parent 9e65e7a commit b058f64
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/feature/stats/geoip_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,10 @@ geoip_note_client_seen(geoip_client_action_t action,
int country_idx = geoip_get_country_by_addr(addr);
if (country_idx < 0)
country_idx = 0; /** unresolved requests are stored at index 0. */
increment_v3_ns_request(country_idx);
IF_BUG_ONCE(country_idx > COUNTRY_MAX) {
return;
}
increment_v3_ns_request((country_t) country_idx);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/lib/geoip/country.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@
/** A signed integer representing a country code. */
typedef int16_t country_t;

#define COUNTRY_MAX INT16_MAX

#endif

0 comments on commit b058f64

Please sign in to comment.