Commit c0107ee5 authored by thakis's avatar thakis Committed by Commit bot

Revert "Enable positional parameters for base::vsnprintf and base::vswprintf on Windows."

This reverts r127788.  Positional parameters aren't part of the C standard
(they are part of POSIX though), we don't really use them in the codebase,
and they don't work in chrome/android with libc++.  Rather
than have a test for them, make them also not work on Windows (like they
originally didn't) -- we shouldn't use positional printf parameters anyways.

Change the 5 uses to not use positional parameters.

BUG=118064,117028,427718

Review URL: https://codereview.chromium.org/902643002

Cr-Commit-Position: refs/heads/master@{#314963}
parent 8a0f4e28
......@@ -34,12 +34,9 @@ inline int strncmp16(const char16* s1, const char16* s2, size_t count) {
inline int vsnprintf(char* buffer, size_t size,
const char* format, va_list arguments) {
int length = _vsprintf_p(buffer, size, format, arguments);
if (length < 0) {
if (size > 0)
buffer[0] = 0;
return _vscprintf_p(format, arguments);
}
int length = vsnprintf_s(buffer, size, size - 1, format, arguments);
if (length < 0)
return _vscprintf(format, arguments);
return length;
}
......@@ -47,12 +44,9 @@ inline int vswprintf(wchar_t* buffer, size_t size,
const wchar_t* format, va_list arguments) {
DCHECK(IsWprintfFormatPortable(format));
int length = _vswprintf_p(buffer, size, format, arguments);
if (length < 0) {
if (size > 0)
buffer[0] = 0;
return _vscwprintf_p(format, arguments);
}
int length = _vsnwprintf_s(buffer, size, size - 1, format, arguments);
if (length < 0)
return _vscwprintf(format, arguments);
return length;
}
......
......@@ -163,19 +163,6 @@ TEST(StringPrintfTest, Invalid) {
}
#endif
// Test that the positional parameters work.
TEST(StringPrintfTest, PositionalParameters) {
std::string out;
SStringPrintf(&out, "%1$s %1$s", "test");
EXPECT_STREQ("test test", out.c_str());
#if defined(OS_WIN)
std::wstring wout;
SStringPrintf(&wout, L"%1$ls %1$ls", L"test");
EXPECT_STREQ(L"test test", wout.c_str());
#endif
}
// Test that StringPrintf and StringAppendV do not change errno.
TEST(StringPrintfTest, StringPrintfErrno) {
errno = 1;
......
......@@ -285,20 +285,20 @@ bool CreateVisualElementsManifest(const base::FilePath& src_path,
<< installer::kVisualElementsManifest << " to " << src_path.value();
return true;
} else {
// A printf_p-style format string for generating the visual elements
// A printf-style format string for generating the visual elements
// manifest. Required arguments, in order, are:
// - Localized display name for the product.
// - Relative path to the VisualElements directory.
// - Relative path to the VisualElements directory, three times.
static const char kManifestTemplate[] =
"<Application>\r\n"
" <VisualElements\r\n"
" DisplayName='%1$ls'\r\n"
" Logo='%2$ls\\Logo.png'\r\n"
" SmallLogo='%2$ls\\SmallLogo.png'\r\n"
" DisplayName='%ls'\r\n"
" Logo='%ls\\Logo.png'\r\n"
" SmallLogo='%ls\\SmallLogo.png'\r\n"
" ForegroundText='light'\r\n"
" BackgroundColor='#323232'>\r\n"
" <DefaultTile ShowName='allLogos'/>\r\n"
" <SplashScreen Image='%2$ls\\splash-620x300.png'/>\r\n"
" <SplashScreen Image='%ls\\splash-620x300.png'/>\r\n"
" </VisualElements>\r\n"
"</Application>";
......@@ -314,7 +314,8 @@ bool CreateVisualElementsManifest(const base::FilePath& src_path,
// Fill the manifest with the desired values.
base::string16 manifest16(base::StringPrintf(
manifest_template.c_str(), display_name.c_str(), elements_dir.c_str()));
manifest_template.c_str(), display_name.c_str(), elements_dir.c_str(),
elements_dir.c_str(), elements_dir.c_str()));
// Write the manifest to |src_path|.
const std::string manifest(base::UTF16ToUTF8(manifest16));
......
......@@ -267,18 +267,18 @@ IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetPrintersSuccess) {
expected_printers.push_back(base::StringPrintf(
"{"
"\"description\":\"Test printer\","
"\"extensionId\":\"%1$s\","
"\"id\":\"%1$s:printer1\","
"\"extensionId\":\"%s\","
"\"id\":\"%s:printer1\","
"\"name\":\"Printer 1\""
"}",
extension_id.c_str()));
extension_id.c_str(), extension_id.c_str()));
expected_printers.push_back(base::StringPrintf(
"{"
"\"extensionId\":\"%1$s\","
"\"id\":\"%1$s:printerNoDesc\","
"\"extensionId\":\"%s\","
"\"id\":\"%s:printerNoDesc\","
"\"name\":\"Printer 2\""
"}",
extension_id.c_str()));
extension_id.c_str(), extension_id.c_str()));
ValidatePrinterListValue(printers, expected_printers);
}
......@@ -305,11 +305,11 @@ IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetPrintersAsyncSuccess) {
expected_printers.push_back(base::StringPrintf(
"{"
"\"description\":\"Test printer\","
"\"extensionId\":\"%1$s\","
"\"id\":\"%1$s:printer1\","
"\"extensionId\":\"%s\","
"\"id\":\"%s:printer1\","
"\"name\":\"Printer 1\""
"}",
extension_id.c_str()));
extension_id.c_str(), extension_id.c_str()));
ValidatePrinterListValue(printers, expected_printers);
}
......@@ -343,33 +343,33 @@ IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetPrintersTwoExtensions) {
expected_printers.push_back(base::StringPrintf(
"{"
"\"description\":\"Test printer\","
"\"extensionId\":\"%1$s\","
"\"id\":\"%1$s:printer1\","
"\"extensionId\":\"%s\","
"\"id\":\"%s:printer1\","
"\"name\":\"Printer 1\""
"}",
extension_id_1.c_str()));
extension_id_1.c_str(), extension_id_1.c_str()));
expected_printers.push_back(base::StringPrintf(
"{"
"\"extensionId\":\"%1$s\","
"\"id\":\"%1$s:printerNoDesc\","
"\"extensionId\":\"%s\","
"\"id\":\"%s:printerNoDesc\","
"\"name\":\"Printer 2\""
"}",
extension_id_1.c_str()));
extension_id_1.c_str(), extension_id_1.c_str()));
expected_printers.push_back(base::StringPrintf(
"{"
"\"description\":\"Test printer\","
"\"extensionId\":\"%1$s\","
"\"id\":\"%1$s:printer1\","
"\"extensionId\":\"%s\","
"\"id\":\"%s:printer1\","
"\"name\":\"Printer 1\""
"}",
extension_id_2.c_str()));
extension_id_2.c_str(), extension_id_2.c_str()));
expected_printers.push_back(base::StringPrintf(
"{"
"\"extensionId\":\"%1$s\","
"\"id\":\"%1$s:printerNoDesc\","
"\"extensionId\":\"%s\","
"\"id\":\"%s:printerNoDesc\","
"\"name\":\"Printer 2\""
"}",
extension_id_2.c_str()));
extension_id_2.c_str(), extension_id_2.c_str()));
ValidatePrinterListValue(printers, expected_printers);
}
......@@ -404,18 +404,18 @@ IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest,
expected_printers.push_back(base::StringPrintf(
"{"
"\"description\":\"Test printer\","
"\"extensionId\":\"%1$s\","
"\"id\":\"%1$s:printer1\","
"\"extensionId\":\"%s\","
"\"id\":\"%s:printer1\","
"\"name\":\"Printer 1\""
"}",
extension_id_2.c_str()));
extension_id_2.c_str(), extension_id_2.c_str()));
expected_printers.push_back(base::StringPrintf(
"{"
"\"extensionId\":\"%1$s\","
"\"id\":\"%1$s:printerNoDesc\","
"\"extensionId\":\"%s\","
"\"id\":\"%s:printerNoDesc\","
"\"name\":\"Printer 2\""
"}",
extension_id_2.c_str()));
extension_id_2.c_str(), extension_id_2.c_str()));
ValidatePrinterListValue(printers, expected_printers);
}
......@@ -450,18 +450,18 @@ IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest,
expected_printers.push_back(base::StringPrintf(
"{"
"\"description\":\"Test printer\","
"\"extensionId\":\"%1$s\","
"\"id\":\"%1$s:printer1\","
"\"extensionId\":\"%s\","
"\"id\":\"%s:printer1\","
"\"name\":\"Printer 1\""
"}",
extension_id_2.c_str()));
extension_id_2.c_str(), extension_id_2.c_str()));
expected_printers.push_back(base::StringPrintf(
"{"
"\"extensionId\":\"%1$s\","
"\"id\":\"%1$s:printerNoDesc\","
"\"extensionId\":\"%s\","
"\"id\":\"%s:printerNoDesc\","
"\"name\":\"Printer 2\""
"}",
extension_id_2.c_str()));
extension_id_2.c_str(), extension_id_2.c_str()));
ValidatePrinterListValue(printers, expected_printers);
}
......
......@@ -39,8 +39,10 @@ bool CreateConnectedIpcChannel(
// between CreateNamedPipe() and CreateFile() calls before it will be passed
// to the network process. It gives full access to the account that
// the calling code is running under and denies access by anyone else.
std::string security_descriptor = base::StringPrintf(
"O:%1$sG:%1$sD:(A;;GA;;;%1$s)", base::WideToUTF8(user_sid).c_str());
std::string user_sid_utf8 = base::WideToUTF8(user_sid);
std::string security_descriptor =
base::StringPrintf("O:%sG:%sD:(A;;GA;;;%s)", user_sid_utf8.c_str(),
user_sid_utf8.c_str(), user_sid_utf8.c_str());
// Generate a unique name for the channel.
std::string channel_name = IPC::Channel::GenerateUniqueRandomChannelID();
......
......@@ -584,8 +584,10 @@ void Me2MeNativeMessagingHost::EnsureElevatedHostCreated() {
// Create a security descriptor that gives full access to the caller and
// denies access by anyone else.
std::string security_descriptor = base::StringPrintf(
"O:%1$sG:%1$sD:(A;;GA;;;%1$s)", base::UTF16ToASCII(user_sid).c_str());
std::string user_sid_ascii = base::UTF16ToASCII(user_sid);
std::string security_descriptor =
base::StringPrintf("O:%sG:%sD:(A;;GA;;;%s)", user_sid_ascii.c_str(),
user_sid_ascii.c_str(), user_sid_ascii.c_str());
ScopedSd sd = ConvertSddlToSd(security_descriptor);
if (!sd) {
......
......@@ -58,7 +58,7 @@ const char kLowIntegrityMandatoryLabel[] = "S:(ML;CIOI;NW;;;LW)";
// containers and objects inherit ACE giving SYSTEM and the logon SID full
// access to them as well.
const char kWindowStationSdFormat[] = "O:SYG:SYD:(A;CIOIIO;GA;;;SY)"
"(A;CIOIIO;GA;;;%1$s)(A;NP;0xf037f;;;SY)(A;NP;0xf037f;;;%1$s)";
"(A;CIOIIO;GA;;;%s)(A;NP;0xf037f;;;SY)(A;NP;0xf037f;;;%s)";
// Security descriptor of the worker process. It gives access SYSTEM full access
// to the process. It gives READ_CONTROL, SYNCHRONIZE, PROCESS_QUERY_INFORMATION
......@@ -123,7 +123,8 @@ bool CreateWindowStationAndDesktop(ScopedSid logon_sid,
std::string desktop_sddl =
base::StringPrintf(kDesktopSdFormat, logon_sid_string.c_str());
std::string window_station_sddl =
base::StringPrintf(kWindowStationSdFormat, logon_sid_string.c_str());
base::StringPrintf(kWindowStationSdFormat, logon_sid_string.c_str(),
logon_sid_string.c_str());
// The worker runs at low integrity level. Make sure it will be able to attach
// to the window station and desktop.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment