]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Check all memory allocation in examples and certtool
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Tue, 14 May 2019 19:39:46 +0000 (21:39 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Tue, 14 May 2019 19:42:28 +0000 (21:42 +0200)
Resolves: #739

Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
doc/examples/ex-verify.c
doc/examples/tlsproxy/buffer.c
doc/examples/tlsproxy/crypto-gnutls.c
src/certtool-cfg.c

index 0aa9922f811e4194829dacebda1debcfe82649ab..623198793b93a4f870d69cda14803d24c3673d3c 100644 (file)
@@ -55,6 +55,7 @@ verify_certificate_chain(const char *hostname,
                                               GNUTLS_TL_VERIFY_CRL, 0));
 
         cert = malloc(sizeof(*cert) * cert_chain_length);
+        assert(cert != NULL);
 
         /* Import all the certificates in the chain to
          * native certificate format.
index cd1ff37eea3b1f5c9a62ed7e2e665110ee622743..05c82121fe17095fe1c3c64e105beb7034a89d01 100644 (file)
@@ -80,6 +80,8 @@ buffer_t *
 bufNew (ssize_t size, ssize_t hwm)
 {
   buffer_t *b = calloc (1, sizeof (buffer_t));
+  if (!b) return NULL;
+
   b->buf = calloc (1, size);
   b->size = size;
   b->hwm = hwm;
index 634f417b423b1567b27b72ec220936e72dcf5baf..0764fdf10f11fdea770583a71c2c419ed6e734db 100644 (file)
@@ -178,6 +178,8 @@ tlssession_new (int isserver,
 {
   int ret;
   tlssession_t *s = calloc (1, sizeof (tlssession_t));
+  if (!s)
+    return NULL;
 
   if (quitfn)
     s->quitfn = quitfn;
index 3cf9aef55f0bc91da0a374fcbcf3b49a9a70d2cd..8e8b8b59c8a0d42bcda3b6d7bdedea6f7af67fd5 100644 (file)
@@ -65,6 +65,12 @@ extern int ask_pass;
 #define MAX_ENTRIES 128
 #define MAX_POLICIES 8
 
+#define CHECK_MALLOC(x) \
+       if (x == NULL) { \
+               fprintf(stderr, "memory error\n"); \
+               exit(1); \
+       }
+
 #define PRINT_TIME_T_ERROR \
        if (sizeof(time_t) < 8) \
                fprintf(stderr, "This system expresses time with a 32-bit time_t; that prevents dates after 2038 to be expressed by GnuTLS.\n")
@@ -245,6 +251,7 @@ void cfg_init(void)
     if (s_name == NULL) { \
       i = 0; \
       s_name = malloc(sizeof(char*)*MAX_ENTRIES); \
+      CHECK_MALLOC(s_name); \
       do { \
        if (val && strcmp(val->pzName, name)!=0) \
          continue; \
@@ -266,10 +273,12 @@ void cfg_init(void)
     if (s_name == NULL) { \
       i = 0; \
       s_name = malloc(sizeof(char*)*MAX_ENTRIES); \
+      CHECK_MALLOC(s_name); \
       do { \
        if (val && strcmp(val->pzName, name)!=0) \
          continue; \
        str = strdup(val->v.strVal); \
+       CHECK_MALLOC(str); \
        if ((p=strchr(str, ' ')) == NULL && (p=strchr(str, '\t')) == NULL) { \
          fprintf(stderr, "Error parsing %s\n", name); \
          exit(1); \