From 80460fd691fbc007370abefa2319ab583ab4f853 Mon Sep 17 00:00:00 2001 From: Steve Huston Date: Tue, 5 Aug 2014 20:02:12 +0000 Subject: ChangeLogTag:Tue Aug 5 17:14:04 UTC 2014 Steve Huston --- ACE/ChangeLog | 6 ++++++ ACE/ace/Process.cpp | 18 +++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/ACE/ChangeLog b/ACE/ChangeLog index cc7b0789194..24383398046 100644 --- a/ACE/ChangeLog +++ b/ACE/ChangeLog @@ -1,3 +1,9 @@ +Tue Aug 5 17:14:04 UTC 2014 Steve Huston + + * ace/Process.cpp (setenv): Correctly re-process variable arg list if + first attempt at formatting the value(s) fails due to lack of + space. Fixes Bugzilla 4175. + Thu Jun 5 14:24:58 UTC 2014 Steve Huston * include/makeinclude/platform_aix_ibm.GNU: Add XL C++ 12.1 to the diff --git a/ACE/ace/Process.cpp b/ACE/ace/Process.cpp index 6b3dfb6f00f..0b41e371af3 100644 --- a/ACE/ace/Process.cpp +++ b/ACE/ace/Process.cpp @@ -1000,10 +1000,6 @@ ACE_Process_Options::setenv (const ACE_TCHAR *variable_name, variable_name, format); - // Start varargs. - va_list argp; - va_start (argp, format); - // Add the rest of the varargs. size_t tmp_buflen = buflen; if (DEFAULT_COMMAND_LINE_BUF_LEN > buflen) @@ -1018,7 +1014,15 @@ ACE_Process_Options::setenv (const ACE_TCHAR *variable_name, do { + // Must restart varargs on each time through this loop, + va_list argp; + va_start (argp, format); + retval = ACE_OS::vsnprintf (safe_stack_buf.get (), tmp_buflen, safe_newformat.get (), argp); + + // End varargs. + va_end (argp); + if (retval > ACE_Utils::truncate_cast (tmp_buflen)) { tmp_buflen *= 2; @@ -1040,7 +1044,10 @@ ACE_Process_Options::setenv (const ACE_TCHAR *variable_name, // ALERT: Since we have to use vsprintf here, there is still a chance that // the stack_buf overflows, i.e., the length of the resulting string // can still possibly go beyond the allocated stack_buf. + va_list argp; + va_start (argp, format); retval = ACE_OS::vsprintf (safe_stack_buf.get (), safe_newformat.get (), argp); + va_end (argp); if (retval == -1) // vsprintf is failed. return -1; @@ -1050,9 +1057,6 @@ ACE_Process_Options::setenv (const ACE_TCHAR *variable_name, return -1; } - // End varargs. - va_end (argp); - // Append the string to our environment buffer. if (this->setenv_i (safe_stack_buf.get (), ACE_OS::strlen (safe_stack_buf.get ())) == -1) -- cgit v1.2.1