From 8569142147f8ba7ec6a3431f96aa00d66b45db61 Mon Sep 17 00:00:00 2001 From: Johan Harvyl Date: Fri, 5 Aug 2016 15:42:59 +0200 Subject: 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 --- recovery.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/recovery.cpp b/recovery.cpp index 28dd212ba..7bdf961e7 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -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); + } } } -- cgit v1.2.3