@cryptotaxi247 / netdata-1 / commits / 5dd111b48

prevent buffer overflow

Costa Tsaousis (ktsaou) committed Jan 19, 2017 at 23:04 UTC 5dd111b4884c32db34a6f15810a359876e1b2a65
1 file changed +3 -2
src/inlined.h
+3 -2
@@ -78,7 +78,7 @@ static inline unsigned long long str2ull(const char *s) {
78 }
79
80 static inline int read_single_number_file(const char *filename, unsigned long long *result) {
81 - char buffer[1024 + 1];
81 + char buffer[30 + 1];
82
83 int fd = open(filename, O_RDONLY, 0666);
84 if(unlikely(fd == -1)) {
@@ -86,7 +86,7 @@ static inline int read_single_number_file(const char *filename, unsigned long lo
86 return 1;
87 }
88
89 - ssize_t r = read(fd, buffer, 1024);
89 + ssize_t r = read(fd, buffer, 30);
90 if(unlikely(r == -1)) {
91 *result = 0;
92 close(fd);
@@ -94,6 +94,7 @@ static inline int read_single_number_file(const char *filename, unsigned long lo
94 }
95
96 close(fd);
97 + buffer[30] = '\0';
98 *result = str2ull(buffer);
99 return 0;
100 }