[PATCH libICE 12/13] add check for malloc
walter harms
wharms at bfs.de
Wed Oct 18 16:07:14 UTC 2017
fix a potential null pointer deference error and
IceAllocScratch() do not report size when allocation failes
Signed-off-by: Walter Harms <wharms at bfs.de>
---
src/misc.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/src/misc.c b/src/misc.c
index 87d6335..fdc671d 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -57,7 +57,10 @@ IceAllocScratch (
free (iceConn->scratch);
iceConn->scratch = malloc (size);
- iceConn->scratch_size = size;
+ if ( !iceConn->scratch )
+ iceConn->scratch_size = 0;
+ else
+ iceConn->scratch_size = size;
}
return (iceConn->scratch);
@@ -415,12 +418,14 @@ _IceAddOpcodeMapping (
)
{
if (hisOpcode <= 0 || hisOpcode > 255)
- {
return;
- }
- else if (iceConn->process_msg_info == NULL)
+
+ if (iceConn->process_msg_info == NULL)
{
iceConn->process_msg_info = malloc (sizeof (_IceProcessMsgInfo));
+ if ( ! iceConn->process_msg_info )
+ return;
+
iceConn->his_min_opcode = iceConn->his_max_opcode = hisOpcode;
}
else if (hisOpcode < iceConn->his_min_opcode)
@@ -433,6 +438,9 @@ _IceAddOpcodeMapping (
iceConn->process_msg_info = malloc (
newsize * sizeof (_IceProcessMsgInfo));
+ if ( ! iceConn->process_msg_info )
+ return;
+
memcpy (&iceConn->process_msg_info[
iceConn->his_min_opcode - hisOpcode], oldVec,
oldsize * sizeof (_IceProcessMsgInfo));
@@ -460,6 +468,9 @@ _IceAddOpcodeMapping (
iceConn->process_msg_info = malloc (
newsize * sizeof (_IceProcessMsgInfo));
+ if ( ! iceConn->process_msg_info )
+ return;
+
memcpy (iceConn->process_msg_info, oldVec,
oldsize * sizeof (_IceProcessMsgInfo));
--
2.1.4
More information about the xorg-devel
mailing list