[Asterisk-code-review] vector: Prevent NULL argument to memcpy. (asterisk[14])

Corey Farrell asteriskteam at digium.com
Sun Oct 30 13:46:05 CDT 2016


Corey Farrell has uploaded a new change for review. ( https://gerrit.asterisk.org/4235 )

Change subject: vector: Prevent NULL argument to memcpy.
......................................................................

vector: Prevent NULL argument to memcpy.

Headers declare that memcpy does not accept NULL argument for the first
two parameters.  Add a conditional block to prevent memcpy and ast_free
from running on vectors with NULL element array.

ASTERISK-26526 #close

Change-Id: I988a476bb5fcfcbd3f6d6c6b3e7769e4f9629b71
---
M include/asterisk/vector.h
1 file changed, 5 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/35/4235/1

diff --git a/include/asterisk/vector.h b/include/asterisk/vector.h
index c74f0a8..83732e7 100644
--- a/include/asterisk/vector.h
+++ b/include/asterisk/vector.h
@@ -172,9 +172,11 @@
 			typeof((vec)->elems) new_elems = ast_calloc(1,		\
 				new_max * sizeof(*new_elems));					\
 			if (new_elems) {									\
-				memcpy(new_elems, (vec)->elems,					\
-					(vec)->current * sizeof(*new_elems)); 		\
-				ast_free((vec)->elems);							\
+				if ((vec)->elems) {								\
+					memcpy(new_elems, (vec)->elems,				\
+						(vec)->current * sizeof(*new_elems)); 	\
+					ast_free((vec)->elems);						\
+				}												\
 				(vec)->elems = new_elems;						\
 				(vec)->max = new_max;							\
 			} else {											\

-- 
To view, visit https://gerrit.asterisk.org/4235
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I988a476bb5fcfcbd3f6d6c6b3e7769e4f9629b71
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 14
Gerrit-Owner: Corey Farrell <git at cfware.com>



More information about the asterisk-code-review mailing list