summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvivek <vivek.ellur@samsung.com>2014-05-06 15:54:49 +0530
committerKristian Høgsberg <krh@bitplanet.net>2014-05-06 15:21:27 -0700
commit6f0907b6d8034a7547c3cf18876810dac68dc3fe (patch)
tree21c0371ec0d958df79deef7b2fd506fed8e854f6
parent47792415165888676078eb3eb98ac4b97ba34140 (diff)
wcap: Check for mmap and malloc return value in wcap decode module
Checking for return value in main.c for wcap_decoder_create function and mmap, malloc return value in wcap_decoder_create function to avoid crashes Signed-off-by: vivek <vivek.ellur@samsung.com>
-rw-r--r--wcap/main.c4
-rw-r--r--wcap/wcap-decode.c9
2 files changed, 13 insertions, 0 deletions
diff --git a/wcap/main.c b/wcap/main.c
index 29bb9c30..16d37f00 100644
--- a/wcap/main.c
+++ b/wcap/main.c
@@ -251,6 +251,10 @@ int main(int argc, char *argv[])
}
decoder = wcap_decoder_create(argv[1]);
+ if (decoder == NULL) {
+ fprintf(stderr, "Creating wcap decoder failed\n");
+ exit(EXIT_FAILURE);
+ }
if (yuv4mpeg2 && isatty(1)) {
fprintf(stderr, "Not dumping yuv4mpeg2 data to terminal. Pipe output to a file or a process.\n");
diff --git a/wcap/wcap-decode.c b/wcap/wcap-decode.c
index 87d93379..76ecc2f4 100644
--- a/wcap/wcap-decode.c
+++ b/wcap/wcap-decode.c
@@ -126,6 +126,11 @@ wcap_decoder_create(const char *filename)
decoder->size = buf.st_size;
decoder->map = mmap(NULL, decoder->size,
PROT_READ, MAP_PRIVATE, decoder->fd, 0);
+ if (decoder->map == MAP_FAILED) {
+ fprintf(stderr, "mmap failed\n");
+ free(decoder);
+ return NULL;
+ }
header = decoder->map;
decoder->format = header->format;
@@ -137,6 +142,10 @@ wcap_decoder_create(const char *filename)
frame_size = header->width * header->height * 4;
decoder->frame = malloc(frame_size);
+ if (decoder->frame == NULL) {
+ free(decoder);
+ return NULL;
+ }
memset(decoder->frame, 0, frame_size);
return decoder;