summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbeck <>2014-10-16 03:19:02 +0000
committerbeck <>2014-10-16 03:19:02 +0000
commit909247b30c58e971994251b7bf7092e9dd8967df (patch)
tree7ece308937377519bc98e92f91a60254d78bd0be
parent2a0ad3abadc99c32f111a2f2aaa9131c0acf27cb (diff)
downloadopenbsd-909247b30c58e971994251b7bf7092e9dd8967df.tar.gz
openbsd-909247b30c58e971994251b7bf7092e9dd8967df.tar.bz2
openbsd-909247b30c58e971994251b7bf7092e9dd8967df.zip
Get rid of the last remaining BUF_strdup and BUF_strlcpy and friends, use
intrinsic functions everywhere, and wrap these functions in an #ifndef LIBRESSL_INTERNAL to make sure we don't bring their use back.
-rw-r--r--src/lib/libcrypto/buffer/buffer.h7
-rw-r--r--src/lib/libcrypto/store/str_lib.c4
-rw-r--r--src/lib/libcrypto/x509/x509_trs.c5
-rw-r--r--src/lib/libssl/src/crypto/buffer/buffer.h7
-rw-r--r--src/lib/libssl/src/crypto/store/str_lib.c4
-rw-r--r--src/lib/libssl/src/crypto/x509/x509_trs.c5
-rw-r--r--src/lib/libssl/src/ssl/ssl_asn1.c4
-rw-r--r--src/lib/libssl/ssl_asn1.c4
8 files changed, 24 insertions, 16 deletions
diff --git a/src/lib/libcrypto/buffer/buffer.h b/src/lib/libcrypto/buffer/buffer.h
index def1943d31..5aa0e3ea47 100644
--- a/src/lib/libcrypto/buffer/buffer.h
+++ b/src/lib/libcrypto/buffer/buffer.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: buffer.h,v 1.13 2014/07/13 14:13:27 beck Exp $ */ 1/* $OpenBSD: buffer.h,v 1.14 2014/10/16 03:19:02 beck 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 *
@@ -84,17 +84,20 @@ BUF_MEM *BUF_MEM_new(void);
84void BUF_MEM_free(BUF_MEM *a); 84void BUF_MEM_free(BUF_MEM *a);
85int BUF_MEM_grow(BUF_MEM *str, size_t len); 85int BUF_MEM_grow(BUF_MEM *str, size_t len);
86int BUF_MEM_grow_clean(BUF_MEM *str, size_t len); 86int BUF_MEM_grow_clean(BUF_MEM *str, size_t len);
87#ifndef LIBRESSL_INTERNAL
87char * BUF_strdup(const char *str); 88char * BUF_strdup(const char *str);
88char * BUF_strndup(const char *str, size_t siz); 89char * BUF_strndup(const char *str, size_t siz);
90#endif
89void * BUF_memdup(const void *data, size_t siz); 91void * BUF_memdup(const void *data, size_t siz);
90void BUF_reverse(unsigned char *out, const unsigned char *in, size_t siz); 92void BUF_reverse(unsigned char *out, const unsigned char *in, size_t siz);
91 93
94#ifndef LIBRESSL_INTERNAL
92/* safe string functions */ 95/* safe string functions */
93size_t BUF_strlcpy(char *dst, const char *src, size_t siz) 96size_t BUF_strlcpy(char *dst, const char *src, size_t siz)
94 __attribute__ ((__bounded__(__string__,1,3))); 97 __attribute__ ((__bounded__(__string__,1,3)));
95size_t BUF_strlcat(char *dst, const char *src, size_t siz) 98size_t BUF_strlcat(char *dst, const char *src, size_t siz)
96 __attribute__ ((__bounded__(__string__,1,3))); 99 __attribute__ ((__bounded__(__string__,1,3)));
97 100#endif
98 101
99/* BEGIN ERROR CODES */ 102/* BEGIN ERROR CODES */
100/* The following lines are auto generated by the script mkerr.pl. Any changes 103/* The following lines are auto generated by the script mkerr.pl. Any changes
diff --git a/src/lib/libcrypto/store/str_lib.c b/src/lib/libcrypto/store/str_lib.c
index ff00aa19ce..9ae93b6405 100644
--- a/src/lib/libcrypto/store/str_lib.c
+++ b/src/lib/libcrypto/store/str_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: str_lib.c,v 1.10 2014/07/10 22:45:58 jsing Exp $ */ 1/* $OpenBSD: str_lib.c,v 1.11 2014/10/16 03:19:02 beck Exp $ */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL 2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2003. 3 * project 2003.
4 */ 4 */
@@ -1341,7 +1341,7 @@ STORE_ATTR_INFO_set_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1341 return 0; 1341 return 0;
1342 } 1342 }
1343 if (!ATTR_IS_SET(attrs, code)) { 1343 if (!ATTR_IS_SET(attrs, code)) {
1344 if ((attrs->values[code].cstring = BUF_strndup(cstr, cstr_size))) 1344 if (cstr && (attrs->values[code].cstring = strndup(cstr, cstr_size)))
1345 return 1; 1345 return 1;
1346 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR, 1346 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR,
1347 ERR_R_MALLOC_FAILURE); 1347 ERR_R_MALLOC_FAILURE);
diff --git a/src/lib/libcrypto/x509/x509_trs.c b/src/lib/libcrypto/x509/x509_trs.c
index 544fb5e884..d4e6be65e6 100644
--- a/src/lib/libcrypto/x509/x509_trs.c
+++ b/src/lib/libcrypto/x509/x509_trs.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_trs.c,v 1.16 2014/09/28 10:52:59 miod Exp $ */ 1/* $OpenBSD: x509_trs.c,v 1.17 2014/10/16 03:19:02 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -57,6 +57,7 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h>
60 61
61#include <openssl/err.h> 62#include <openssl/err.h>
62#include <openssl/x509v3.h> 63#include <openssl/x509v3.h>
@@ -202,7 +203,7 @@ X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int),
202 if (trtmp->flags & X509_TRUST_DYNAMIC_NAME) 203 if (trtmp->flags & X509_TRUST_DYNAMIC_NAME)
203 free(trtmp->name); 204 free(trtmp->name);
204 /* dup supplied name */ 205 /* dup supplied name */
205 if ((trtmp->name = BUF_strdup(name)) == NULL) 206 if (name == NULL || (trtmp->name = strdup(name)) == NULL)
206 goto err; 207 goto err;
207 /* Keep the dynamic flag of existing entry */ 208 /* Keep the dynamic flag of existing entry */
208 trtmp->flags &= X509_TRUST_DYNAMIC; 209 trtmp->flags &= X509_TRUST_DYNAMIC;
diff --git a/src/lib/libssl/src/crypto/buffer/buffer.h b/src/lib/libssl/src/crypto/buffer/buffer.h
index def1943d31..5aa0e3ea47 100644
--- a/src/lib/libssl/src/crypto/buffer/buffer.h
+++ b/src/lib/libssl/src/crypto/buffer/buffer.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: buffer.h,v 1.13 2014/07/13 14:13:27 beck Exp $ */ 1/* $OpenBSD: buffer.h,v 1.14 2014/10/16 03:19:02 beck 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 *
@@ -84,17 +84,20 @@ BUF_MEM *BUF_MEM_new(void);
84void BUF_MEM_free(BUF_MEM *a); 84void BUF_MEM_free(BUF_MEM *a);
85int BUF_MEM_grow(BUF_MEM *str, size_t len); 85int BUF_MEM_grow(BUF_MEM *str, size_t len);
86int BUF_MEM_grow_clean(BUF_MEM *str, size_t len); 86int BUF_MEM_grow_clean(BUF_MEM *str, size_t len);
87#ifndef LIBRESSL_INTERNAL
87char * BUF_strdup(const char *str); 88char * BUF_strdup(const char *str);
88char * BUF_strndup(const char *str, size_t siz); 89char * BUF_strndup(const char *str, size_t siz);
90#endif
89void * BUF_memdup(const void *data, size_t siz); 91void * BUF_memdup(const void *data, size_t siz);
90void BUF_reverse(unsigned char *out, const unsigned char *in, size_t siz); 92void BUF_reverse(unsigned char *out, const unsigned char *in, size_t siz);
91 93
94#ifndef LIBRESSL_INTERNAL
92/* safe string functions */ 95/* safe string functions */
93size_t BUF_strlcpy(char *dst, const char *src, size_t siz) 96size_t BUF_strlcpy(char *dst, const char *src, size_t siz)
94 __attribute__ ((__bounded__(__string__,1,3))); 97 __attribute__ ((__bounded__(__string__,1,3)));
95size_t BUF_strlcat(char *dst, const char *src, size_t siz) 98size_t BUF_strlcat(char *dst, const char *src, size_t siz)
96 __attribute__ ((__bounded__(__string__,1,3))); 99 __attribute__ ((__bounded__(__string__,1,3)));
97 100#endif
98 101
99/* BEGIN ERROR CODES */ 102/* BEGIN ERROR CODES */
100/* The following lines are auto generated by the script mkerr.pl. Any changes 103/* The following lines are auto generated by the script mkerr.pl. Any changes
diff --git a/src/lib/libssl/src/crypto/store/str_lib.c b/src/lib/libssl/src/crypto/store/str_lib.c
index ff00aa19ce..9ae93b6405 100644
--- a/src/lib/libssl/src/crypto/store/str_lib.c
+++ b/src/lib/libssl/src/crypto/store/str_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: str_lib.c,v 1.10 2014/07/10 22:45:58 jsing Exp $ */ 1/* $OpenBSD: str_lib.c,v 1.11 2014/10/16 03:19:02 beck Exp $ */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL 2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2003. 3 * project 2003.
4 */ 4 */
@@ -1341,7 +1341,7 @@ STORE_ATTR_INFO_set_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1341 return 0; 1341 return 0;
1342 } 1342 }
1343 if (!ATTR_IS_SET(attrs, code)) { 1343 if (!ATTR_IS_SET(attrs, code)) {
1344 if ((attrs->values[code].cstring = BUF_strndup(cstr, cstr_size))) 1344 if (cstr && (attrs->values[code].cstring = strndup(cstr, cstr_size)))
1345 return 1; 1345 return 1;
1346 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR, 1346 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR,
1347 ERR_R_MALLOC_FAILURE); 1347 ERR_R_MALLOC_FAILURE);
diff --git a/src/lib/libssl/src/crypto/x509/x509_trs.c b/src/lib/libssl/src/crypto/x509/x509_trs.c
index 544fb5e884..d4e6be65e6 100644
--- a/src/lib/libssl/src/crypto/x509/x509_trs.c
+++ b/src/lib/libssl/src/crypto/x509/x509_trs.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_trs.c,v 1.16 2014/09/28 10:52:59 miod Exp $ */ 1/* $OpenBSD: x509_trs.c,v 1.17 2014/10/16 03:19:02 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -57,6 +57,7 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h>
60 61
61#include <openssl/err.h> 62#include <openssl/err.h>
62#include <openssl/x509v3.h> 63#include <openssl/x509v3.h>
@@ -202,7 +203,7 @@ X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int),
202 if (trtmp->flags & X509_TRUST_DYNAMIC_NAME) 203 if (trtmp->flags & X509_TRUST_DYNAMIC_NAME)
203 free(trtmp->name); 204 free(trtmp->name);
204 /* dup supplied name */ 205 /* dup supplied name */
205 if ((trtmp->name = BUF_strdup(name)) == NULL) 206 if (name == NULL || (trtmp->name = strdup(name)) == NULL)
206 goto err; 207 goto err;
207 /* Keep the dynamic flag of existing entry */ 208 /* Keep the dynamic flag of existing entry */
208 trtmp->flags &= X509_TRUST_DYNAMIC; 209 trtmp->flags &= X509_TRUST_DYNAMIC;
diff --git a/src/lib/libssl/src/ssl/ssl_asn1.c b/src/lib/libssl/src/ssl/ssl_asn1.c
index 627acbf5b0..8dc24d5283 100644
--- a/src/lib/libssl/src/ssl/ssl_asn1.c
+++ b/src/lib/libssl/src/ssl/ssl_asn1.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_asn1.c,v 1.37 2014/07/13 23:34:39 jsing Exp $ */ 1/* $OpenBSD: ssl_asn1.c,v 1.38 2014/10/16 03:19:02 beck 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 *
@@ -585,7 +585,7 @@ d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp, long length)
585 c.slen -= (c.p - c.q); 585 c.slen -= (c.p - c.q);
586 } 586 }
587 if (os.data) { 587 if (os.data) {
588 ret->tlsext_hostname = BUF_strndup((char *)os.data, os.length); 588 ret->tlsext_hostname = strndup((char *)os.data, os.length);
589 free(os.data); 589 free(os.data);
590 os.data = NULL; 590 os.data = NULL;
591 os.length = 0; 591 os.length = 0;
diff --git a/src/lib/libssl/ssl_asn1.c b/src/lib/libssl/ssl_asn1.c
index 627acbf5b0..8dc24d5283 100644
--- a/src/lib/libssl/ssl_asn1.c
+++ b/src/lib/libssl/ssl_asn1.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_asn1.c,v 1.37 2014/07/13 23:34:39 jsing Exp $ */ 1/* $OpenBSD: ssl_asn1.c,v 1.38 2014/10/16 03:19:02 beck 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 *
@@ -585,7 +585,7 @@ d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp, long length)
585 c.slen -= (c.p - c.q); 585 c.slen -= (c.p - c.q);
586 } 586 }
587 if (os.data) { 587 if (os.data) {
588 ret->tlsext_hostname = BUF_strndup((char *)os.data, os.length); 588 ret->tlsext_hostname = strndup((char *)os.data, os.length);
589 free(os.data); 589 free(os.data);
590 os.data = NULL; 590 os.data = NULL;
591 os.length = 0; 591 os.length = 0;