Skip to content

Commit

Permalink
[GTK][WPE] CGroupMemoryController::getCgroupFileValue not stack if no…
Browse files Browse the repository at this point in the history
…t numerical value is scanned from the file input (e.g: max)

https://bugs.webkit.org/show_bug.cgi?id=273931

Reviewed by Carlos Alberto Lopez Perez.

Improves the CGroupMemoryController::getCgroupFileValue by ensuring it
handles non-numeric values (e.g., max).

Fixes TestNetworkProcessMemoryPressure API test (webkit.org/b/263016).

* Source/WebKit/UIProcess/linux/MemoryPressureMonitor.cpp:
(WebKit::CGroupMemoryController::getCgroupFileValue):
* Tools/TestWebKitAPI/glib/TestExpectations.json:

Canonical link: https://commits.webkit.org/278599@main
  • Loading branch information
psaavedra committed May 10, 2024
1 parent 8648d79 commit a5f69d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
15 changes: 13 additions & 2 deletions Source/WebKit/UIProcess/linux/MemoryPressureMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ static const unsigned maxCgroupPath = 4096; // PATH_MAX = 4096 from (Linux) incl
#define MEMINFO_TOKEN_BUFFER_SIZE 50
#define STRINGIFY_EXPANDED(val) #val
#define STRINGIFY(val) STRINGIFY_EXPANDED(val)
#define VALUE_BUFFER_SIZE 128
#define ZONEINFO_TOKEN_BUFFER_SIZE 128

// The lowWatermark is the sum of the low watermarks across all zones as the
Expand Down Expand Up @@ -438,8 +439,18 @@ size_t CGroupMemoryController::getCgroupFileValue(FILE *file)
if (!file || fseek(file, 0, SEEK_SET))
return notSet;

size_t value;
return (fscanf(file, "%zu", &value) == 1) ? value : notSet;
char rawValue[VALUE_BUFFER_SIZE + 1];
if (fscanf(file, "%" STRINGIFY(VALUE_BUFFER_SIZE) "[^\n]", rawValue) < 1)
return notSet;

errno = 0;
char* endptr;
long value = strtol(rawValue, &endptr, 10);

if (errno == ERANGE || value < 0 || *endptr != '\0')
return notSet;

return static_cast<size_t>(value);
}

size_t CGroupMemoryController::getMemoryTotalWithCgroup()
Expand Down
7 changes: 0 additions & 7 deletions Tools/TestWebKitAPI/glib/TestExpectations.json
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,6 @@
}

},
"TestNetworkProcessMemoryPressure": {
"subtests": {
"/webkit/WebKitWebsiteData/memory-pressure": {
"expected": {"gtk": {"status": ["TIMEOUT"], "bug": "webkit.org/b/263016"}}
}
}
},
"TestWebKitNetworkSession": {
"subtests": {
"/webkit/WebKitNetworkSession/proxy": {
Expand Down

0 comments on commit a5f69d0

Please sign in to comment.