diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-05-02 08:46:28 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-05-02 08:46:28 -0400 |
commit | 246765342e681ae6f8c35709f9acd9a78d7048d2 (patch) | |
tree | 68e30cbf3d55d63dfa4263172ed6ad7e3d8ec8fb /src/or/dirserv.c | |
parent | 7c3f87eb4b2c3c4ce3422b3561bee36f3c9956c1 (diff) | |
parent | 993e314c6f08d587480070e9f19d313b81b39a09 (diff) | |
download | tor-246765342e681ae6f8c35709f9acd9a78d7048d2.tar.gz tor-246765342e681ae6f8c35709f9acd9a78d7048d2.zip |
Merge branch 'maint-0.3.1' into maint-0.3.2
Diffstat (limited to 'src/or/dirserv.c')
-rw-r--r-- | src/or/dirserv.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/or/dirserv.c b/src/or/dirserv.c index ff85dfa2ac..95bef9889d 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -2781,14 +2781,23 @@ dirserv_read_measured_bandwidths(const char *from_file, time_t file_time, now; int ok; + /* Initialise line, so that we can't possibly run off the end. */ + memset(line, 0, sizeof(line)); + if (fp == NULL) { log_warn(LD_CONFIG, "Can't open bandwidth file at configured location: %s", from_file); return -1; } - if (!fgets(line, sizeof(line), fp) - || !strlen(line) || line[strlen(line)-1] != '\n') { + /* If fgets fails, line is either unmodified, or indeterminate. */ + if (!fgets(line, sizeof(line), fp)) { + log_warn(LD_DIRSERV, "Empty bandwidth file"); + fclose(fp); + return -1; + } + + if (!strlen(line) || line[strlen(line)-1] != '\n') { log_warn(LD_DIRSERV, "Long or truncated time in bandwidth file: %s", escaped(line)); fclose(fp); |