summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2014-05-17 00:21:25 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2014-05-17 00:21:25 +0200
commit3d6a02f19ff15a38dae9686033e37499b3968256 (patch)
tree7ff63164e043e4ea6af4a715c702a59fe24ba0e9
parent51612fca32dda445056ca9a7533bae258acd3ecb (diff)
downloadlibtasn1-3d6a02f19ff15a38dae9686033e37499b3968256.tar.gz
libtasn1-3d6a02f19ff15a38dae9686033e37499b3968256.tar.bz2
libtasn1-3d6a02f19ff15a38dae9686033e37499b3968256.zip
safer usage of memcpy().
-rw-r--r--lib/element.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/element.c b/lib/element.c
index 8062bce..3f31aa2 100644
--- a/lib/element.c
+++ b/lib/element.c
@@ -621,7 +621,7 @@ asn1_write_value (asn1_node node_root, const char *name,
if (ptr_size < data_size) { \
return ASN1_MEM_ERROR; \
} else { \
- if (ptr) \
+ if (ptr && data_size > 0) \
memcpy (ptr, data, data_size); \
}
@@ -631,8 +631,9 @@ asn1_write_value (asn1_node node_root, const char *name,
return ASN1_MEM_ERROR; \
} else { \
/* this strcpy is checked */ \
- if (ptr) \
+ if (ptr) { \
_asn1_strcpy (ptr, data); \
+ } \
}
#define PUT_AS_STR_VALUE( ptr, ptr_size, data, data_size) \
@@ -642,7 +643,8 @@ asn1_write_value (asn1_node node_root, const char *name,
} else { \
/* this strcpy is checked */ \
if (ptr) { \
- memcpy (ptr, data, data_size); \
+ if (data_size > 0) \
+ memcpy (ptr, data, data_size); \
ptr[data_size] = 0; \
} \
}
@@ -887,7 +889,8 @@ asn1_read_value_type (asn1_node root, const char *name, void *ivalue,
case ASN1_ETYPE_OBJECT_ID:
if (node->type & CONST_ASSIGN)
{
- value[0] = 0;
+ if (value)
+ value[0] = 0;
p = node->down;
while (p)
{