summaryrefslogtreecommitdiff
blob: d1b4d8cd9197134b5d98c3d8ce5ba06562e86849 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
commit d1d5f1c46aebf480af7c46d64b3fc0f75814946d
Author: Palmer Dabbelt <palmer@dabbelt.com>
Date:   Fri Dec 5 15:47:25 2014 -0800

    Check that the username/password files aren't empty
    
    This would have caused a bit of undefined behavior due to some
    uninitialized stack buffers.

diff --git a/src/libmhng/mailbox.c++ b/src/libmhng/mailbox.c++
index a21f9ab..794a74b 100644
--- a/src/libmhng/mailbox.c++
+++ b/src/libmhng/mailbox.c++
@@ -195,7 +195,10 @@ std::string mailbox::username(void) const
     }
 
     char line[BUFFER_SIZE];
-    fgets(line, BUFFER_SIZE, file);
+    if (fgets(line, BUFFER_SIZE, file) == NULL) {
+        fprintf(stderr, "Empty username file\n");
+        abort();
+    }
     while (isspace(line[strlen(line)-1]))
         line[strlen(line)-1] = '\0';
 
@@ -218,7 +221,10 @@ std::string mailbox::password(void) const
     }
 
     char line[BUFFER_SIZE];
-    fgets(line, BUFFER_SIZE, file);
+    if (fgets(line, BUFFER_SIZE, file) == NULL) {
+        fprintf(stderr, "Empty password file\n");
+        abort();
+    }
     while (isspace(line[strlen(line)-1]))
         line[strlen(line)-1] = '\0';