Sophie

Sophie

distrib > Mageia > 6 > armv7hl > media > core-updates-src > by-pkgid > e292cda8ad33284786d7f1384ee2e82d > files > 9

ming-0.4.5-14.1.mga6.src.rpm

From 847b9897940521a325f491965737b7291603caf1 Mon Sep 17 00:00:00 2001
From: Hugo Lefeuvre <hle@debian.org>
Date: Fri, 13 Oct 2017 15:35:00 +0200
Subject: [PATCH 18/29] Avoid NULL pointer dereference in util/read.c.

Make sure that buf isn't dereferenced if malloc failed. In this
case, report error and abort.
---
 util/read.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/util/read.c b/util/read.c
index 80399ca0..9d5bc262 100644
--- a/util/read.c
+++ b/util/read.c
@@ -239,6 +239,11 @@ char *readBytes(FILE *f, unsigned long size)
 
   buf = (char *)malloc(sizeof(char)*size);
 
+  if (buf == NULL) {
+    fprintf(stderr, "readBytes: Failed to allocate %lu bytes", sizeof(char) * size);
+    exit(-1);
+  }
+
   for(i=0;i<size;i++)
   {
     buf[i]=(char)readUInt8(f);
-- 
2.14.3