From 57a5a0095c3fe0f22dcbb9d99a82cc94f2b608c7 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Sun, 17 Jan 2016 14:30:53 -0800 Subject: Update to rra-c-util 5.10 and C TAP Harness 3.4 Update to rra-c-util 5.10: * Add missing va_end to xasprintf implementation. * Fix Perl test suite framework for new Automake relative paths. * Improve portability to Kerberos included in Solaris 10. * Use appropriate warning flags with Clang (currently not warning clean). Update to C TAP Harness 3.4: * Fix segfault in runtests with an empty test list. * Display verbose test results with -v or C_TAP_VERBOSE. * Test infrastructure builds cleanly with Clang warnings. * Support comments and blank lines in test lists. --- portable/setenv.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'portable/setenv.c') diff --git a/portable/setenv.c b/portable/setenv.c index 472282a..f1f6db4 100644 --- a/portable/setenv.c +++ b/portable/setenv.c @@ -26,6 +26,7 @@ * the system version. */ #if TESTING +# undef setenv # define setenv test_setenv int test_setenv(const char *, const char *, int); #endif @@ -34,29 +35,22 @@ int setenv(const char *name, const char *value, int overwrite) { char *envstring; - size_t size; + /* Do nothing if not overwriting and the variable is already set. */ if (!overwrite && getenv(name) != NULL) return 0; - /* - * Allocate memory for the environment string. We intentionally don't use - * the xmalloc family of allocation routines here, since the intention is - * to provide a replacement for the standard library function that sets - * errno and returns in the event of a memory allocation failure. - */ - size = strlen(name) + 1 + strlen(value) + 1; - envstring = malloc(size); - if (envstring == NULL) - return -1; - /* * Build the environment string and add it to the environment using * putenv. Systems without putenv lose, but XPG4 requires it. + * + * We intentionally don't use the xmalloc family of allocation routines + * here, since the intention is to provide a replacement for the standard + * library function that sets errno and returns in the event of a memory + * allocation failure. */ - strlcpy(envstring, name, size); - strlcat(envstring, "=", size); - strlcat(envstring, value, size); + if (asprintf(&envstring, "%s=%s", name, value) < 0) + return -1; return putenv(envstring); /* -- cgit v1.2.3