diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2017-07-27 16:07:50 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2017-07-27 16:07:50 -0300 |
commit | 09e241fb1271021e3615512debd3136891547562 (patch) | |
tree | 8245b6084607a34185cfa7d3d45f5228937020f1 /linux/Battery.c | |
parent | 3975e9ce5cba0e3972b2ddab28c198e000441501 (diff) |
Security review: check results of snprintf.
Calls marked with xSnprintf shouldn't fail.
Abort program cleanly if any of them does.
Diffstat (limited to 'linux/Battery.c')
-rw-r--r-- | linux/Battery.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/linux/Battery.c b/linux/Battery.c index e575b307..761b8ad7 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -56,7 +56,7 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short unsigned long int total = 0; for (unsigned int i = 0; i < nBatteries; i++) { char infoPath[30]; - snprintf(infoPath, sizeof infoPath, "%s%s/%s", batteryPath, batteries[i], fileName); + xSnprintf(infoPath, sizeof infoPath, "%s%s/%s", batteryPath, batteries[i], fileName); FILE* file = fopen(infoPath, "r"); if (!file) { @@ -106,7 +106,7 @@ static ACPresence procAcpiCheck() { continue; char statePath[50]; - snprintf((char *) statePath, sizeof statePath, "%s/%s/state", power_supplyPath, entryName); + xSnprintf((char *) statePath, sizeof statePath, "%s/%s/state", power_supplyPath, entryName); FILE* file = fopen(statePath, "r"); if (!file) { @@ -196,7 +196,7 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { if (entryName[0] == 'B' && entryName[1] == 'A' && entryName[2] == 'T') { - snprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/uevent", entryName); + xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/uevent", entryName); int fd = open(filePath, O_RDONLY); if (fd == -1) { closedir(dir); @@ -249,7 +249,7 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { continue; } - snprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/online", entryName); + xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/online", entryName); int fd = open(filePath, O_RDONLY); if (fd == -1) { closedir(dir); |