summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2017-02-20 13:49:55 +0100
committerNikos Mavrogiannopoulos <nmav@redhat.com>2017-02-20 16:35:41 +0100
commitaa78a8c916d62a92d36be861e0433f00452688aa (patch)
tree5dad902fe28b27b2a496e1fe7426c4dea3745412
parent5873d38c46b22a41fe19f4cd70cc1a977961c686 (diff)
downloadgnutls-aa78a8c916d62a92d36be861e0433f00452688aa.tar.gz
make_printable_string: allow operation with null input
Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
-rw-r--r--lib/x509/common.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/x509/common.c b/lib/x509/common.c
index b260784a6c..12fc7c7e56 100644
--- a/lib/x509/common.c
+++ b/lib/x509/common.c
@@ -285,6 +285,15 @@ make_printable_string(unsigned etype, const gnutls_datum_t * input,
int printable = 0;
int ret;
+ /* empty input strings result to a null string */
+ if (input->data == NULL || input->size == 0) {
+ out->data = gnutls_calloc(1, 1);
+ if (out->data == NULL)
+ return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
+ out->size = 0;
+ return 0;
+ }
+
if (etype == ASN1_ETYPE_BMP_STRING) {
ret = _gnutls_ucs2_to_utf8(input->data, input->size, out, 1);
if (ret < 0) {
@@ -399,6 +408,8 @@ decode_complex_string(const struct oid_to_string *oentry, void *value,
/* _gnutls_x509_read_value always null terminates */
}
+ assert(out->data != NULL);
+
/* Refuse to deal with strings containing NULs. */
if (strlen((void *) out->data) != (size_t) out->size) {
_gnutls_free_datum(out);