From 730646199b8de879621e97d3196d49f8b71afdda Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Tue, 26 Apr 2016 17:14:32 -0700 Subject: updater: Don't zero out CommandParameters with memset(3). [1] switched a few things to android::base::unique_fd including CommandParameters.fd. However, we were using memset(3) to zero out the struct, which effectively assigned unique_fd(0) to fd. When it called fd.reset(), file descriptor 0 was unintentionally closed. When FD 0 was later reassigned via open(2), it led to lseek(2) errors: "Bad file descriptor". This CL switches to using braced-init (i.e. '= {}') instead, so that the default constructor unique_fd(-1) would be called. [1]: commit bcabd0929316fdd022ea102cc86396547ad9f070 Bug: 28391985 Change-Id: If1f99932b15552714c399e65c8b80550344b758a --- updater/blockimg.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/updater/blockimg.cpp b/updater/blockimg.cpp index 908e11631..2e30c5bf3 100644 --- a/updater/blockimg.cpp +++ b/updater/blockimg.cpp @@ -1318,8 +1318,7 @@ static unsigned int HashString(const char *s) { static Value* PerformBlockImageUpdate(const char* name, State* state, int /* argc */, Expr* argv[], const Command* commands, size_t cmdcount, bool dryrun) { - CommandParameters params; - memset(¶ms, 0, sizeof(params)); + CommandParameters params = {}; params.canwrite = !dryrun; fprintf(stderr, "performing %s\n", dryrun ? "verification" : "update"); -- cgit v1.2.3