summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2019-05-15 04:52:35 +0000
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2019-05-15 04:52:35 +0000
commit885b9c31f47bb55bd5e592c6e3787e3132ff8937 (patch)
treecbf0b21f3a59ae99f5bc6f51dc43c106a488050e
parent3667f16983e479f6dbbeeab84fec36b45a7c82ad (diff)
parentbb31860b6e034e99d75173ed39e72e2b3a6ebe66 (diff)
downloadgnutls-885b9c31f47bb55bd5e592c6e3787e3132ff8937.tar.gz
Merge branch 'tmp-check-allocations' into 'master'
Check all memory allocation in examples and certtool Closes #739 See merge request gnutls/gnutls!998
-rw-r--r--doc/examples/ex-verify.c1
-rw-r--r--doc/examples/tlsproxy/buffer.c2
-rw-r--r--doc/examples/tlsproxy/crypto-gnutls.c2
-rw-r--r--src/certtool-cfg.c9
4 files changed, 14 insertions, 0 deletions
diff --git a/doc/examples/ex-verify.c b/doc/examples/ex-verify.c
index 0aa9922f81..623198793b 100644
--- a/doc/examples/ex-verify.c
+++ b/doc/examples/ex-verify.c
@@ -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.
diff --git a/doc/examples/tlsproxy/buffer.c b/doc/examples/tlsproxy/buffer.c
index cd1ff37eea..05c82121fe 100644
--- a/doc/examples/tlsproxy/buffer.c
+++ b/doc/examples/tlsproxy/buffer.c
@@ -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;
diff --git a/doc/examples/tlsproxy/crypto-gnutls.c b/doc/examples/tlsproxy/crypto-gnutls.c
index 634f417b42..0764fdf10f 100644
--- a/doc/examples/tlsproxy/crypto-gnutls.c
+++ b/doc/examples/tlsproxy/crypto-gnutls.c
@@ -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;
diff --git a/src/certtool-cfg.c b/src/certtool-cfg.c
index 3cf9aef55f..8e8b8b59c8 100644
--- a/src/certtool-cfg.c
+++ b/src/certtool-cfg.c
@@ -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); \