summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2014-04-20 22:31:56 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2014-04-20 22:31:56 +0000
commit5b48ff17484c198d3d6bac9de7618bbf56290dc0 (patch)
tree71f2464b0e41bfd738ce67e5df38665e00e2904f
parent0ad503da6caefe4870875521e56c0ccf3119c890 (diff)
Eliminate duplicated logic by switching from malloc+snprintf to asprintf
ok beck@
-rw-r--r--lib/libcrypto/dso/dso_dlfcn.c34
1 files changed, 14 insertions, 20 deletions
diff --git a/lib/libcrypto/dso/dso_dlfcn.c b/lib/libcrypto/dso/dso_dlfcn.c
index 245b9b14789..62b826ea430 100644
--- a/lib/libcrypto/dso/dso_dlfcn.c
+++ b/lib/libcrypto/dso/dso_dlfcn.c
@@ -307,30 +307,24 @@ static char *
dlfcn_name_converter(DSO *dso, const char *filename)
{
char *translated;
- int len, rsize, transform;
-
- len = strlen(filename);
- rsize = len + 1;
- transform = (strstr(filename, "/") == NULL);
- if (transform) {
- /* We will convert this to "%s.so" or "lib%s.so" etc */
- rsize += DSO_extlen; /* The length of ".so" */
+ int ret;
+
+ if (strchr(filename, '/') == NULL) {
+ /* Bare name, so convert to "%s.so" or "lib%s.so" */
if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0)
- rsize += 3; /* The length of "lib" */
+ ret = asprintf(&translated, "lib%s" DSO_ext, filename);
+ else
+ ret = asprintf(&translated, "%s" DSO_ext, filename);
+ if (ret == -1)
+ translated = NULL;
+ } else {
+ /* Full path, so just duplicate it */
+ translated = strdup(filename);
}
- translated = malloc(rsize);
- if (translated == NULL) {
+
+ if (translated == NULL)
DSOerr(DSO_F_DLFCN_NAME_CONVERTER,
DSO_R_NAME_TRANSLATION_FAILED);
- return (NULL);
- }
- if (transform) {
- if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0)
- snprintf(translated, rsize, "lib%s" DSO_ext, filename);
- else
- snprintf(translated, rsize, "%s" DSO_ext, filename);
- } else
- snprintf(translated, rsize, "%s", filename);
return (translated);
}