tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

commit 690c7be2537dc30be2d1f4978af7df77c46c2782
parent 49ce31b2b6c0cfbcccb605ee58b612f73e2a228a
Author: Nick Mathewson <nickm@torproject.org>
Date:   Wed,  3 Mar 2021 14:52:15 -0500

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:
Achanges/bug40315 | 5+++++
Msrc/lib/meminfo/.may_include | 1+
Msrc/lib/meminfo/meminfo.c | 3++-
3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/changes/bug40315 b/changes/bug40315 @@ -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. diff --git a/src/lib/meminfo/.may_include b/src/lib/meminfo/.may_include @@ -5,4 +5,5 @@ lib/fs/*.h lib/log/*.h lib/malloc/*.h lib/meminfo/*.h +lib/string/*.h lib/testsupport/*.h diff --git 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 */