From 241bcf05e0e394bbf2681f359f52646dd6c707f6 Mon Sep 17 00:00:00 2001 From: Narayan Kamath Date: Mon, 11 May 2015 16:59:46 +0100 Subject: [PATCH] Fix file descriptor leak when opening invalid archives. Also add -Wunreachable-code to the set of compiler flags, otherwise noreturn becomes considerably less useful. bug: https://code.google.com/p/android/issues/detail?id=171099 Change-Id: I9a95d45633c731c7046d4e4a39844d9cebfd1718 --- fastboot/Android.mk | 2 +- fastboot/fastboot.cpp | 3 +++ fastboot/fastboot.h | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/fastboot/Android.mk b/fastboot/Android.mk index 7b2975b7f..064882636 100644 --- a/fastboot/Android.mk +++ b/fastboot/Android.mk @@ -23,7 +23,7 @@ LOCAL_SRC_FILES := protocol.c engine.c bootimg_utils.cpp fastboot.cpp util.c fs. LOCAL_MODULE := fastboot LOCAL_MODULE_TAGS := debug LOCAL_CONLYFLAGS += -std=gnu99 -LOCAL_CFLAGS += -Wall -Wextra -Werror +LOCAL_CFLAGS += -Wall -Wextra -Werror -Wunreachable-code ifeq ($(HOST_OS),linux) LOCAL_SRC_FILES += usb_linux.c util_linux.c diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp index e35cc70ec..c599fc290 100644 --- a/fastboot/fastboot.cpp +++ b/fastboot/fastboot.cpp @@ -701,12 +701,14 @@ void do_update(usb_handle *usb, const char *filename, int erase_first) ZipArchiveHandle zip; int error = OpenArchive(filename, &zip); if (error != 0) { + CloseArchive(zip); die("failed to open zip file '%s': %s", filename, ErrorCodeString(error)); } unsigned sz; void* data = unzip_file(zip, "android-info.txt", &sz); if (data == 0) { + CloseArchive(zip); die("update package '%s' has no android-info.txt", filename); } @@ -717,6 +719,7 @@ void do_update(usb_handle *usb, const char *filename, int erase_first) if (fd < 0) { if (images[i].is_optional) continue; + CloseArchive(zip); die("update package missing %s", images[i].img_name); } fastboot_buffer buf; diff --git a/fastboot/fastboot.h b/fastboot/fastboot.h index 1786e4913..481c50117 100644 --- a/fastboot/fastboot.h +++ b/fastboot/fastboot.h @@ -69,7 +69,7 @@ int fb_queue_is_empty(void); /* util stuff */ double now(); char *mkmsg(const char *fmt, ...); -void die(const char *fmt, ...); +__attribute__((__noreturn__)) void die(const char *fmt, ...); void get_my_path(char *path);