From a33cf7cd35bb9735823fa1276617c38edbd8b385 Mon Sep 17 00:00:00 2001 From: Adam Mitz Date: Thu, 22 Sep 2022 17:58:28 -0500 Subject: Merge pull request #1907 from lukem/format-security Fix -Wformat-security issues (cherry picked from commit 0b7e12778ae92315cbd51c901cb8402d6bd646a7) # Conflicts: # ACE/websvcs/lib/URL_Addr.cpp --- ACE/ace/ACE.cpp | 12 +----- ACE/ace/INET_Addr.cpp | 12 +----- ACE/ace/Log_Msg.cpp | 45 ++++------------------ ACE/ace/Log_Record.cpp | 27 ++++--------- ACE/ace/Process.cpp | 9 +---- ACE/ace/ace_wchar.h | 6 +++ ACE/docs/ACE-guidelines.html | 8 ++++ .../Event_Server/Event_Server/Consumer_Router.cpp | 11 +++--- .../Event_Server/Event_Server/Supplier_Router.cpp | 11 +++--- .../ASX/UPIPE_Event_Server/Consumer_Router.cpp | 11 ++---- .../ASX/UPIPE_Event_Server/Supplier_Router.cpp | 11 ++---- ACE/examples/OS/Process/process.cpp | 25 ++---------- ACE/tests/MEM_Stream_Test.cpp | 14 +------ ACE/tests/Malloc_Test.cpp | 10 ++--- ACE/tests/Naming_Test.cpp | 6 +-- ACE/tests/Pipe_Test.cpp | 8 +--- ACE/tests/Process_Manager_Test.cpp | 2 +- ACE/tests/Process_Mutex_Test.cpp | 12 ++---- ACE/tests/Process_Test.cpp | 8 +--- ACE/tests/RW_Process_Mutex_Test.cpp | 10 +---- ACE/tests/Time_Service_Test.cpp | 4 +- ACE/tests/test_config.h | 10 ++--- ACE/websvcs/lib/URL_Addr.cpp | 34 ++++++---------- .../Factory_Service/EventChannelFactory_i.cpp | 8 ++-- TAO/orbsvcs/ImplRepo_Service/ImR_Activator_i.cpp | 6 +-- TAO/orbsvcs/tests/HTIOP/test_config.h | 10 ++--- 26 files changed, 105 insertions(+), 225 deletions(-) diff --git a/ACE/ace/ACE.cpp b/ACE/ace/ACE.cpp index 0ff5080d688..a4379dec41e 100644 --- a/ACE/ace/ACE.cpp +++ b/ACE/ace/ACE.cpp @@ -2343,11 +2343,7 @@ ACE::format_hexdump (const char *buffer, textver[j] = 0; ACE_OS::snprintf (obuf, obuf_sz - (obuf - obuf_start), -#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) - ACE_TEXT (" %ls\n"), -#else - ACE_TEXT (" %s\n"), -#endif + ACE_TEXT (" %") ACE_TEXT_PRIs ACE_TEXT ("\n"), textver); while (*obuf != '\0') @@ -2384,11 +2380,7 @@ ACE::format_hexdump (const char *buffer, textver[i] = 0; ACE_OS::snprintf (obuf, obuf_sz - (obuf - obuf_start), -#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) - ACE_TEXT (" %ls\n"), -#else - ACE_TEXT (" %s\n"), -#endif + ACE_TEXT (" %") ACE_TEXT_PRIs ACE_TEXT ("\n"), textver); } return size; diff --git a/ACE/ace/INET_Addr.cpp b/ACE/ace/INET_Addr.cpp index 70eedf9f954..d5cc97cfc81 100644 --- a/ACE/ace/INET_Addr.cpp +++ b/ACE/ace/INET_Addr.cpp @@ -50,20 +50,12 @@ ACE_INET_Addr::addr_to_string (ACE_TCHAR s[], + 5 // ACE_OS::strlen ("65535"), Assuming the max port number. + 1 // sizeof (':'), addr/port sep + 1; // sizeof ('\0'), terminating NUL -#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) - ACE_TCHAR const *format = ACE_TEXT("%ls:%d"); -#else - ACE_TCHAR const *format = ACE_TEXT("%s:%d"); -#endif /* !ACE_WIN32 && ACE_USES_WCHAR */ + ACE_TCHAR const *format = ACE_TEXT("%") ACE_TEXT_PRIs ACE_TEXT(":%d"); #if defined (ACE_HAS_IPV6) if (ACE_OS::strchr (hoststr, ACE_TEXT (':')) != 0) { total_len += 2; // ACE_OS::strlen ("[]") IPv6 addr frames -# if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) - format = ACE_TEXT("[%ls]:%d"); -# else - format = ACE_TEXT("[%s]:%d"); -# endif /* !ACE_WIN32 && ACE_USES_WCHAR */ + format = ACE_TEXT("[%") ACE_TEXT_PRIs ACE_TEXT("]:%d"); } #endif // ACE_HAS_IPV6 diff --git a/ACE/ace/Log_Msg.cpp b/ACE/ace/Log_Msg.cpp index dbf09f5d3da..2490004c2f4 100644 --- a/ACE/ace/Log_Msg.cpp +++ b/ACE/ace/Log_Msg.cpp @@ -1241,11 +1241,7 @@ ACE_Log_Msg::log (const ACE_TCHAR *format_str, break; case 'N': // Source file name -#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) - ACE_OS::strcpy (fp, ACE_TEXT ("ls")); -#else - ACE_OS::strcpy (fp, ACE_TEXT ("s")); -#endif + ACE_OS::strcpy (fp, ACE_TEXT_PRIs); if (can_check) this_len = ACE_OS::snprintf (bp, bspace, format, this->file () ? @@ -1260,11 +1256,7 @@ ACE_Log_Msg::log (const ACE_TCHAR *format_str, break; case 'n': // Program name -#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) - ACE_OS::strcpy (fp, ACE_TEXT ("ls")); -#else /* ACE_WIN32 && ACE_USES_WCHAR */ - ACE_OS::strcpy (fp, ACE_TEXT ("s")); -#endif + ACE_OS::strcpy (fp, ACE_TEXT_PRIs); if (can_check) this_len = ACE_OS::snprintf (bp, bspace, format, ACE_Log_Msg::program_name_ ? @@ -1504,11 +1496,7 @@ ACE_Log_Msg::log (const ACE_TCHAR *format_str, { // Nope, print out standard priority_name() string -#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) - ACE_OS::strcpy (fp, ACE_TEXT ("ls")); -#else - ACE_OS::strcpy (fp, ACE_TEXT ("s")); -#endif + ACE_OS::strcpy (fp, ACE_TEXT_PRIs); if (can_check) this_len = ACE_OS::snprintf (bp, bspace, format, @@ -1538,11 +1526,7 @@ ACE_Log_Msg::log (const ACE_TCHAR *format_str, { #endif -#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) - ACE_OS::strcpy (fp, ACE_TEXT ("ls")); -#else /* ACE_WIN32 && ACE_USES_WCHAR */ - ACE_OS::strcpy (fp, ACE_TEXT ("s")); -#endif + ACE_OS::strcpy (fp, ACE_TEXT_PRIs); if (can_check) this_len = ACE_OS::snprintf (bp, bspace, format, ACE_TEXT_CHAR_TO_TCHAR (msg)); @@ -1722,11 +1706,7 @@ ACE_Log_Msg::log (const ACE_TCHAR *format_str, sizeof (day_and_time) / sizeof (ACE_TCHAR), true); } -#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) - ACE_OS::strcpy (fp, ACE_TEXT ("ls")); -#else - ACE_OS::strcpy (fp, ACE_TEXT ("s")); -#endif + ACE_OS::strcpy (fp, ACE_TEXT_PRIs); if (can_check) this_len = ACE_OS::snprintf (bp, bspace, format, day_and_time); @@ -1740,11 +1720,7 @@ ACE_Log_Msg::log (const ACE_TCHAR *format_str, // hour:minute:sec.usec format. { ACE_TCHAR day_and_time[27]; -#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) - ACE_OS::strcpy (fp, ACE_TEXT ("ls")); -#else - ACE_OS::strcpy (fp, ACE_TEXT ("s")); -#endif + ACE_OS::strcpy (fp, ACE_TEXT_PRIs); // Did we find the flag indicating a time value argument if (format[1] == ACE_TEXT('#')) { @@ -1819,11 +1795,10 @@ ACE_Log_Msg::log (const ACE_TCHAR *format_str, { #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) wchar_t *str = va_arg (argp, wchar_t *); - ACE_OS::strcpy (fp, ACE_TEXT ("ls")); #else /* ACE_WIN32 && ACE_USES_WCHAR */ ACE_TCHAR *str = va_arg (argp, ACE_TCHAR *); - ACE_OS::strcpy (fp, ACE_TEXT ("s")); #endif /* ACE_WIN32 && ACE_USES_WCHAR */ + ACE_OS::strcpy (fp, ACE_TEXT_PRIs); if (can_check) this_len = ACE_OS::snprintf (bp, bspace, format, str ? str : ACE_TEXT ("(null)")); @@ -2977,11 +2952,7 @@ ACE_Log_Msg::log_hexdump (ACE_Log_Priority log_priority, if (text) wr_ptr += ACE_OS::snprintf (wr_ptr, end_ptr - wr_ptr, -#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) - ACE_TEXT ("%ls - "), -#else - ACE_TEXT ("%s - "), -#endif + ACE_TEXT ("%") ACE_TEXT_PRIs ACE_TEXT (" - "), text); wr_ptr += ACE_OS::snprintf (wr_ptr, diff --git a/ACE/ace/Log_Record.cpp b/ACE/ace/Log_Record.cpp index 68c4ef78a1d..603101a154d 100644 --- a/ACE/ace/Log_Record.cpp +++ b/ACE/ace/Log_Record.cpp @@ -235,16 +235,6 @@ ACE_Log_Record::format_msg (const ACE_TCHAR host_name[], /* yyyy-mm-dd hh:mm:ss.mmmmmm */ ACE_TCHAR timestamp[27]; // Only used by VERBOSE and VERBOSE_LITE. - // The sprintf format needs to be different for Windows and POSIX - // in the wide-char case. -#if defined (ACE_WIN32) || !defined (ACE_USES_WCHAR) - const ACE_TCHAR *verbose_fmt = ACE_TEXT ("%s@%s@%u@%s@%s"); - const ACE_TCHAR *verbose_lite_fmt = ACE_TEXT ("%s@%s@%s"); -#else - const ACE_TCHAR *verbose_fmt = ACE_TEXT ("%ls@%ls@%u@%ls@%ls"); - const ACE_TCHAR *verbose_lite_fmt = ACE_TEXT ("%ls@%ls@%ls"); -#endif - if (ACE_BIT_ENABLED (verbose_flag, ACE_Log_Msg::VERBOSE) || ACE_BIT_ENABLED (verbose_flag, @@ -269,7 +259,10 @@ ACE_Log_Record::format_msg (const ACE_TCHAR host_name[], ? ACE_TEXT ("") : host_name); ACE_OS::snprintf (verbose_msg, verbose_msg_size, - verbose_fmt, + ACE_TEXT ("%") ACE_TEXT_PRIs + ACE_TEXT ("@%") ACE_TEXT_PRIs + ACE_TEXT ("@%u@%") ACE_TEXT_PRIs + ACE_TEXT ("@%") ACE_TEXT_PRIs, timestamp, lhost_name, this->pid_, @@ -278,7 +271,9 @@ ACE_Log_Record::format_msg (const ACE_TCHAR host_name[], } else if (ACE_BIT_ENABLED (verbose_flag, ACE_Log_Msg::VERBOSE_LITE)) ACE_OS::snprintf (verbose_msg, verbose_msg_size, - verbose_lite_fmt, + ACE_TEXT ("%") ACE_TEXT_PRIs + ACE_TEXT ("@%") ACE_TEXT_PRIs + ACE_TEXT ("@%") ACE_TEXT_PRIs, timestamp, ACE_Log_Record::priority_name (ACE_Log_Priority (this->type_)), this->msg_data_); @@ -318,15 +313,9 @@ ACE_Log_Record::print (const ACE_TCHAR host_name[], { int const verbose_msg_len = static_cast (ACE_OS::strlen (verbose_msg)); -#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) - int const fwrite_result = ACE_OS::fprintf (fp, - ACE_TEXT ("%ls"), - verbose_msg); -#else int const fwrite_result = ACE_OS::fprintf (fp, - ACE_TEXT ("%s"), + ACE_TEXT ("%") ACE_TEXT_PRIs, verbose_msg); -#endif // We should have written everything if (fwrite_result != verbose_msg_len) result = -1; diff --git a/ACE/ace/Process.cpp b/ACE/ace/Process.cpp index ea1c4f10c9c..a1921102960 100644 --- a/ACE/ace/Process.cpp +++ b/ACE/ace/Process.cpp @@ -1041,14 +1041,9 @@ ACE_Process_Options::setenv (const ACE_TCHAR *variable_name, ACE_NEW_RETURN (newformat, ACE_TCHAR[buflen], -1); ACE_Auto_Basic_Array_Ptr safe_newformat (newformat); -# if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) - const ACE_TCHAR *fmt = ACE_TEXT ("%ls=%ls"); -# else - const ACE_TCHAR *fmt = ACE_TEXT ("%s=%s"); -# endif - // Add in the variable name. - ACE_OS::snprintf (safe_newformat.get (), buflen, fmt, + ACE_OS::snprintf (safe_newformat.get (), buflen, + ACE_TEXT ("%") ACE_TEXT_PRIs ACE_TEXT ("=%") ACE_TEXT_PRIs, variable_name, format); // Add the rest of the varargs. diff --git a/ACE/ace/ace_wchar.h b/ACE/ace/ace_wchar.h index 7afc673328b..37197c1c968 100644 --- a/ACE/ace/ace_wchar.h +++ b/ACE/ace/ace_wchar.h @@ -94,6 +94,11 @@ typedef char ACE_ANTI_TCHAR; # define ACE_TEXT_CHAR_TO_TCHAR(STRING) ACE_Ascii_To_Wide (STRING).wchar_rep () # define ACE_TEXT_WCHAR_TO_TCHAR(STRING) STRING # define ACE_TEXT_ANTI_TO_TCHAR(STRING) ACE_Ascii_To_Wide (STRING).wchar_rep () +# if !defined (ACE_WIN32) +# define ACE_TEXT_PRIs ACE_TEXT("ls") +# else +# define ACE_TEXT_PRIs ACE_TEXT("s") +# endif #else /* ACE_USES_WCHAR */ typedef char ACE_TCHAR; typedef wchar_t ACE_ANTI_TCHAR; @@ -103,6 +108,7 @@ typedef wchar_t ACE_ANTI_TCHAR; # define ACE_TEXT_CHAR_TO_TCHAR(STRING) STRING # define ACE_TEXT_WCHAR_TO_TCHAR(STRING) ACE_Wide_To_Ascii (STRING).char_rep () # define ACE_TEXT_ANTI_TO_TCHAR(STRING) ACE_Wide_To_Ascii (STRING).char_rep () +# define ACE_TEXT_PRIs ACE_TEXT("s") #endif /* ACE_USES_WCHAR */ // The OS_String module defines some wide-char functions that are not diff --git a/ACE/docs/ACE-guidelines.html b/ACE/docs/ACE-guidelines.html index 26d1b6062c2..45bd3672ab4 100644 --- a/ACE/docs/ACE-guidelines.html +++ b/ACE/docs/ACE-guidelines.html @@ -830,6 +830,14 @@ Foo::bar ()
  • Do not use the Win32 TCHAR macros. The wide character-ness of ACE is separate from UNICODE and _UNICODE. +
  • If you have a printf-like format specifier that + uses %s to format a string, certain WCHAR implementations + require %ls instead. + The macro ACE_TEXT_PRIs contains "s" or "ls" + depending upon the WCHAR implementation, and may be used as + ACE_TEXT("%") ACE_TEXT_PRI_s, where the first argument may also + contain flags and width specifiers. +
  • For TAO, don't use ACE_TCHAR or ACE_TEXT. The CORBA specification defines APIs as using char. So most of the time there is no need to use wide characters. diff --git a/ACE/examples/ASX/Event_Server/Event_Server/Consumer_Router.cpp b/ACE/examples/ASX/Event_Server/Event_Server/Consumer_Router.cpp index 8a74e8039b4..3cafe8d1149 100644 --- a/ACE/examples/ASX/Event_Server/Event_Server/Consumer_Router.cpp +++ b/ACE/examples/ASX/Event_Server/Event_Server/Consumer_Router.cpp @@ -125,11 +125,6 @@ Consumer_Router::put (ACE_Message_Block *mb, } // Return information about the . -#if defined (ACE_WIN32) || !defined (ACE_USES_WCHAR) -# define FMTSTR ACE_TEXT ("%s\t %d/%s %s (%s)\n") -#else -# define FMTSTR ACE_TEXT ("%ls\t %d/%ls %ls (%ls)\n") -#endif /* ACE_WIN32 || !ACE_USES_WCHAR */ int Consumer_Router::info (ACE_TCHAR **strp, size_t length) const @@ -142,7 +137,11 @@ Consumer_Router::info (ACE_TCHAR **strp, size_t length) const return -1; ACE_OS::sprintf (buf, - FMTSTR, + ACE_TEXT ("%") ACE_TEXT_PRIs + ACE_TEXT ("\t %d/%") ACE_TEXT_PRIs + ACE_TEXT (" %") ACE_TEXT_PRIs + ACE_TEXT (" (%") ACE_TEXT_PRIs + ACE_TEXT (")\n"), module_name, addr.get_port_number (), ACE_TEXT ("tcp"), diff --git a/ACE/examples/ASX/Event_Server/Event_Server/Supplier_Router.cpp b/ACE/examples/ASX/Event_Server/Event_Server/Supplier_Router.cpp index 81e20cfc3c7..68ac0b56e6c 100644 --- a/ACE/examples/ASX/Event_Server/Event_Server/Supplier_Router.cpp +++ b/ACE/examples/ASX/Event_Server/Event_Server/Supplier_Router.cpp @@ -131,11 +131,6 @@ Supplier_Router::put (ACE_Message_Block *mb, } // Return information about the . -#if defined (ACE_WIN32) || !defined (ACE_USES_WCHAR) -# define FMTSTR ACE_TEXT ("%s\t %d/%s %s (%s)\n") -#else -# define FMTSTR ACE_TEXT ("%ls\t %d/%ls %ls (%ls)\n") -#endif /* ACE_WIN32 || !ACE_USES_WCHAR */ int Supplier_Router::info (ACE_TCHAR **strp, size_t length) const @@ -148,7 +143,11 @@ Supplier_Router::info (ACE_TCHAR **strp, size_t length) const return -1; ACE_OS::sprintf (buf, - FMTSTR, + ACE_TEXT ("%") ACE_TEXT_PRIs + ACE_TEXT ("\t %d/%") ACE_TEXT_PRIs + ACE_TEXT (" %") ACE_TEXT_PRIs + ACE_TEXT (" (%") ACE_TEXT_PRIs + ACE_TEXT (")\n"), module_name, addr.get_port_number (), ACE_TEXT ("tcp"), diff --git a/ACE/examples/ASX/UPIPE_Event_Server/Consumer_Router.cpp b/ACE/examples/ASX/UPIPE_Event_Server/Consumer_Router.cpp index 153fbd557e4..75755e7d538 100644 --- a/ACE/examples/ASX/UPIPE_Event_Server/Consumer_Router.cpp +++ b/ACE/examples/ASX/UPIPE_Event_Server/Consumer_Router.cpp @@ -117,13 +117,10 @@ Consumer_Router::info (ACE_TCHAR **strp, size_t length) const if (sa.get_local_addr (addr) == -1) return -1; -#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) -# define FMTSTR ACE_TEXT ("%ls\t %ls/ %ls") -#else -# define FMTSTR ACE_TEXT ("%s\t %s/ %s") -#endif - - ACE_OS::sprintf (buf, FMTSTR, + ACE_OS::sprintf (buf, + ACE_TEXT ("%") ACE_TEXT_PRIs + ACE_TEXT ("\t %") ACE_TEXT_PRIs + ACE_TEXT ("/ %") ACE_TEXT_PRIs, module_name, ACE_TEXT ("upipe"), ACE_TEXT ("# consumer router\n")); diff --git a/ACE/examples/ASX/UPIPE_Event_Server/Supplier_Router.cpp b/ACE/examples/ASX/UPIPE_Event_Server/Supplier_Router.cpp index f372147bf67..9eaa54699a4 100644 --- a/ACE/examples/ASX/UPIPE_Event_Server/Supplier_Router.cpp +++ b/ACE/examples/ASX/UPIPE_Event_Server/Supplier_Router.cpp @@ -116,13 +116,10 @@ Supplier_Router::info (ACE_TCHAR **strp, size_t length) const if (sa.get_local_addr (addr) == -1) return -1; -#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) -# define FMTSTR ACE_TEXT ("%ls\t %ls/ %ls") -#else -# define FMTSTR ACE_TEXT ("%s\t %s/ %s") -#endif - - ACE_OS::sprintf (buf, FMTSTR, + ACE_OS::sprintf (buf, + ACE_TEXT ("%") ACE_TEXT_PRIs + ACE_TEXT ("\t %") ACE_TEXT_PRIs + ACE_TEXT ("/ %") ACE_TEXT_PRIs, module_name, ACE_TEXT ("upipe"), ACE_TEXT ("# supplier router\n")); diff --git a/ACE/examples/OS/Process/process.cpp b/ACE/examples/OS/Process/process.cpp index 17e27597fa4..fa411cbc00b 100644 --- a/ACE/examples/OS/Process/process.cpp +++ b/ACE/examples/OS/Process/process.cpp @@ -181,11 +181,7 @@ static void test_ls (void) { ACE_Process_Options options; -#if defined (ACE_WIN32) || !defined (ACE_USES_WCHAR) - options.command_line (ACE_TEXT ("%s -al"), LS_PATH); -#else - options.command_line (ACE_TEXT ("%ls -al"), LS_PATH); -#endif + options.command_line (ACE_TEXT ("%") ACE_TEXT_PRIs ACE_TEXT (" -al"), LS_PATH); ACE_Process new_process; if (new_process.spawn (options) == -1) { @@ -207,11 +203,7 @@ static void test_wait (void) { ACE_Process_Options options; -#if defined (ACE_WIN32) || !defined (ACE_USES_WCHAR) - options.command_line (ACE_TEXT ("%s 10"), SLEEP_PATH); -#else - options.command_line (ACE_TEXT ("%ls 10"), SLEEP_PATH); -#endif + options.command_line (ACE_TEXT ("%") ACE_TEXT_PRIs ACE_TEXT (" 10"), SLEEP_PATH); ACE_Process process1; if (process1.spawn (options) == -1) { @@ -466,11 +458,7 @@ test_setenv (const ACE_TCHAR *argv0) options.setenv (ACE_TEXT ("ACE_PROCESS_TEST= here's a large number %u"), 0 - 1); options.setenv (ACE_TEXT ("ACE_PROCESS_TEST2"), ACE_TEXT ("ophilli")); -#if defined (ACE_WIN32) || !defined (ACE_USES_WCHAR) - options.command_line ("%s -g", argv0); -#else - options.command_line ("%ls -g", argv0); -#endif + options.command_line (ACE_TEXT ("%") ACE_TEXT_PRIs ACE_TEXT (" -g", argv0); ACE_Process process; if (process.spawn (options) == -1) { @@ -522,13 +510,8 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[]) if (run_all) { -#if defined (ACE_WIN32) || !defined (ACE_USES_WCHAR) - const ACE_TCHAR *cmdline = ACE_TEXT ("%s -d -l -s -w"); -#else - const ACE_TCHAR *cmdline = ACE_TEXT ("%ls -d -l -s -w"); -#endif ACE_Process_Options options; - options.command_line (cmdline, argv[0]); + options.command_line (ACE_TEXT ("%") ACE_TEXT_PRIs ACE_TEXT (" -d -l -s -w"), argv[0]); ACE_Process process; if (process.spawn (options) == -1) ACE_ERROR_RETURN ((LM_ERROR, diff --git a/ACE/tests/MEM_Stream_Test.cpp b/ACE/tests/MEM_Stream_Test.cpp index 0819d766df4..940e0dd4088 100644 --- a/ACE/tests/MEM_Stream_Test.cpp +++ b/ACE/tests/MEM_Stream_Test.cpp @@ -281,12 +281,7 @@ test_reactive (const ACE_TCHAR *prog, ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("spawn_n ()"))); #else ACE_Process_Options opts; -# if defined (ACE_WIN32) || !defined (ACE_USES_WCHAR) - const ACE_TCHAR *cmdline_fmt = ACE_TEXT ("%s -p%d -r"); -# else - const ACE_TCHAR *cmdline_fmt = ACE_TEXT ("%ls -p%d -r"); -# endif /* ACE_WIN32 || !ACE_USES_WCHAR */ - opts.command_line (cmdline_fmt, prog, sport); + opts.command_line (ACE_TEXT ("%") ACE_TEXT_PRIs ACE_TEXT (" -p%d -r"), prog, sport); if (ACE_Process_Manager::instance ()->spawn_n (NUMBER_OF_REACTIVE_CONNECTIONS, opts) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("spawn_n ()"))); @@ -372,12 +367,7 @@ test_concurrent (const ACE_TCHAR *prog, ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("spawn_n()"))); #else ACE_Process_Options opts; -# if defined (ACE_WIN32) || !defined (ACE_USES_WCHAR) - const ACE_TCHAR *cmdline_fmt = ACE_TEXT ("%s -p%d -m"); -# else - const ACE_TCHAR *cmdline_fmt = ACE_TEXT ("%ls -p%d -m"); -# endif /* ACE_WIN32 || !ACE_USES_WCHAR */ - opts.command_line (cmdline_fmt, prog, sport); + opts.command_line (ACE_TEXT ("%") ACE_TEXT_PRIs ACE_TEXT (" -p%d -m"), prog, sport); if (ACE_Process_Manager::instance ()->spawn_n (NUMBER_OF_MT_CONNECTIONS, opts) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("spawn_n()"))); diff --git a/ACE/tests/Malloc_Test.cpp b/ACE/tests/Malloc_Test.cpp index 02b6854d416..d8bd50fe7f4 100644 --- a/ACE/tests/Malloc_Test.cpp +++ b/ACE/tests/Malloc_Test.cpp @@ -358,12 +358,10 @@ run_main (int argc, ACE_TCHAR *argv[]) // No arguments means we're the parent process. ACE_Process_Options options (1); -#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) - static const ACE_TCHAR* format = ACE_TEXT ("%ls%ls%ls"); -#else - static const ACE_TCHAR* format = ACE_TEXT ("%s%s%s"); -#endif /* !ACE_WIN32 && ACE_USES_WCHAR */ - options.command_line (format, EXE_LOCATION, + options.command_line (ACE_TEXT ("%") ACE_TEXT_PRIs + ACE_TEXT ("%") ACE_TEXT_PRIs + ACE_TEXT ("%") ACE_TEXT_PRIs, + EXE_LOCATION, argc > 0 ? argv[0] : ACE_TEXT ("Malloc_Test"), ACE_TEXT (" run_as_test")); diff --git a/ACE/tests/Naming_Test.cpp b/ACE/tests/Naming_Test.cpp index 42a825ed381..c171a74aa70 100644 --- a/ACE/tests/Naming_Test.cpp +++ b/ACE/tests/Naming_Test.cpp @@ -259,11 +259,7 @@ run_main (int argc, ACE_TCHAR *argv[]) } // Set the database name using the pid. mktemp isn't always available. ACE_OS::snprintf(temp_file, BUFSIZ, -#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) - ACE_TEXT ("%ls%d"), -#else - ACE_TEXT ("%s%d"), -#endif + ACE_TEXT ("%") ACE_TEXT_PRIs ACE_TEXT ("%d"), pname, (int)(ACE_OS::getpid ())); diff --git a/ACE/tests/Pipe_Test.cpp b/ACE/tests/Pipe_Test.cpp index b98d33d37e3..026619e1be1 100644 --- a/ACE/tests/Pipe_Test.cpp +++ b/ACE/tests/Pipe_Test.cpp @@ -113,14 +113,10 @@ run_main (int argc, ACE_TCHAR *argv[]) ACE_START_TEST (ACE_TEXT("Pipe_Test")); ACE_INIT_LOG (ACE_TEXT("Pipe_Test-children")); -# if defined (ACE_WIN32) || !defined (ACE_USES_WCHAR) - const ACE_TCHAR *cmdline_fmt = ACE_TEXT ("%s -c%s"); -# else - const ACE_TCHAR *cmdline_fmt = ACE_TEXT ("%ls -c%ls"); -# endif /* ACE_WIN32 || !ACE_USES_WCHAR */ ACE_Process_Options options; # ifndef ACE_LACKS_VA_FUNCTIONS - options.command_line (cmdline_fmt, + options.command_line (ACE_TEXT ("%") ACE_TEXT_PRIs + ACE_TEXT (" -c%") ACE_TEXT_PRIs, argc > 0 ? argv[0] : ACE_TEXT ("Pipe_Test"), close_pipe == 0 ? ACE_TEXT (" -d") : ACE_TEXT ("")); # else diff --git a/ACE/tests/Process_Manager_Test.cpp b/ACE/tests/Process_Manager_Test.cpp index d08152588d6..334c8c1e751 100644 --- a/ACE/tests/Process_Manager_Test.cpp +++ b/ACE/tests/Process_Manager_Test.cpp @@ -241,7 +241,7 @@ command_line_test (void) ACE_Process_Options options (1, command_len + 1); #ifndef ACE_LACKS_VA_FUNCTIONS - options.command_line (command); + options.command_line (ACE_TEXT ("%") ACE_TEXT_PRIs, command); #endif ACE_TCHAR * const *procargv = options.command_line_argv (); diff --git a/ACE/tests/Process_Mutex_Test.cpp b/ACE/tests/Process_Mutex_Test.cpp index 74d9aa65663..82beb03f78b 100644 --- a/ACE/tests/Process_Mutex_Test.cpp +++ b/ACE/tests/Process_Mutex_Test.cpp @@ -146,18 +146,14 @@ run_main (int argc, ACE_TCHAR *argv[]) ACE_Process_Mutex mutex( mutex_name ); # endif -#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) - static const ACE_TCHAR* format = ACE_TEXT ("%ls -c -n %ls%ls"); -#else - static const ACE_TCHAR* format = ACE_TEXT ("%s -c -n %s%s"); -#endif /* !ACE_WIN32 && ACE_USES_WCHAR */ ACE_Process_Options options; #ifndef ACE_LACKS_VA_FUNCTIONS - options.command_line (format, argc > 0 ? argv[0] : ACE_TEXT ("Process_Mutex_Test"), mutex_name, + options.command_line (ACE_TEXT ("%") ACE_TEXT_PRIs + ACE_TEXT (" -c -n %") ACE_TEXT_PRIs + ACE_TEXT ("%") ACE_TEXT_PRIs, + argc > 0 ? argv[0] : ACE_TEXT ("Process_Mutex_Test"), mutex_name, release_mutex == 0 ? ACE_TEXT (" -d") : ACE_TEXT ("")); -#else - ACE_UNUSED_ARG (format); #endif #ifdef ACE_HAS_PROCESS_SPAWN diff --git a/ACE/tests/Process_Test.cpp b/ACE/tests/Process_Test.cpp index 328702994b5..444f879ab1d 100644 --- a/ACE/tests/Process_Test.cpp +++ b/ACE/tests/Process_Test.cpp @@ -34,13 +34,7 @@ test_setenv (void) ACE_OS::strcat (bigval, ACE_TEXT ("01234567890123456789012345678901234567890123456789")); #ifndef ACE_LACKS_VA_FUNCTIONS -# if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) - const ACE_TCHAR *fmt = ACE_TEXT ("%ls"); -# else - const ACE_TCHAR *fmt = ACE_TEXT ("%s"); -# endif - - if (0 != opts.setenv (ACE_TEXT ("A"), fmt, bigval)) + if (0 != opts.setenv (ACE_TEXT ("A"), ACE_TEXT ("%") ACE_TEXT_PRIs, bigval)) { status = errno; ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("setenv"))); diff --git a/ACE/tests/RW_Process_Mutex_Test.cpp b/ACE/tests/RW_Process_Mutex_Test.cpp index 7c84597df70..960bdae1468 100644 --- a/ACE/tests/RW_Process_Mutex_Test.cpp +++ b/ACE/tests/RW_Process_Mutex_Test.cpp @@ -431,11 +431,6 @@ run_main (int argc, ACE_TCHAR *argv[]) mutex_name.c_str (), ACE_TEXT ("ctor"))); } -#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) - static const ACE_TCHAR* format = ACE_TEXT ("%ls -c %d -p %u -n %ls"); -#else - static const ACE_TCHAR* format = ACE_TEXT ("%s -c %d -p %u -n %s"); -#endif /* !ACE_WIN32 && ACE_USES_WCHAR */ // The parent process reads time ranges sent from the children via // UDP. Grab an unused UDP port to tell the children to send to. @@ -462,13 +457,12 @@ run_main (int argc, ACE_TCHAR *argv[]) Child *child = (i == 0 ? &writer : &readers[i-1]); ACE_Process_Options options; #ifndef ACE_LACKS_VA_FUNCTIONS - options.command_line (format, + options.command_line (ACE_TEXT ("%") ACE_TEXT_PRIs + ACE_TEXT (" -c %d -p %u -n %") ACE_TEXT_PRIs, argc > 0 ? argv[0] : ACE_TEXT ("RW_Process_Mutex_Test"), i, (unsigned int)me.get_port_number (), mutex_name.c_str ()); -#else - ACE_UNUSED_ARG (format); #endif if (child->spawn (options) == -1) { diff --git a/ACE/tests/Time_Service_Test.cpp b/ACE/tests/Time_Service_Test.cpp index f8350526b36..295d784f5f9 100644 --- a/ACE/tests/Time_Service_Test.cpp +++ b/ACE/tests/Time_Service_Test.cpp @@ -65,7 +65,7 @@ run_main (int, ACE_TCHAR *[]) const ACE_TCHAR *server_cl = APPLICATION ACE_TEXT ("server.conf"); ACE_Process_Options server_options; #ifndef ACE_LACKS_VA_FUNCTIONS - server_options.command_line (server_cl); + server_options.command_line (ACE_TEXT ("%") ACE_TEXT_PRIs, server_cl); #endif ACE_Process server; @@ -85,7 +85,7 @@ run_main (int, ACE_TCHAR *[]) const ACE_TCHAR *clerk_cl = APPLICATION ACE_TEXT ("clerk.conf"); ACE_Process_Options clerk_options; #ifndef ACE_LACKS_VA_FUNCTIONS - clerk_options.command_line (clerk_cl); + clerk_options.command_line (ACE_TEXT ("%") ACE_TEXT_PRIs, clerk_cl); #endif ACE_Process clerk; diff --git a/ACE/tests/test_config.h b/ACE/tests/test_config.h index e606f048a21..79b21ec8099 100644 --- a/ACE/tests/test_config.h +++ b/ACE/tests/test_config.h @@ -149,14 +149,12 @@ size_t const ACE_MAX_THREADS = 4; } #else /* ! VXWORKS */ -# if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) -# define ACE_INIT_LOG_FMT ACE_TEXT ("%ls%ls%ls") -# else -# define ACE_INIT_LOG_FMT ACE_TEXT ("%s%s%s") -# endif /* !ACE_WIN32 && ACE_USES_WCHAR */ #define ACE_INIT_LOG(NAME) \ ACE_TCHAR temp[MAXPATHLEN]; \ - ACE_OS::sprintf (temp, ACE_INIT_LOG_FMT, \ + ACE_OS::sprintf (temp, \ + ACE_TEXT ("%") ACE_TEXT_PRIs \ + ACE_TEXT ("%") ACE_TEXT_PRIs \ + ACE_TEXT ("%") ACE_TEXT_PRIs, \ ACE_LOG_DIRECTORY, \ ACE::basename (NAME, ACE_DIRECTORY_SEPARATOR_CHAR), \ ACE_LOG_FILE_EXT_NAME); \ diff --git a/ACE/websvcs/lib/URL_Addr.cpp b/ACE/websvcs/lib/URL_Addr.cpp index 7439bdd4f7d..325dd4ae423 100644 --- a/ACE/websvcs/lib/URL_Addr.cpp +++ b/ACE/websvcs/lib/URL_Addr.cpp @@ -41,16 +41,6 @@ static size_t tn3270_size = sizeof(tn3270)/sizeof(tn3270[0]) - 1; static ACE_TCHAR gopher[] = ACE_TEXT ("gopher:"); static size_t gopher_size = sizeof(gopher)/sizeof(gopher[0]) - 1; -// When assembling URLs, sprintf() is often used. The format specifier for -// a string changes depending on the platform and char width being fed to it. -// Since we use ACE_TCHAR for strings, and it changes with the char width, -// the printf specifier needs to change with the platform. -#if defined (ACE_WIN32) || !defined (ACE_USES_WCHAR) -# define ACE_PRINTF_S ACE_TEXT ("%s") -#else -# define ACE_PRINTF_S ACE_TEXT ("%ls") -#endif - ACE_URL_Addr::ACE_URL_Addr (void) : url_ (0) { @@ -531,11 +521,11 @@ ACE_HTTP_Addr::addr_to_string (ACE_TCHAR *buffer, if (flags == 0) { ACE_INET_Addr inet = this->get_inet_address (); - n += ACE_OS::sprintf (buffer + n, ACE_PRINTF_S, inet.get_host_addr ()); + n += ACE_OS::sprintf (buffer + n, ACE_TEXT ("%") ACE_TEXT_PRIs, inet.get_host_addr ()); } else { - n += ACE_OS::sprintf (buffer + n, ACE_PRINTF_S, this->hostname_); + n += ACE_OS::sprintf (buffer + n, ACE_TEXT ("%") ACE_TEXT_PRIs, this->hostname_); } if (this->port_number_ != ACE_DEFAULT_HTTP_PORT) @@ -545,13 +535,13 @@ ACE_HTTP_Addr::addr_to_string (ACE_TCHAR *buffer, if (this->path_ != 0) { n += ACE_OS::sprintf (buffer + n, - ACE_TEXT ("/") ACE_PRINTF_S, + ACE_TEXT ("/%") ACE_TEXT_PRIs, this->path_); } if (this->query_ != 0) { n += ACE_OS::sprintf (buffer + n, - ACE_TEXT ("?") ACE_PRINTF_S, + ACE_TEXT ("?%") ACE_TEXT_PRIs, this->query_); } return 0; @@ -704,12 +694,12 @@ ACE_FTP_Addr::addr_to_string (ACE_TCHAR *buffer, if (this->user_ != 0) { - n += ACE_OS::sprintf (buffer + n, ACE_PRINTF_S, this->user_); + n += ACE_OS::sprintf (buffer + n, ACE_TEXT ("%") ACE_TEXT_PRIs, this->user_); } if (this->password_ != 0) { n += ACE_OS::sprintf (buffer + n, - ACE_TEXT (":") ACE_PRINTF_S, + ACE_TEXT (":%") ACE_TEXT_PRIs, this->password_); } @@ -721,16 +711,16 @@ ACE_FTP_Addr::addr_to_string (ACE_TCHAR *buffer, if (flags == 0) { ACE_INET_Addr inet = this->get_inet_address (); - n += ACE_OS::sprintf (buffer + n, ACE_PRINTF_S, inet.get_host_addr ()); + n += ACE_OS::sprintf (buffer + n, ACE_TEXT ("%") ACE_TEXT_PRIs, inet.get_host_addr ()); } else { - n += ACE_OS::sprintf (buffer + n, ACE_PRINTF_S, this->hostname_); + n += ACE_OS::sprintf (buffer + n, ACE_TEXT ("%") ACE_TEXT_PRIs, this->hostname_); } if (this->path_ != 0) { n += ACE_OS::sprintf (buffer + n, - ACE_TEXT ("/") ACE_PRINTF_S, + ACE_TEXT ("/%") ACE_TEXT_PRIs, this->path_); } return 0; @@ -915,12 +905,12 @@ ACE_Mailto_Addr::addr_to_string (ACE_TCHAR *buffer, return -1; size_t n = ACE_OS::sprintf (buffer, - ACE_TEXT ("mailto:") ACE_PRINTF_S ACE_TEXT - ("@") ACE_PRINTF_S, + ACE_TEXT ("mailto:%") ACE_TEXT_PRIs + ACE_TEXT ("@%") ACE_TEXT_PRIs, this->user_, this->hostname_); if (this->headers_ != 0) { - n += ACE_OS::sprintf (buffer + n, ACE_TEXT ("?") ACE_PRINTF_S, + n += ACE_OS::sprintf (buffer + n, ACE_TEXT ("?%") ACE_TEXT_PRIs, this->headers_); } diff --git a/TAO/orbsvcs/FTRT_Event_Service/Factory_Service/EventChannelFactory_i.cpp b/TAO/orbsvcs/FTRT_Event_Service/Factory_Service/EventChannelFactory_i.cpp index aeb2d6bfb1c..ff81d3bc106 100644 --- a/TAO/orbsvcs/FTRT_Event_Service/Factory_Service/EventChannelFactory_i.cpp +++ b/TAO/orbsvcs/FTRT_Event_Service/Factory_Service/EventChannelFactory_i.cpp @@ -103,7 +103,8 @@ CORBA::Object_ptr EventChannelFactory_i::create_process ( const int ENV_BUF_LEN = 512; ACE_TCHAR buf[ENV_BUF_LEN]; server_addr.addr_to_string(buf,ENV_BUF_LEN,0); - options.setenv(ACE_TEXT("EventChannelFactoryAddr"), buf); + options.setenv(ACE_TEXT("EventChannelFactoryAddr"), + ACE_TEXT("%") ACE_TEXT_PRIs, buf); // extract the object ID from the criteria for (CORBA::ULong i = 0; i < the_criteria.length(); ++i) @@ -114,7 +115,8 @@ CORBA::Object_ptr EventChannelFactory_i::create_process ( const char* id_str = name[0].id.in(); the_criteria[i].val >>= val; if (id_str[0] != '-') // environment variable - options.setenv(ACE_TEXT_CHAR_TO_TCHAR(id_str), ACE_TEXT("%s"), val); + options.setenv(ACE_TEXT_CHAR_TO_TCHAR(id_str), + ACE_TEXT("%") ACE_TEXT_PRIs, val); else {// command line option ACE_OS::sprintf(buf, ACE_TEXT(" %s %s"), id_str, val); str += buf; @@ -124,7 +126,7 @@ CORBA::Object_ptr EventChannelFactory_i::create_process ( ORBSVCS_DEBUG((LM_DEBUG, "Command Line : %s\n", str.c_str())); - options.command_line(str.c_str()); + options.command_line(ACE_TEXT("%") ACE_TEXT_PRIs, str.c_str()); // Try to create a new process running date. ACE_Process new_process; diff --git a/TAO/orbsvcs/ImplRepo_Service/ImR_Activator_i.cpp b/TAO/orbsvcs/ImplRepo_Service/ImR_Activator_i.cpp index ab2e06d5c0f..8551aad3601 100644 --- a/TAO/orbsvcs/ImplRepo_Service/ImR_Activator_i.cpp +++ b/TAO/orbsvcs/ImplRepo_Service/ImR_Activator_i.cpp @@ -537,7 +537,7 @@ ImR_Activator_i::start_server(const char* name, 1, cmdline_buf_len + 1, this->env_buf_len_, this->max_env_vars_); - proc_opts.command_line (ACE_TEXT_CHAR_TO_TCHAR(cmdline)); + proc_opts.command_line (ACE_TEXT("%") ACE_TEXT_PRIs, ACE_TEXT_CHAR_TO_TCHAR(cmdline)); proc_opts.working_directory (dir); // Win32 does not support the CLOSE_ON_EXEC semantics for sockets // the way unix does, so in order to avoid having the child process @@ -564,13 +564,13 @@ ImR_Activator_i::start_server(const char* name, { CORBA::String_var ior = orb_->object_to_string (locator_.in ()); proc_opts.setenv (ACE_TEXT ("ImplRepoServiceIOR"), - ACE_TEXT_CHAR_TO_TCHAR (ior.in ())); + ACE_TEXT("%") ACE_TEXT_PRIs, ACE_TEXT_CHAR_TO_TCHAR (ior.in ())); } for (CORBA::ULong i = 0; i < env.length (); ++i) { proc_opts.setenv (ACE_TEXT_CHAR_TO_TCHAR (env[i].name.in ()), - ACE_TEXT_CHAR_TO_TCHAR (env[i].value.in ())); + ACE_TEXT("%") ACE_TEXT_PRIs, ACE_TEXT_CHAR_TO_TCHAR (env[i].value.in ())); } pid = this->process_mgr_.spawn (proc_opts, this); diff --git a/TAO/orbsvcs/tests/HTIOP/test_config.h b/TAO/orbsvcs/tests/HTIOP/test_config.h index d44559b8963..4bb8f2982ae 100644 --- a/TAO/orbsvcs/tests/HTIOP/test_config.h +++ b/TAO/orbsvcs/tests/HTIOP/test_config.h @@ -126,14 +126,12 @@ size_t const ACE_MAX_THREADS = 4; } #else /* ! VXWORKS */ -# if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) -# define ACE_INIT_LOG_FMT ACE_TEXT ("%ls%ls%ls") -# else -# define ACE_INIT_LOG_FMT ACE_TEXT ("%s%s%s") -# endif /* !ACE_WIN32 && ACE_USES_WCHAR */ #define ACE_INIT_LOG(NAME) \ ACE_TCHAR temp[MAXPATHLEN]; \ - ACE_OS::sprintf (temp, ACE_INIT_LOG_FMT, \ + ACE_OS::sprintf (temp, \ + ACE_TEXT ("%") ACE_TEXT_PRIs \ + ACE_TEXT ("%") ACE_TEXT_PRIs \ + ACE_TEXT ("%") ACE_TEXT_PRIs, \ ACE_LOG_DIRECTORY, \ ACE::basename (NAME, ACE_DIRECTORY_SEPARATOR_CHAR), \ ACE_LOG_FILE_EXT_NAME); \ -- cgit v1.2.1