summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorderaadt <>2014-04-20 10:31:43 +0000
committerderaadt <>2014-04-20 10:31:43 +0000
commitba5ffe465c7b412a5c5361b3ef1897cccc0543a3 (patch)
treef70f0a2c839fe80bfe832a19ebee0988da0b5261 /src
parentccee83a0cbb25cd47e7c93283f5331f21e4fe078 (diff)
downloadopenbsd-ba5ffe465c7b412a5c5361b3ef1897cccc0543a3.tar.gz
openbsd-ba5ffe465c7b412a5c5361b3ef1897cccc0543a3.tar.bz2
openbsd-ba5ffe465c7b412a5c5361b3ef1897cccc0543a3.zip
Use calloc(a,b) instead of malloc(a*b) + memset(a*b). I don't know if
this instance is integer-overflowable, but we cannot keep hand-auditing every instance (or apathetically ignoring these issues) when the simple calloc idiom is better in the presence of a good calloc(). It is simply unfeasible to always enter correct range checks before the aggregate size calculation, just go find some 4000 lines of code, REPAIR THEM ALL, then come back and tell me I am wrong. This only works on systems where calloc() does the integer overflow check, but if your system doesn't do this, you need to ask your vendor WHY THEY ARE 10 YEARS BEHIND IN BEST PRACTICE? This is the kind of problem that needs to be solved at the right layer. malloc integer-overflow was implicated in the 2002 OpenSSH hole. OpenSSH and much other code is now written to use calloc(), for instance OpenSSH has 103 calls to it. We feel safer with our use of calloc(). It is a natural approach for us to use calloc(). How safe do you feel on systems which lack that range check in their calloc()? Good writeup from 2006: http://undeadly.org/cgi?action=article&sid=20060330071917
Diffstat (limited to 'src')
-rw-r--r--src/lib/libssl/src/ssl/ssl_ciph.c3
-rw-r--r--src/lib/libssl/ssl_ciph.c3
2 files changed, 2 insertions, 4 deletions
diff --git a/src/lib/libssl/src/ssl/ssl_ciph.c b/src/lib/libssl/src/ssl/ssl_ciph.c
index 7d2ea6c481..87b3f7a3cc 100644
--- a/src/lib/libssl/src/ssl/ssl_ciph.c
+++ b/src/lib/libssl/src/ssl/ssl_ciph.c
@@ -1030,12 +1030,11 @@ ssl_cipher_strength_sort(CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p)
1030 curr = curr->next; 1030 curr = curr->next;
1031 } 1031 }
1032 1032
1033 number_uses = malloc((max_strength_bits + 1) * sizeof(int)); 1033 number_uses = calloc((max_strength_bits + 1), sizeof(int));
1034 if (!number_uses) { 1034 if (!number_uses) {
1035 SSLerr(SSL_F_SSL_CIPHER_STRENGTH_SORT, ERR_R_MALLOC_FAILURE); 1035 SSLerr(SSL_F_SSL_CIPHER_STRENGTH_SORT, ERR_R_MALLOC_FAILURE);
1036 return (0); 1036 return (0);
1037 } 1037 }
1038 memset(number_uses, 0, (max_strength_bits + 1) * sizeof(int));
1039 1038
1040 /* 1039 /*
1041 * Now find the strength_bits values actually used 1040 * Now find the strength_bits values actually used
diff --git a/src/lib/libssl/ssl_ciph.c b/src/lib/libssl/ssl_ciph.c
index 7d2ea6c481..87b3f7a3cc 100644
--- a/src/lib/libssl/ssl_ciph.c
+++ b/src/lib/libssl/ssl_ciph.c
@@ -1030,12 +1030,11 @@ ssl_cipher_strength_sort(CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p)
1030 curr = curr->next; 1030 curr = curr->next;
1031 } 1031 }
1032 1032
1033 number_uses = malloc((max_strength_bits + 1) * sizeof(int)); 1033 number_uses = calloc((max_strength_bits + 1), sizeof(int));
1034 if (!number_uses) { 1034 if (!number_uses) {
1035 SSLerr(SSL_F_SSL_CIPHER_STRENGTH_SORT, ERR_R_MALLOC_FAILURE); 1035 SSLerr(SSL_F_SSL_CIPHER_STRENGTH_SORT, ERR_R_MALLOC_FAILURE);
1036 return (0); 1036 return (0);
1037 } 1037 }
1038 memset(number_uses, 0, (max_strength_bits + 1) * sizeof(int));
1039 1038
1040 /* 1039 /*
1041 * Now find the strength_bits values actually used 1040 * Now find the strength_bits values actually used