]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Fix parsing bug in linux get_total_system_memory().
authorNick Mathewson <nickm@torproject.org>
Wed, 3 Mar 2021 19:52:15 +0000 (14:52 -0500)
committerNick Mathewson <nickm@torproject.org>
Wed, 3 Mar 2021 19:52:15 +0000 (14:52 -0500)
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.

changes/bug40315 [new file with mode: 0644]
src/lib/meminfo/.may_include
src/lib/meminfo/meminfo.c

diff --git a/changes/bug40315 b/changes/bug40315
new file mode 100644 (file)
index 0000000..9e9c740
--- /dev/null
@@ -0,0 +1,5 @@
+  o Minor bugfixes (Linux, relay):
+    - Fix a bug in determining total available system memory that would have
+      been triggered if the format of /proc/meminfo had ever changed
+      to include "MemTotal:" in the middle of a line. Fixes bug 40315;
+      bugfix on 0.2.5.4-alpha.
index 9e4d25fd6a241362cb603efd4f19def69fd93983..12fe36d1342eb8cd745b5622627fbf644ca7e864 100644 (file)
@@ -5,4 +5,5 @@ lib/fs/*.h
 lib/log/*.h
 lib/malloc/*.h
 lib/meminfo/*.h
+lib/string/*.h
 lib/testsupport/*.h
index b7d991e4104303355a94ee871f01e763b453bee7..77da579f9942b3ad72052e95eb21041363aeb7a9 100644 (file)
@@ -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 */