summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2015-04-15 16:25:43 +0000
committerjsing <>2015-04-15 16:25:43 +0000
commit4392117575862b75cab68af43d324941bcc50add (patch)
tree93f4dd5b408000ba8c70c2f3ed904827d01167b8
parent7948fa34e2e3a2bdbdec9153ddb86a20ddb4944a (diff)
downloadopenbsd-4392117575862b75cab68af43d324941bcc50add.tar.gz
openbsd-4392117575862b75cab68af43d324941bcc50add.tar.bz2
openbsd-4392117575862b75cab68af43d324941bcc50add.zip
Clean up the ssl_bytes_to_cipher_list() API - rather than having the
ability to pass or not pass a STACK_OF(SSL_CIPHER) *, which is then either zeroed or if NULL a new one is allocated, always allocate one and return it directly. Inspired by simliar changes in BoringSSL. ok beck@ doug@
-rw-r--r--src/lib/libssl/s3_srvr.c8
-rw-r--r--src/lib/libssl/src/ssl/s3_srvr.c8
-rw-r--r--src/lib/libssl/src/ssl/ssl_lib.c24
-rw-r--r--src/lib/libssl/src/ssl/ssl_locl.h4
-rw-r--r--src/lib/libssl/ssl_lib.c24
-rw-r--r--src/lib/libssl/ssl_locl.h4
6 files changed, 30 insertions, 42 deletions
diff --git a/src/lib/libssl/s3_srvr.c b/src/lib/libssl/s3_srvr.c
index ce48809f65..5248cc864c 100644
--- a/src/lib/libssl/s3_srvr.c
+++ b/src/lib/libssl/s3_srvr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: s3_srvr.c,v 1.101 2015/03/27 12:29:54 jsing Exp $ */ 1/* $OpenBSD: s3_srvr.c,v 1.102 2015/04/15 16:25:43 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -988,9 +988,9 @@ ssl3_get_client_hello(SSL *s)
988 } 988 }
989 if (p + i - d > n) 989 if (p + i - d > n)
990 goto truncated; 990 goto truncated;
991 if ((i > 0) && 991 if (i > 0) {
992 (ssl_bytes_to_cipher_list(s, p, i, &(ciphers)) == NULL)) { 992 if ((ciphers = ssl_bytes_to_cipher_list(s, p, i)) == NULL)
993 goto err; 993 goto err;
994 } 994 }
995 p += i; 995 p += i;
996 996
diff --git a/src/lib/libssl/src/ssl/s3_srvr.c b/src/lib/libssl/src/ssl/s3_srvr.c
index ce48809f65..5248cc864c 100644
--- a/src/lib/libssl/src/ssl/s3_srvr.c
+++ b/src/lib/libssl/src/ssl/s3_srvr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: s3_srvr.c,v 1.101 2015/03/27 12:29:54 jsing Exp $ */ 1/* $OpenBSD: s3_srvr.c,v 1.102 2015/04/15 16:25:43 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -988,9 +988,9 @@ ssl3_get_client_hello(SSL *s)
988 } 988 }
989 if (p + i - d > n) 989 if (p + i - d > n)
990 goto truncated; 990 goto truncated;
991 if ((i > 0) && 991 if (i > 0) {
992 (ssl_bytes_to_cipher_list(s, p, i, &(ciphers)) == NULL)) { 992 if ((ciphers = ssl_bytes_to_cipher_list(s, p, i)) == NULL)
993 goto err; 993 goto err;
994 } 994 }
995 p += i; 995 p += i;
996 996
diff --git a/src/lib/libssl/src/ssl/ssl_lib.c b/src/lib/libssl/src/ssl/ssl_lib.c
index 79ce81e70e..b5ce2ea5ac 100644
--- a/src/lib/libssl/src/ssl/ssl_lib.c
+++ b/src/lib/libssl/src/ssl/ssl_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_lib.c,v 1.102 2015/03/27 12:26:41 jsing Exp $ */ 1/* $OpenBSD: ssl_lib.c,v 1.103 2015/04/15 16:25:43 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -1410,11 +1410,10 @@ ssl_cipher_list_to_bytes(SSL *s, STACK_OF(SSL_CIPHER) *sk, unsigned char *p)
1410} 1410}
1411 1411
1412STACK_OF(SSL_CIPHER) * 1412STACK_OF(SSL_CIPHER) *
1413ssl_bytes_to_cipher_list(SSL *s, unsigned char *p, int num, 1413ssl_bytes_to_cipher_list(SSL *s, unsigned char *p, int num)
1414 STACK_OF(SSL_CIPHER) **skp)
1415{ 1414{
1416 const SSL_CIPHER *c; 1415 const SSL_CIPHER *c;
1417 STACK_OF(SSL_CIPHER) *sk; 1416 STACK_OF(SSL_CIPHER) *sk = NULL;
1418 int i; 1417 int i;
1419 unsigned long cipher_id; 1418 unsigned long cipher_id;
1420 uint16_t cipher_value; 1419 uint16_t cipher_value;
@@ -1428,13 +1427,10 @@ ssl_bytes_to_cipher_list(SSL *s, unsigned char *p, int num,
1428 SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST); 1427 SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST);
1429 return (NULL); 1428 return (NULL);
1430 } 1429 }
1431 if (skp == NULL || *skp == NULL) { 1430
1432 sk = sk_SSL_CIPHER_new_null(); /* change perhaps later */ 1431 if ((sk = sk_SSL_CIPHER_new_null()) == NULL) {
1433 if (sk == NULL) 1432 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST, ERR_R_MALLOC_FAILURE);
1434 goto err; 1433 goto err;
1435 } else {
1436 sk = *skp;
1437 sk_SSL_CIPHER_zero(sk);
1438 } 1434 }
1439 1435
1440 for (i = 0; i < num; i += SSL3_CIPHER_VALUE_SIZE) { 1436 for (i = 0; i < num; i += SSL3_CIPHER_VALUE_SIZE) {
@@ -1486,13 +1482,11 @@ ssl_bytes_to_cipher_list(SSL *s, unsigned char *p, int num,
1486 } 1482 }
1487 } 1483 }
1488 1484
1489 if (skp != NULL)
1490 *skp = sk;
1491 return (sk); 1485 return (sk);
1492 1486
1493err: 1487err:
1494 if (skp == NULL || *skp == NULL) 1488 sk_SSL_CIPHER_free(sk);
1495 sk_SSL_CIPHER_free(sk); 1489
1496 return (NULL); 1490 return (NULL);
1497} 1491}
1498 1492
diff --git a/src/lib/libssl/src/ssl/ssl_locl.h b/src/lib/libssl/src/ssl/ssl_locl.h
index cb1da576f4..7b3ecdf665 100644
--- a/src/lib/libssl/src/ssl/ssl_locl.h
+++ b/src/lib/libssl/src/ssl/ssl_locl.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_locl.h,v 1.89 2015/03/27 12:29:54 jsing Exp $ */ 1/* $OpenBSD: ssl_locl.h,v 1.90 2015/04/15 16:25:43 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -570,7 +570,7 @@ DECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(SSL_CIPHER, SSL_CIPHER, ssl_cipher_id);
570int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap, 570int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap,
571 const SSL_CIPHER * const *bp); 571 const SSL_CIPHER * const *bp);
572STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s, unsigned char *p, 572STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s, unsigned char *p,
573 int num, STACK_OF(SSL_CIPHER) **skp); 573 int num);
574int ssl_cipher_list_to_bytes(SSL *s, STACK_OF(SSL_CIPHER) *sk, 574int ssl_cipher_list_to_bytes(SSL *s, STACK_OF(SSL_CIPHER) *sk,
575 unsigned char *p); 575 unsigned char *p);
576STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth, 576STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth,
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c
index 79ce81e70e..b5ce2ea5ac 100644
--- a/src/lib/libssl/ssl_lib.c
+++ b/src/lib/libssl/ssl_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_lib.c,v 1.102 2015/03/27 12:26:41 jsing Exp $ */ 1/* $OpenBSD: ssl_lib.c,v 1.103 2015/04/15 16:25:43 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -1410,11 +1410,10 @@ ssl_cipher_list_to_bytes(SSL *s, STACK_OF(SSL_CIPHER) *sk, unsigned char *p)
1410} 1410}
1411 1411
1412STACK_OF(SSL_CIPHER) * 1412STACK_OF(SSL_CIPHER) *
1413ssl_bytes_to_cipher_list(SSL *s, unsigned char *p, int num, 1413ssl_bytes_to_cipher_list(SSL *s, unsigned char *p, int num)
1414 STACK_OF(SSL_CIPHER) **skp)
1415{ 1414{
1416 const SSL_CIPHER *c; 1415 const SSL_CIPHER *c;
1417 STACK_OF(SSL_CIPHER) *sk; 1416 STACK_OF(SSL_CIPHER) *sk = NULL;
1418 int i; 1417 int i;
1419 unsigned long cipher_id; 1418 unsigned long cipher_id;
1420 uint16_t cipher_value; 1419 uint16_t cipher_value;
@@ -1428,13 +1427,10 @@ ssl_bytes_to_cipher_list(SSL *s, unsigned char *p, int num,
1428 SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST); 1427 SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST);
1429 return (NULL); 1428 return (NULL);
1430 } 1429 }
1431 if (skp == NULL || *skp == NULL) { 1430
1432 sk = sk_SSL_CIPHER_new_null(); /* change perhaps later */ 1431 if ((sk = sk_SSL_CIPHER_new_null()) == NULL) {
1433 if (sk == NULL) 1432 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST, ERR_R_MALLOC_FAILURE);
1434 goto err; 1433 goto err;
1435 } else {
1436 sk = *skp;
1437 sk_SSL_CIPHER_zero(sk);
1438 } 1434 }
1439 1435
1440 for (i = 0; i < num; i += SSL3_CIPHER_VALUE_SIZE) { 1436 for (i = 0; i < num; i += SSL3_CIPHER_VALUE_SIZE) {
@@ -1486,13 +1482,11 @@ ssl_bytes_to_cipher_list(SSL *s, unsigned char *p, int num,
1486 } 1482 }
1487 } 1483 }
1488 1484
1489 if (skp != NULL)
1490 *skp = sk;
1491 return (sk); 1485 return (sk);
1492 1486
1493err: 1487err:
1494 if (skp == NULL || *skp == NULL) 1488 sk_SSL_CIPHER_free(sk);
1495 sk_SSL_CIPHER_free(sk); 1489
1496 return (NULL); 1490 return (NULL);
1497} 1491}
1498 1492
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h
index cb1da576f4..7b3ecdf665 100644
--- a/src/lib/libssl/ssl_locl.h
+++ b/src/lib/libssl/ssl_locl.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_locl.h,v 1.89 2015/03/27 12:29:54 jsing Exp $ */ 1/* $OpenBSD: ssl_locl.h,v 1.90 2015/04/15 16:25:43 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -570,7 +570,7 @@ DECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(SSL_CIPHER, SSL_CIPHER, ssl_cipher_id);
570int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap, 570int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap,
571 const SSL_CIPHER * const *bp); 571 const SSL_CIPHER * const *bp);
572STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s, unsigned char *p, 572STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s, unsigned char *p,
573 int num, STACK_OF(SSL_CIPHER) **skp); 573 int num);
574int ssl_cipher_list_to_bytes(SSL *s, STACK_OF(SSL_CIPHER) *sk, 574int ssl_cipher_list_to_bytes(SSL *s, STACK_OF(SSL_CIPHER) *sk,
575 unsigned char *p); 575 unsigned char *p);
576STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth, 576STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth,