diff options
author | Sebastian Benoit <benno@cvs.openbsd.org> | 2019-03-09 10:11:54 +0000 |
---|---|---|
committer | Sebastian Benoit <benno@cvs.openbsd.org> | 2019-03-09 10:11:54 +0000 |
commit | 270e3fb2b72f0d9443ad0ca6bddcb5fd684e3aee (patch) | |
tree | 65ed5539fde38f0250f46e6e1f14297230d1b303 /usr.sbin | |
parent | b9e0ee2fedbb14ed48872cb4a7cfd9d744777730 (diff) |
use temporary strings for calls to basename(), because it may change
the contents of its argument (on other platforms). Also strdup() the result,
because basename returns a pointer to static memory.
ok florian@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/acme-client/main.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/usr.sbin/acme-client/main.c b/usr.sbin/acme-client/main.c index b1cf7ac00d1..564290e6720 100644 --- a/usr.sbin/acme-client/main.c +++ b/usr.sbin/acme-client/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.43 2019/03/08 18:42:44 benno Exp $ */ +/* $Id: main.c,v 1.44 2019/03/09 10:11:53 benno Exp $ */ /* * Copyright (c) 2016 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -113,29 +113,33 @@ main(int argc, char *argv[]) if ((certdir = strdup(tmpsd)) == NULL) err(EXIT_FAILURE, "strdup"); free(tmps); + tmps = tmpsd = NULL; if (domain->cert != NULL) { - if ((certfile = basename(domain->cert)) != NULL) { - if ((certfile = strdup(certfile)) == NULL) - err(EXIT_FAILURE, "strdup"); - } else + if ((tmps = strdup(domain->cert)) == NULL) + err(EXIT_FAILURE, "strdup"); + if ((certfile = basename(tmps)) == NULL) err(EXIT_FAILURE, "basename"); + if ((certfile = strdup(certfile)) == NULL) + err(EXIT_FAILURE, "strdup"); } if (domain->chain != NULL) { - if ((chainfile = basename(domain->chain)) != NULL) { - if ((chainfile = strdup(chainfile)) == NULL) - err(EXIT_FAILURE, "strdup"); - } else + if ((tmps = strdup(domain->chain)) == NULL) + err(EXIT_FAILURE, "strdup"); + if ((chainfile = basename(tmps)) == NULL) err(EXIT_FAILURE, "basename"); + if ((chainfile = strdup(chainfile)) == NULL) + err(EXIT_FAILURE, "strdup"); } if (domain->fullchain != NULL) { - if ((fullchainfile = basename(domain->fullchain)) != NULL) { - if ((fullchainfile = strdup(fullchainfile)) == NULL) - err(EXIT_FAILURE, "strdup"); - } else + if ((tmps = strdup(domain->fullchain)) == NULL) + err(EXIT_FAILURE, "strdup"); + if ((fullchainfile = basename(tmps)) == NULL) err(EXIT_FAILURE, "basename"); + if ((fullchainfile = strdup(fullchainfile)) == NULL) + err(EXIT_FAILURE, "strdup"); } if ((auth = domain->auth) == NULL) { @@ -419,6 +423,9 @@ main(int argc, char *argv[]) free(certdir); free(alts); + free(certfile); + free(chainfile); + free(fullchainfile); return rc != COMP__MAX ? EXIT_FAILURE : (c == 2 ? EXIT_SUCCESS : 2); usage: fprintf(stderr, |