summaryrefslogtreecommitdiff
path: root/lib/element.c
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2012-11-24 10:41:33 +0100
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2012-11-24 10:41:33 +0100
commit2ac0d04b5f8571866e729e9d816ea69780892634 (patch)
tree38b4ec7e74c3dceb88726e7b42e18253af2e1a46 /lib/element.c
parentbbfe113c2d7540c6883eb3d83d7052f49f7988fc (diff)
downloadlibtasn1-2ac0d04b5f8571866e729e9d816ea69780892634.tar.gz
libtasn1-2ac0d04b5f8571866e729e9d816ea69780892634.tar.bz2
libtasn1-2ac0d04b5f8571866e729e9d816ea69780892634.zip
some simplifications in time handling
Diffstat (limited to 'lib/element.c')
-rw-r--r--lib/element.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/element.c b/lib/element.c
index c1718e2..2c761c5 100644
--- a/lib/element.c
+++ b/lib/element.c
@@ -536,12 +536,12 @@ asn1_write_value (asn1_node node_root, const char *name,
default:
return ASN1_VALUE_NOT_FOUND;
}
- _asn1_set_value (node, value, _asn1_strlen (value) + 1);
+ _asn1_set_value (node, value, _asn1_strlen (value));
}
break;
case ASN1_ETYPE_GENERALIZED_TIME:
if (value)
- _asn1_set_value (node, value, _asn1_strlen (value) + 1);
+ _asn1_set_value (node, value, _asn1_strlen (value));
break;
case ASN1_ETYPE_OCTET_STRING:
case ASN1_ETYPE_GENERALSTRING:
@@ -628,6 +628,16 @@ asn1_write_value (asn1_node node_root, const char *name,
_asn1_strcpy(ptr, data); \
}
+#define PUT_AS_STR_VALUE( ptr, ptr_size, data, data_size) \
+ *len = data_size + 1; \
+ if (ptr_size < *len) { \
+ return ASN1_MEM_ERROR; \
+ } else { \
+ /* this strcpy is checked */ \
+ memcpy(ptr, data, data_size); \
+ ptr[data_size] = 0; \
+ }
+
#define ADD_STR_VALUE( ptr, ptr_size, data) \
*len = (int) _asn1_strlen(data) + 1; \
if (ptr_size < (int) _asn1_strlen(ptr)+(*len)) { \
@@ -895,7 +905,7 @@ asn1_read_value_type (asn1_node root, const char *name, void *ivalue, int *len,
break;
case ASN1_ETYPE_GENERALIZED_TIME:
case ASN1_ETYPE_UTC_TIME:
- PUT_STR_VALUE (value, value_size, node->value);
+ PUT_AS_STR_VALUE (value, value_size, node->value, node->value_len);
break;
case ASN1_ETYPE_OCTET_STRING:
case ASN1_ETYPE_GENERALSTRING: