summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthakis <thakis@chromium.org>2015-02-05 19:42:14 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-06 03:44:25 +0000
commitc0107ee59bdb5b6337f7bbdb4e8210c0bfeb547b (patch)
tree60e81dabaf818666ecb5940227b6b184e827b0ab
parent8a0f4e28e2030d0a6ad09b68311efc428cc48ce6 (diff)
downloadchromium_src-c0107ee59bdb5b6337f7bbdb4e8210c0bfeb547b.zip
chromium_src-c0107ee59bdb5b6337f7bbdb4e8210c0bfeb547b.tar.gz
chromium_src-c0107ee59bdb5b6337f7bbdb4e8210c0bfeb547b.tar.bz2
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}
-rw-r--r--base/strings/string_util_win.h18
-rw-r--r--base/strings/stringprintf_unittest.cc13
-rw-r--r--chrome/installer/setup/install.cc15
-rw-r--r--extensions/browser/api/printer_provider/printer_provider_apitest.cc66
-rw-r--r--remoting/host/ipc_util_win.cc6
-rw-r--r--remoting/host/setup/me2me_native_messaging_host.cc6
-rw-r--r--remoting/host/win/unprivileged_process_delegate.cc5
7 files changed, 58 insertions, 71 deletions
diff --git a/base/strings/string_util_win.h b/base/strings/string_util_win.h
index 602ba27..61eda20 100644
--- a/base/strings/string_util_win.h
+++ b/base/strings/string_util_win.h
@@ -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;
}
diff --git a/base/strings/stringprintf_unittest.cc b/base/strings/stringprintf_unittest.cc
index 3217478..c49637c 100644
--- a/base/strings/stringprintf_unittest.cc
+++ b/base/strings/stringprintf_unittest.cc
@@ -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;
diff --git a/chrome/installer/setup/install.cc b/chrome/installer/setup/install.cc
index d94824d..68ecef4 100644
--- a/chrome/installer/setup/install.cc
+++ b/chrome/installer/setup/install.cc
@@ -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));
diff --git a/extensions/browser/api/printer_provider/printer_provider_apitest.cc b/extensions/browser/api/printer_provider/printer_provider_apitest.cc
index 0dd8df0..30840b3 100644
--- a/extensions/browser/api/printer_provider/printer_provider_apitest.cc
+++ b/extensions/browser/api/printer_provider/printer_provider_apitest.cc
@@ -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);
}
diff --git a/remoting/host/ipc_util_win.cc b/remoting/host/ipc_util_win.cc
index dbc5c54..22ac15a 100644
--- a/remoting/host/ipc_util_win.cc
+++ b/remoting/host/ipc_util_win.cc
@@ -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();
diff --git a/remoting/host/setup/me2me_native_messaging_host.cc b/remoting/host/setup/me2me_native_messaging_host.cc
index e3480b1..7472c24 100644
--- a/remoting/host/setup/me2me_native_messaging_host.cc
+++ b/remoting/host/setup/me2me_native_messaging_host.cc
@@ -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) {
diff --git a/remoting/host/win/unprivileged_process_delegate.cc b/remoting/host/win/unprivileged_process_delegate.cc
index b7997912..0537218 100644
--- a/remoting/host/win/unprivileged_process_delegate.cc
+++ b/remoting/host/win/unprivileged_process_delegate.cc
@@ -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.