]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
copy_string() and copy_data() are more resilient on null input
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Fri, 18 Apr 2014 21:11:25 +0000 (23:11 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Fri, 18 Apr 2014 21:11:25 +0000 (23:11 +0200)
lib/x509/common.c

index 5f63dcf615b57db316c412b9a42a219cf15dc586..77a90a73361ecc74e839e8cc31ef06aa073905b7 100644 (file)
@@ -1863,9 +1863,11 @@ unsigned size_to_check;
                return GNUTLS_E_SHORT_MEMORY_BUFFER;
        }
 
-       if (out != NULL) {
+       if (out != NULL && str->data != NULL) {
                memcpy(out, str->data, str->size);
                out[str->size] = 0;
+       } else if (out != NULL) {
+               out[0] = 0;
        }
        *out_size = str->size;
 
@@ -1880,7 +1882,7 @@ int _gnutls_copy_data(gnutls_datum_t* str, uint8_t *out, size_t *out_size)
                return GNUTLS_E_SHORT_MEMORY_BUFFER;
        }
 
-       if (out != NULL) {
+       if (out != NULL && str->data != NULL) {
                memcpy(out, str->data, str->size);
        }
        *out_size = str->size;