From cd3c53b848de88b06c2e81af2e03b4aae287d626 Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: May 01 2015 22:55:04 +0000 Subject: Fix a read-after-close in a self-test If we hit a problem reading a sample file, don't try to read() it again after we close the descriptor. Found by static analysis. --- diff --git a/tests/tools/json.c b/tests/tools/json.c index ca0136f..e42b1da 100644 --- a/tests/tools/json.c +++ b/tests/tools/json.c @@ -84,11 +84,15 @@ main(int argc, const char **argv) n = read(fd, e + r, st.st_size - r); if (n <= 0) { ret = errno; - close(fd); - continue; + break; } r += n; } + if (r < st.st_size) { + fprintf(stderr, "read(): %s\n", strerror(errno)); + close(fd); + break; + } close(fd); i = cm_json_decode(parent, e, st.st_size, &j, &left); if (i != 0) {