From 4018233c5dec90870294752bf79fc4987b9eada9 Mon Sep 17 00:00:00 2001 From: tedu Date: Wed, 23 Apr 2014 21:54:30 +0000 Subject: [PATCH] replace a bunch of hand duped strings with strdup --- lib/libcrypto/dso/dso_dlfcn.c | 8 ++------ lib/libcrypto/dso/dso_lib.c | 6 ++---- lib/libssl/src/crypto/dso/dso_dlfcn.c | 8 ++------ lib/libssl/src/crypto/dso/dso_lib.c | 6 ++---- 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/lib/libcrypto/dso/dso_dlfcn.c b/lib/libcrypto/dso/dso_dlfcn.c index 62b826ea430..9731df136d1 100644 --- a/lib/libcrypto/dso/dso_dlfcn.c +++ b/lib/libcrypto/dso/dso_dlfcn.c @@ -255,23 +255,19 @@ dlfcn_merger(DSO *dso, const char *filespec1, const char *filespec2) /* If the first file specification is a rooted path, it rules. same goes if the second file specification is missing. */ if (!filespec2 || (filespec1 != NULL && filespec1[0] == '/')) { - len = strlen(filespec1) + 1; - merged = malloc(len); + merged = strdup(filespec1); if (!merged) { DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE); return (NULL); } - strlcpy(merged, filespec1, len); } /* If the first file specification is missing, the second one rules. */ else if (!filespec1) { - len = strlen(filespec2) + 1; - merged = malloc(strlen(filespec2) + 1); + merged = strdup(filespec2); if (!merged) { DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE); return (NULL); } - strlcpy(merged, filespec2, len); } else /* This part isn't as trivial as it looks. It assumes that the second file specification really is a directory, and diff --git a/lib/libcrypto/dso/dso_lib.c b/lib/libcrypto/dso/dso_lib.c index ae10104560e..882b9c2fcbf 100644 --- a/lib/libcrypto/dso/dso_lib.c +++ b/lib/libcrypto/dso/dso_lib.c @@ -356,12 +356,11 @@ DSO_set_filename(DSO *dso, const char *filename) return (0); } /* We'll duplicate filename */ - copied = malloc(strlen(filename) + 1); + copied = strdup(filename); if (copied == NULL) { DSOerr(DSO_F_DSO_SET_FILENAME, ERR_R_MALLOC_FAILURE); return (0); } - strlcpy(copied, filename, strlen(filename) + 1); if (dso->filename) free(dso->filename); dso->filename = copied; @@ -409,13 +408,12 @@ DSO_convert_filename(DSO *dso, const char *filename) result = dso->meth->dso_name_converter(dso, filename); } if (result == NULL) { - result = malloc(strlen(filename) + 1); + result = strdup(filename); if (result == NULL) { DSOerr(DSO_F_DSO_CONVERT_FILENAME, ERR_R_MALLOC_FAILURE); return (NULL); } - strlcpy(result, filename, strlen(filename) + 1); } return (result); } diff --git a/lib/libssl/src/crypto/dso/dso_dlfcn.c b/lib/libssl/src/crypto/dso/dso_dlfcn.c index 62b826ea430..9731df136d1 100644 --- a/lib/libssl/src/crypto/dso/dso_dlfcn.c +++ b/lib/libssl/src/crypto/dso/dso_dlfcn.c @@ -255,23 +255,19 @@ dlfcn_merger(DSO *dso, const char *filespec1, const char *filespec2) /* If the first file specification is a rooted path, it rules. same goes if the second file specification is missing. */ if (!filespec2 || (filespec1 != NULL && filespec1[0] == '/')) { - len = strlen(filespec1) + 1; - merged = malloc(len); + merged = strdup(filespec1); if (!merged) { DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE); return (NULL); } - strlcpy(merged, filespec1, len); } /* If the first file specification is missing, the second one rules. */ else if (!filespec1) { - len = strlen(filespec2) + 1; - merged = malloc(strlen(filespec2) + 1); + merged = strdup(filespec2); if (!merged) { DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE); return (NULL); } - strlcpy(merged, filespec2, len); } else /* This part isn't as trivial as it looks. It assumes that the second file specification really is a directory, and diff --git a/lib/libssl/src/crypto/dso/dso_lib.c b/lib/libssl/src/crypto/dso/dso_lib.c index ae10104560e..882b9c2fcbf 100644 --- a/lib/libssl/src/crypto/dso/dso_lib.c +++ b/lib/libssl/src/crypto/dso/dso_lib.c @@ -356,12 +356,11 @@ DSO_set_filename(DSO *dso, const char *filename) return (0); } /* We'll duplicate filename */ - copied = malloc(strlen(filename) + 1); + copied = strdup(filename); if (copied == NULL) { DSOerr(DSO_F_DSO_SET_FILENAME, ERR_R_MALLOC_FAILURE); return (0); } - strlcpy(copied, filename, strlen(filename) + 1); if (dso->filename) free(dso->filename); dso->filename = copied; @@ -409,13 +408,12 @@ DSO_convert_filename(DSO *dso, const char *filename) result = dso->meth->dso_name_converter(dso, filename); } if (result == NULL) { - result = malloc(strlen(filename) + 1); + result = strdup(filename); if (result == NULL) { DSOerr(DSO_F_DSO_CONVERT_FILENAME, ERR_R_MALLOC_FAILURE); return (NULL); } - strlcpy(result, filename, strlen(filename) + 1); } return (result); } -- 2.20.1