aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-05-02 08:46:28 -0400
committerNick Mathewson <nickm@torproject.org>2018-05-02 08:46:28 -0400
commit8625f36de1085cb24e532adb0bb76d3d2b6b5808 (patch)
tree1ee1e0c7bacb560cd34d5a0e06d61622527f66d9 /src
parentf26d6ead21015b7ba6f7d72ebfc2ebf29da0863b (diff)
parentc66b512671cf1711c7325db664335f1694bb3109 (diff)
downloadtor-8625f36de1085cb24e532adb0bb76d3d2b6b5808.tar.gz
tor-8625f36de1085cb24e532adb0bb76d3d2b6b5808.zip
Merge branch 'maint-0.3.3'
Diffstat (limited to 'src')
-rw-r--r--src/or/dirserv.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index 61383aa861..e058e04f8b 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -2569,14 +2569,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);