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

Anonymous Coward asteriskteam at digium.com
Mon Oct 31 09:55:08 CDT 2016


Anonymous Coward #1000019 has submitted this change and it was merged. ( 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(-)

Approvals:
  Mark Michelson: Looks good to me, approved
  Anonymous Coward #1000019: Verified
  Badalian Vyacheslav: Looks good to me, but someone else must approve



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: merged
Gerrit-Change-Id: I988a476bb5fcfcbd3f6d6c6b3e7769e4f9629b71
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 14
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Badalian Vyacheslav <v.badalyan at open-bs.ru>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>



More information about the asterisk-code-review mailing list