forked from enlightenment/enlightenment
tempget: Check return values from fgets()
Without this checking we might operate on wrong data read in. Better check. SVN revision: 71445
This commit is contained in:
parent
9432f762d0
commit
1ced507bf4
|
@ -401,7 +401,8 @@ check(void)
|
||||||
{
|
{
|
||||||
char dummy[4096];
|
char dummy[4096];
|
||||||
|
|
||||||
fgets(buf, sizeof(buf), f);
|
if (fgets(buf, sizeof(buf), f) == NULL) goto error;
|
||||||
|
|
||||||
buf[sizeof(buf) - 1] = 0;
|
buf[sizeof(buf) - 1] = 0;
|
||||||
if (sscanf(buf, "%s %s %i", dummy, dummy, &temp) == 3)
|
if (sscanf(buf, "%s %s %i", dummy, dummy, &temp) == 3)
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
@ -417,7 +418,8 @@ check(void)
|
||||||
f = fopen(sensor_path, "rb");
|
f = fopen(sensor_path, "rb");
|
||||||
if (f)
|
if (f)
|
||||||
{
|
{
|
||||||
fgets(buf, sizeof(buf), f);
|
if (fgets(buf, sizeof(buf), f) == NULL) goto error;
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
buf[sizeof(buf) - 1] = 0;
|
buf[sizeof(buf) - 1] = 0;
|
||||||
if (sscanf(buf, "%i", &temp) == 1)
|
if (sscanf(buf, "%i", &temp) == 1)
|
||||||
|
@ -434,7 +436,8 @@ check(void)
|
||||||
f = fopen(sensor_path, "r");
|
f = fopen(sensor_path, "r");
|
||||||
if (f)
|
if (f)
|
||||||
{
|
{
|
||||||
fgets(buf, sizeof(buf), f);
|
if (fgets(buf, sizeof(buf), f) == NULL) goto error;
|
||||||
|
|
||||||
buf[sizeof(buf) - 1] = 0;
|
buf[sizeof(buf) - 1] = 0;
|
||||||
|
|
||||||
/* actually read the temp */
|
/* actually read the temp */
|
||||||
|
@ -453,7 +456,8 @@ check(void)
|
||||||
f = fopen(sensor_path, "r");
|
f = fopen(sensor_path, "r");
|
||||||
if (f)
|
if (f)
|
||||||
{
|
{
|
||||||
fgets(buf, sizeof(buf), f);
|
if (fgets(buf, sizeof(buf), f) == NULL) goto error;
|
||||||
|
|
||||||
buf[sizeof(buf) - 1] = 0;
|
buf[sizeof(buf) - 1] = 0;
|
||||||
|
|
||||||
/* actually read the temp */
|
/* actually read the temp */
|
||||||
|
@ -474,7 +478,8 @@ check(void)
|
||||||
{
|
{
|
||||||
char *p, *q;
|
char *p, *q;
|
||||||
|
|
||||||
fgets(buf, sizeof(buf), f);
|
if (fgets(buf, sizeof(buf), f) == NULL) goto error;
|
||||||
|
|
||||||
buf[sizeof(buf) - 1] = 0;
|
buf[sizeof(buf) - 1] = 0;
|
||||||
fclose(f);
|
fclose(f);
|
||||||
p = strchr(buf, ':');
|
p = strchr(buf, ':');
|
||||||
|
@ -497,7 +502,8 @@ check(void)
|
||||||
f = fopen(sensor_path, "r");
|
f = fopen(sensor_path, "r");
|
||||||
if (f)
|
if (f)
|
||||||
{
|
{
|
||||||
fgets(buf, sizeof(buf), f);
|
if (fgets(buf, sizeof(buf), f) == NULL) goto error;
|
||||||
|
|
||||||
buf[sizeof(buf) - 1] = 0;
|
buf[sizeof(buf) - 1] = 0;
|
||||||
fclose(f);
|
fclose(f);
|
||||||
temp = atoi(buf);
|
temp = atoi(buf);
|
||||||
|
|
Loading…
Reference in New Issue