Commit 690c7be2 authored by Nick Mathewson's avatar Nick Mathewson 🎨
Browse files

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
parent 49ce31b2
Pipeline #3682 passed with stage
in 19 minutes and 7 seconds
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
......@@ -5,4 +5,5 @@ lib/fs/*.h
......@@ -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"
#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 */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment