summaryrefslogtreecommitdiff
path: root/src/lib/meminfo/meminfo.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2021-03-03 14:52:15 -0500
committerNick Mathewson <nickm@torproject.org>2021-03-03 14:52:15 -0500
commit690c7be2537dc30be2d1f4978af7df77c46c2782 (patch)
tree1fd8e0ee410ae63932c3e515f16091dbbc6514c2 /src/lib/meminfo/meminfo.c
parent49ce31b2b6c0cfbcccb605ee58b612f73e2a228a (diff)
downloadtor-690c7be2537dc30be2d1f4978af7df77c46c2782.tar.gz
tor-690c7be2537dc30be2d1f4978af7df77c46c2782.zip
Fix parsing bug in linux get_total_system_memory().
Use find_str_at_start_of_line(), not strstr() here: we don't want to match "MemTotal: " if it appears in the middle of a line. Fixes #40315; bugfix on 0.2.5.4-alpha.
Diffstat (limited to 'src/lib/meminfo/meminfo.c')
-rw-r--r--src/lib/meminfo/meminfo.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/lib/meminfo/meminfo.c b/src/lib/meminfo/meminfo.c
index b7d991e410..77da579f99 100644
--- a/src/lib/meminfo/meminfo.c
+++ b/src/lib/meminfo/meminfo.c
@@ -17,6 +17,7 @@
#include "lib/fs/files.h"
#include "lib/log/log.h"
#include "lib/malloc/malloc.h"
+#include "lib/string/util_string.h"
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
@@ -65,7 +66,7 @@ get_total_system_memory_impl(void)
s = read_file_to_str_until_eof(fd, 65536, &file_size);
if (!s)
goto err;
- cp = strstr(s, "MemTotal:");
+ cp = find_str_at_start_of_line(s, "MemTotal:");
if (!cp)
goto err;
/* Use the system sscanf so that space will match a wider number of space */