Handle error from fopen_path in finish_recovery

The fopen_path will fail here e.g. if /cache is corrupt and could
not be mounted. Not properly handling an error code from
fopen_path() results in a boot loop into recovery as fwrite() on
a NULL FILE object will crash the recovery app.

Change-Id: I1ccff5a8cb620a32f32adfe97a3fae8e5e908f39
This commit is contained in:
Johan Harvyl
2016-08-05 15:42:59 +02:00
committed by Johan Redestig
parent 61240f88ea
commit 8569142147
+6 -4
View File
@@ -504,10 +504,12 @@ finish_recovery() {
if (has_cache) {
LOGI("Saving locale \"%s\"\n", locale);
FILE* fp = fopen_path(LOCALE_FILE, "w");
fwrite(locale, 1, len, fp);
fflush(fp);
fsync(fileno(fp));
check_and_fclose(fp, LOCALE_FILE);
if (fp != NULL) {
fwrite(locale, 1, len, fp);
fflush(fp);
fsync(fileno(fp));
check_and_fclose(fp, LOCALE_FILE);
}
}
}