aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/temperature/tempget.c
diff options
context:
space:
mode:
authorStefan Schmidt <stefan@datenfreihafen.org>2012-05-26 22:50:06 +0000
committerStefan Schmidt <stefan@datenfreihafen.org>2012-05-26 22:50:06 +0000
commit1ced507bf4ba384f91be4f28b3967f7a5a305952 (patch)
tree1c10a1387a24986775aae748640fa933fd974b66 /src/modules/temperature/tempget.c
parente: tiling: fix use of unused var (diff)
downloadenlightenment-1ced507bf4ba384f91be4f28b3967f7a5a305952.tar.gz
tempget: Check return values from fgets()
Without this checking we might operate on wrong data read in. Better check. SVN revision: 71445
Diffstat (limited to 'src/modules/temperature/tempget.c')
-rw-r--r--src/modules/temperature/tempget.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/modules/temperature/tempget.c b/src/modules/temperature/tempget.c
index 28d3be240..f1746f2c1 100644
--- a/src/modules/temperature/tempget.c
+++ b/src/modules/temperature/tempget.c
@@ -401,7 +401,8 @@ check(void)
{
char dummy[4096];
- fgets(buf, sizeof(buf), f);
+ if (fgets(buf, sizeof(buf), f) == NULL) goto error;
+
buf[sizeof(buf) - 1] = 0;
if (sscanf(buf, "%s %s %i", dummy, dummy, &temp) == 3)
ret = 1;
@@ -417,7 +418,8 @@ check(void)
f = fopen(sensor_path, "rb");
if (f)
{
- fgets(buf, sizeof(buf), f);
+ if (fgets(buf, sizeof(buf), f) == NULL) goto error;
+
fclose(f);
buf[sizeof(buf) - 1] = 0;
if (sscanf(buf, "%i", &temp) == 1)
@@ -434,7 +436,8 @@ check(void)
f = fopen(sensor_path, "r");
if (f)
{
- fgets(buf, sizeof(buf), f);
+ if (fgets(buf, sizeof(buf), f) == NULL) goto error;
+
buf[sizeof(buf) - 1] = 0;
/* actually read the temp */
@@ -453,7 +456,8 @@ check(void)
f = fopen(sensor_path, "r");
if (f)
{
- fgets(buf, sizeof(buf), f);
+ if (fgets(buf, sizeof(buf), f) == NULL) goto error;
+
buf[sizeof(buf) - 1] = 0;
/* actually read the temp */
@@ -474,7 +478,8 @@ check(void)
{
char *p, *q;
- fgets(buf, sizeof(buf), f);
+ if (fgets(buf, sizeof(buf), f) == NULL) goto error;
+
buf[sizeof(buf) - 1] = 0;
fclose(f);
p = strchr(buf, ':');
@@ -497,7 +502,8 @@ check(void)
f = fopen(sensor_path, "r");
if (f)
{
- fgets(buf, sizeof(buf), f);
+ if (fgets(buf, sizeof(buf), f) == NULL) goto error;
+
buf[sizeof(buf) - 1] = 0;
fclose(f);
temp = atoi(buf);