From 158eee16eca95204e9e1580efd15eee759bc3c8c Mon Sep 17 00:00:00 2001 From: Leandro Dorileo Date: Thu, 15 Jan 2015 11:22:05 -0200 Subject: [PATCH] png: fix non null-terminated string issue Pointed out by coverity tests: https://bugs.tizen.org/jira/browse/TC-2097 --- src/plugins/png/png.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/plugins/png/png.c b/src/plugins/png/png.c index fdcd11a..416cbec 100644 --- a/src/plugins/png/png.c +++ b/src/plugins/png/png.c @@ -55,15 +55,16 @@ _chunk_to_uint(unsigned char *buf) static int _png_data_get(int fd, struct lms_image_info *info) { - unsigned char buf[16], *p; + unsigned char buf[17], *p; const unsigned char sig[8] = {0x89, 0x50, 0x4e, 0x47, 0xd, 0xa, 0x1a, 0xa}; const unsigned char ihdr[4] = {'I', 'H', 'D', 'R'}; unsigned int length; - if (read(fd, buf, sizeof(buf)) != sizeof(buf)) { + if (read(fd, buf, sizeof(buf) - 1) != sizeof(buf) - 1) { perror("read"); return -1; } + buf[sizeof(buf) - 1] = '\0'; if (memcmp(buf, sig, sizeof(sig)) != 0) { fprintf(stderr, "ERROR: invalid PNG signature.\n"); -- 2.7.4