Revert "GH614: Use memcpy()/strdup() when possible"

This reverts commit a89c9a0d855bce735116acfe147b24e386f566ba.

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4357)
This commit is contained in:
Pauli 2017-09-12 09:13:00 +10:00
parent eff1752b66
commit 4cacc9d510
4 changed files with 11 additions and 9 deletions

View File

@ -156,21 +156,23 @@ static char *dl_merger(DSO *dso, const char *filespec1, const char *filespec2)
* if the second file specification is missing. * if the second file specification is missing.
*/ */
if (!filespec2 || filespec1[0] == '/') { if (!filespec2 || filespec1[0] == '/') {
merged = OPENSSL_strdup(filespec1); merged = OPENSSL_malloc(strlen(filespec1) + 1);
if (merged == NULL) { if (merged == NULL) {
DSOerr(DSO_F_DL_MERGER, ERR_R_MALLOC_FAILURE); DSOerr(DSO_F_DL_MERGER, ERR_R_MALLOC_FAILURE);
return (NULL); return (NULL);
} }
strcpy(merged, filespec1);
} }
/* /*
* If the first file specification is missing, the second one rules. * If the first file specification is missing, the second one rules.
*/ */
else if (!filespec1) { else if (!filespec1) {
merged = OPENSSL_strdup(filespec2); merged = OPENSSL_malloc(strlen(filespec2) + 1);
if (merged == NULL) { if (merged == NULL) {
DSOerr(DSO_F_DL_MERGER, ERR_R_MALLOC_FAILURE); DSOerr(DSO_F_DL_MERGER, ERR_R_MALLOC_FAILURE);
return (NULL); return (NULL);
} }
strcpy(merged, filespec2);
} else } else
/* /*
* This part isn't as trivial as it looks. It assumes that the * This part isn't as trivial as it looks. It assumes that the

View File

@ -196,21 +196,23 @@ static char *dlfcn_merger(DSO *dso, const char *filespec1,
* if the second file specification is missing. * if the second file specification is missing.
*/ */
if (!filespec2 || (filespec1 != NULL && filespec1[0] == '/')) { if (!filespec2 || (filespec1 != NULL && filespec1[0] == '/')) {
merged = OPENSSL_strdup(filespec1); merged = OPENSSL_malloc(strlen(filespec1) + 1);
if (merged == NULL) { if (merged == NULL) {
DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE); DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE);
return (NULL); return (NULL);
} }
strcpy(merged, filespec1);
} }
/* /*
* If the first file specification is missing, the second one rules. * If the first file specification is missing, the second one rules.
*/ */
else if (!filespec1) { else if (!filespec1) {
merged = OPENSSL_strdup(filespec2); merged = OPENSSL_malloc(strlen(filespec2) + 1);
if (merged == NULL) { if (merged == NULL) {
DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE); DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE);
return (NULL); return (NULL);
} }
strcpy(merged, filespec2);
} else { } else {
/* /*
* This part isn't as trivial as it looks. It assumes that the * This part isn't as trivial as it looks. It assumes that the

View File

@ -27,14 +27,12 @@ int OPENSSL_memcmp(const void *v1, const void *v2, size_t n)
char *CRYPTO_strdup(const char *str, const char* file, int line) char *CRYPTO_strdup(const char *str, const char* file, int line)
{ {
char *ret; char *ret;
size_t size;
if (str == NULL) if (str == NULL)
return NULL; return NULL;
size = strlen(str) + 1; ret = CRYPTO_malloc(strlen(str) + 1, file, line);
ret = CRYPTO_malloc(size, file, line);
if (ret != NULL) if (ret != NULL)
memcpy(ret, str, size); strcpy(ret, str);
return ret; return ret;
} }

View File

@ -2471,7 +2471,7 @@ char *SSL_get_shared_ciphers(const SSL *s, char *buf, int len)
*p = '\0'; *p = '\0';
return buf; return buf;
} }
memcpy(p, c->name, n + 1); strcpy(p, c->name);
p += n; p += n;
*(p++) = ':'; *(p++) = ':';
len -= n + 1; len -= n + 1;