diff --git a/src/detection/cpuusage/cpuusage_linux.c b/src/detection/cpuusage/cpuusage_linux.c index cb6101a97..118353e2c 100644 --- a/src/detection/cpuusage/cpuusage_linux.c +++ b/src/detection/cpuusage/cpuusage_linux.c @@ -41,7 +41,7 @@ const char* ffGetCpuUsageInfo(FFlist* cpuTimes) }; } else - break; // because we read the whole /proc/stat, we can safely quit when the line does not start with "cpuN" + break; start = token + 1; } diff --git a/src/detection/memory/memory_linux.c b/src/detection/memory/memory_linux.c index d4ebf4de9..3da3e7930 100644 --- a/src/detection/memory/memory_linux.c +++ b/src/detection/memory/memory_linux.c @@ -21,22 +21,22 @@ const char* ffDetectMemory(FFMemoryResult* ram) char *token = NULL; if((token = strstr(buf, "MemTotal:")) != NULL) - sscanf(token, "MemTotal: %" PRIu64, &memTotal); + memTotal = strtoul(token + strlen("MemTotal:"), NULL, 10); if((token = strstr(buf, "MemFree:")) != NULL) - sscanf(token, "MemFree: %" PRIu64, &memFree); + memFree = strtoul(token + strlen("MemFree:"), NULL, 10); if((token = strstr(buf, "Buffers:")) != NULL) - sscanf(token, "Buffers: %" PRIu64, &buffers); + buffers = strtoul(token + strlen("Buffers:"), NULL, 10); if((token = strstr(buf, "Cached:")) != NULL) - sscanf(token, "Cached: %" PRIu64, &cached); + cached = strtoul(token + strlen("Cached:"), NULL, 10); if((token = strstr(buf, "Shmem:")) != NULL) - sscanf(token, "Shmem: %" PRIu64, &shmem); + shmem = strtoul(token + strlen("Shmem:"), NULL, 10); if((token = strstr(buf, "SReclaimable:")) != NULL) - sscanf(token, "SReclaimable: %" PRIu64, &sReclaimable); + sReclaimable = strtoul(token + strlen("SReclaimable:"), NULL, 10); ram->bytesTotal = memTotal * 1024lu; ram->bytesUsed = (memTotal + shmem - memFree - buffers - cached - sReclaimable) * 1024lu; diff --git a/src/detection/swap/swap_linux.c b/src/detection/swap/swap_linux.c index 02183d6e6..77d95d589 100644 --- a/src/detection/swap/swap_linux.c +++ b/src/detection/swap/swap_linux.c @@ -18,10 +18,10 @@ const char* ffDetectSwap(FFSwapResult* swap) char *token = NULL; if ((token = strstr(buf, "SwapTotal:")) != NULL) - sscanf(token, "SwapTotal: %" PRIu64, &swapTotal); + swapTotal = strtoul(token + strlen("SwapTotal:"), NULL, 10); if ((token = strstr(buf, "SwapFree:")) != NULL) - sscanf(token, "SwapFree: %" PRIu64, &swapFree); + swapFree = strtoul(token + strlen("SwapFree:"), NULL, 10); swap->bytesTotal = swapTotal * 1024lu; swap->bytesUsed = (swapTotal - swapFree) * 1024lu; diff --git a/src/detection/uptime/uptime_linux.c b/src/detection/uptime/uptime_linux.c index f4ea790a1..79bb5580c 100644 --- a/src/detection/uptime/uptime_linux.c +++ b/src/detection/uptime/uptime_linux.c @@ -13,11 +13,12 @@ const char* ffDetectUptime(FFUptimeResult* result) return "ffReadFileData(\"/proc/uptime\", sizeof(buf) - 1, buf) failed"; buf[nRead] = '\0'; - double sec; - if(sscanf(buf, "%lf", &sec) > 0) + char *err = NULL; + double sec = strtod(buf, &err); + if(err != buf) result->uptime = (uint64_t) (sec * 1000); else - return "sscanf(buf.chars, \"%lf\", &sec) failed"; + return "strtod(buf, &err) failed"; result->bootTime = ffTimeGetNow() + result->uptime;