| | @@ -2847,10 +2852,40 @@ |
| 2847 | 2852 | |
| 2848 | 2853 | #if defined(UNICODE) && !defined(WIN32) |
| 2849 | 2854 | if (wcsstr(lpszFmt, TEXT("%s")) != NULL) { |
| 2850 | | - /* This is a coding error as strings coming into this function should NEVER use this format. |
| 2851 | | - * If the token below is not '%S' then this would recurse. */ |
| 2852 | | - log_printf_queue(useQueue, source_id, LEVEL_ERROR, TEXT("Coding Error. String contains invalid string token for queued logging: %S"), lpszFmt); |
| 2853 | | - return; |
| 2855 | + /* On UNIX platforms string tokens must always use "%S" variables and not "%s". We can |
| 2856 | + * not safely use malloc here as the call may have originated from a signal handler. |
| 2857 | + * Copy the template into the formatMessages string reserved for this thread, replace |
| 2858 | + * the tokens and then continue using that. */ |
| 2859 | + threadId = getThreadId(); |
| 2860 | + _tcsncpy(formatMessages[threadId], lpszFmt, QUEUED_BUFFER_SIZE); |
| 2861 | + /* Terminate just in case the format was too long. */ |
| 2862 | + formatMessages[threadId][QUEUED_BUFFER_SIZE - 1] = TEXT('\0'); |
| 2863 | + |
| 2864 | + format = formatMessages[threadId]; |
| 2865 | + |
| 2866 | + /* Replace the tokens. */ |
| 2867 | +#ifdef _DEBUG_QUEUE |
| 2868 | + _tprintf(TEXT("Replacing string tokens.\n")); |
| 2869 | + _tprintf(TEXT(" From: %S\n"), format); |
| 2870 | +#endif |
| 2871 | + len = wcslen(format); |
| 2872 | + if (len > 0) { |
| 2873 | + for (i = 0; i < len; i++) { |
| 2874 | + if ((i > 0) && (format[i - 1] == TEXT('%')) && (format[i] == TEXT('s'))) { |
| 2875 | + /* Make sure the '%' was not escaped. */ |
| 2876 | + if ((i > 1) && (format[i - 2] == TEXT('%'))) { |
| 2877 | + /* Escaped. Do nothing. */ |
| 2878 | + } else { |
| 2879 | + /* 's' needs to be changed to 'S' */ |
| 2880 | + format[i] = TEXT('S'); |
| 2881 | + } |
| 2882 | + } |
| 2883 | + } |
| 2884 | + } |
| 2885 | +#ifdef _DEBUG_QUEUE |
| 2886 | + _tprintf(TEXT(" To: %S\n"), format); |
| 2887 | +#endif |
| 2888 | + lpszFmt = format; |
| 2854 | 2889 | } |
| 2855 | 2890 | #endif |
| 2856 | 2891 | |