Calling function 'fopen' after check function like 'access' which perform check on path can cause a time-of-check, time-of-use race condition.
For resolving this, remove 'access' and just print error message of fopen() fail with errno.
Change-Id: I46b4639815b52fef1548209d703cf40d9ee6920b
#define __BASE_GUI_DIRECT_H__
#include "gui_general.h"
+#include <errno.h>
extern int fota_gr_direct_init(void);
extern void fota_gr_direct_deinit(void);
FILE *fp;
- if (access("/tmp/upgrade/ro_progress", R_OK) == 0) {
- fp = fopen("/tmp/upgrade/ro_progress", "r");
- if (fp) {
- if (fscanf(fp, "%d", &percent) == EOF)
- LOG("Error occurs at reading ro_progress");
- if (percent == -1 && *s_saved_percent > 0) {
- LOG("END ro update\n");
- fclose(fp);
- return -1;
- }
- if (percent < 0)
- percent = 0;
- if (percent > 0xffffff)
- percent = 0xffffff;
+ fp = fopen("/tmp/upgrade/ro_progress", "r");
+ if (fp) {
+ if (fscanf(fp, "%d", &percent) == EOF)
+ LOG("Error occurs at reading ro_progress");
+ if (percent == -1 && *s_saved_percent > 0) {
+ LOG("END ro update\n");
fclose(fp);
- } else
- percent = *s_percent_to_draw;
+ return -1;
+ }
+ if (percent < 0)
+ percent = 0;
+ if (percent > 0xffffff)
+ percent = 0xffffff;
+ fclose(fp);
+ } else {
+ LOG("fopen fail, error msg : %s\n", strerror(errno));
+ percent = *s_percent_to_draw;
}
if (*s_percent_to_draw < percent)
FILE *fp;
- if (access("/tmp/upgrade/ro_progress", R_OK) == 0) {
- fp = fopen("/tmp/upgrade/ro_progress", "r");
- if (fp) {
- if (fscanf(fp, "%d", &percent) == EOF)
- LOG("Error occurs at reading ro_progress");
- if (percent == -1 && s_saved_percent > 0) {
- LOG("END ro update\n");
- fclose(fp);
- return -1;
- }
- if (percent < 0)
- percent = 0;
- if (percent > 0xffffff)
- percent = 0xffffff;
+ fp = fopen("/tmp/upgrade/ro_progress", "r");
+ if (fp) {
+ if (fscanf(fp, "%d", &percent) == EOF)
+ LOG("Error occurs at reading ro_progress");
+ if (percent == -1 && s_saved_percent > 0) {
+ LOG("END ro update\n");
fclose(fp);
- } else
- percent = s_percent_to_draw;
+ return -1;
+ }
+ if (percent < 0)
+ percent = 0;
+ if (percent > 0xffffff)
+ percent = 0xffffff;
+ fclose(fp);
+ } else {
+ LOG("fopen fail, error msg : %s\n", strerror(errno));
+ percent = s_percent_to_draw;
}
if (s_percent_to_draw < percent)
FILE *fp;
- if (access("/tmp/recovery_progress", R_OK) == 0) {
- fp = fopen("/tmp/recovery_progress", "r");
- if (fp) {
- if (fscanf(fp, "%d", &percent) == EOF)
- LOG("Error occurs at reading progress");
- if (percent < 0)
- percent = 0;
- if (percent > 0xffffff)
- percent = 0xffffff;
- fclose(fp);
- } else
- percent = *s_percent_to_draw;
+ fp = fopen("/tmp/recovery_progress", "r");
+ if (fp) {
+ if (fscanf(fp, "%d", &percent) == EOF)
+ LOG("Error occurs at reading progress");
+ if (percent < 0)
+ percent = 0;
+ if (percent > 0xffffff)
+ percent = 0xffffff;
+ fclose(fp);
+ } else {
+ LOG("fopen fail, error msg : %s\n", strerror(errno));
+ percent = *s_percent_to_draw;
}
*s_percent_to_draw = percent;
//static int b_text_drawn = 0;
FILE *fp;
- if (total <= 0 && access("/tmp/upgrade/total", R_OK) == 0) {
+ if (total <= 0) {
fp = fopen("/tmp/upgrade/total", "r");
if (fp) {
if (fscanf(fp, "%d", &total) == EOF)
if (total > 0xffffff)
total = 0xffffff;
fclose(fp);
- } else
+ } else {
+ LOG("fopen fail, error msg : %s\n", strerror(errno));
total = 0;
+ }
}
- if (access("/tmp/upgrade/progress", R_OK) == 0) {
- fp = fopen("/tmp/upgrade/progress", "r");
- if (fp) {
- if (fscanf(fp, "%d", &progress) == EOF)
- LOG("Error occurs at reading progress");
- if (progress < 0)
- progress = 0;
- if (progress > total)
- progress = total;
- fclose(fp);
- } else
+ fp = fopen("/tmp/upgrade/progress", "r");
+ if (fp) {
+ if (fscanf(fp, "%d", &progress) == EOF)
+ LOG("Error occurs at reading progress");
+ if (progress < 0)
progress = 0;
+ if (progress > total)
+ progress = total;
+ fclose(fp);
+ } else {
+ LOG("fopen fail, error msg : %s\n", strerror(errno));
+ progress = 0;
}
if (total == 0)
#include "rw-update_new_fb.h"
#include <sys/ioctl.h>
#include <unistd.h>
+#include <errno.h>
#ifdef CAIRO_LIB
#include "rw-update_new_cairo.h"
static int b_text_drawn = 0;
FILE *fp;
- if (total <= 0 && access("/tmp/upgrade/total", R_OK) == 0) {
+ if (total <= 0) {
fp = fopen("/tmp/upgrade/total", "r");
if (fp) {
if (fscanf(fp, "%d", &total) == EOF)
if (total > 0xffffff)
total = 0xffffff;
fclose(fp);
- } else
+ } else {
+ _DEBUG_LOG("fopen fail, error msg : %s\n", strerror(errno));
total = 0;
+ }
}
- if (access("/tmp/upgrade/progress", R_OK) == 0) {
- fp = fopen("/tmp/upgrade/progress", "r");
- if (fp) {
- if (fscanf(fp, "%d", &progress) == EOF)
- _DEBUG_LOG("Error occurs at reading progress");
- if (progress < 0)
- progress = 0;
- if (progress > total)
- progress = total;
- fclose(fp);
- } else
+ fp = fopen("/tmp/upgrade/progress", "r");
+ if (fp) {
+ if (fscanf(fp, "%d", &progress) == EOF)
+ _DEBUG_LOG("Error occurs at reading progress");
+ if (progress < 0)
progress = 0;
+ if (progress > total)
+ progress = total;
+ fclose(fp);
+ } else {
+ _DEBUG_LOG("fopen fail, error msg : %s\n", strerror(errno));
+ progress = 0;
}
_DEBUG_LOG("progress: %d/%d", progress, total);