diff options
author | Binbin <binloveplay1314@qq.com> | 2022-06-12 03:27:44 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-11 22:27:44 +0300 |
commit | 62ac1ab007b9ba25588671fdefd0025028030504 (patch) | |
tree | 46cc4fa600b0639006551140ad75077681270465 /src/syscheck.c | |
parent | 032619b82b6c9b882dc99c22bdab020a865489fa (diff) | |
download | redis-62ac1ab007b9ba25588671fdefd0025028030504.tar.gz |
Fix crash when overcommit_memory is inaccessible (#10848)
When `/proc/sys/vm/overcommit_memory` is inaccessible, fp is NULL.
`checkOvercommit` will return -1 without setting err_msg, and then
the err_msg is used to print the log, crash the server.
Set the err_msg variables to Null when declaring it, seems safer.
And the overcommit_memory error log will print two "WARNING",
like `WARNING WARNING overcommit_memory is set to 0!`, this PR
also removes the second WARNING in `checkOvercommit`.
Reported in #10846. Fixes #10846. Introduced in #10636 (7.0.1)
Diffstat (limited to 'src/syscheck.c')
-rw-r--r-- | src/syscheck.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/syscheck.c b/src/syscheck.c index 9f338b118..58dc78f1b 100644 --- a/src/syscheck.c +++ b/src/syscheck.c @@ -143,7 +143,7 @@ int checkOvercommit(sds *error_msg) { FILE *fp = fopen("/proc/sys/vm/overcommit_memory","r"); char buf[64]; - if (!fp) return -1; + if (!fp) return 0; if (fgets(buf,64,fp) == NULL) { fclose(fp); return 0; @@ -152,7 +152,7 @@ int checkOvercommit(sds *error_msg) { if (atoi(buf)) { *error_msg = sdsnew( - "WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. " + "overcommit_memory is set to 0! Background save may fail under low memory condition. " "To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the " "command 'sysctl vm.overcommit_memory=1' for this to take effect."); return -1; @@ -351,7 +351,7 @@ check checks[] = { int syscheck(void) { check *cur_check = checks; int ret = 1; - sds err_msg; + sds err_msg = NULL; while (cur_check->check_fn) { int res = cur_check->check_fn(&err_msg); printf("[%s]...", cur_check->name); |