|
|
Created:
5 years, 7 months ago by benwells Modified:
5 years, 7 months ago CC:
chromium-reviews, cbentzel+watch_chromium.org, mmenke, chrome-apps-syd-reviews_chromium.org Base URL:
https://chromium.googlesource.com/chromium/src.git@master Target Ref:
refs/pending/heads/master Project:
chromium Visibility:
Public. |
DescriptionFix uninitialized reads in DnsConfigServiceWin tests.
BUG=486575
Committed: https://crrev.com/9d04c6ad2ac23314e6dd5d9f9bb6029146fcb4e0
Cr-Commit-Position: refs/heads/master@{#329499}
Patch Set 1 #
Total comments: 3
Patch Set 2 : Neater #
Total comments: 1
Patch Set 3 : Set 'set' explicitly #Messages
Total messages: 15 (3 generated)
benwells@chromium.org changed reviewers: + thakis@chromium.org
This turned out to be yuckier than I thought it would. Let me know if there is a cleaner approach.
Thanks for looking at my mess! https://codereview.chromium.org/1132333003/diff/1/net/dns/dns_config_service_... File net/dns/dns_config_service_win_unittest.cc (right): https://codereview.chromium.org/1132333003/diff/1/net/dns/dns_config_service_... net/dns/dns_config_service_win_unittest.cc:261: { true, L"primary.dns.suffix" }, Huh, I thought that using a brace initializer for a struct zero-initializes all fields after the listed ones to 0 (like `mystruct a = {};` sets all fields to 0). Is that not the case here? Why not? If not, I'd just add a few `{ { false }, { false } }` lines in these blocks rather than add all these automatic initializers.
https://codereview.chromium.org/1132333003/diff/1/net/dns/dns_config_service_... File net/dns/dns_config_service_win_unittest.cc (right): https://codereview.chromium.org/1132333003/diff/1/net/dns/dns_config_service_... net/dns/dns_config_service_win_unittest.cc:261: { true, L"primary.dns.suffix" }, On 2015/05/11 04:08:29, Nico wrote: > Huh, I thought that using a brace initializer for a struct zero-initializes all > fields after the listed ones to 0 (like `mystruct a = {};` sets all fields to > 0). Is that not the case here? Why not? > > If not, I'd just add a few `{ { false }, { false } }` lines in these blocks > rather than add all these automatic initializers. The problem was elsewhere, with these changes fallout from the actual fix. See next comment for details. https://codereview.chromium.org/1132333003/diff/1/net/dns/dns_config_service_... net/dns/dns_config_service_win_unittest.cc:486: internal::ConvertSettingsToDnsConfig(settings, &config)); This was the line causing the error that I investigated. The problem is that settings.policy_search_list.set is not initialized, because the new default initializer for DnsSystemSettings initializes policy_search_list with policy_search_list(). As RegString has no default values / no constructor this leaves set uninitialized. The actual fix for this was to add the "= false" to RegString and RegDword. The rest of the change was required to make this test compile.
On 2015/05/11 05:12:38, benwells wrote: > https://codereview.chromium.org/1132333003/diff/1/net/dns/dns_config_service_... > File net/dns/dns_config_service_win_unittest.cc (right): > > https://codereview.chromium.org/1132333003/diff/1/net/dns/dns_config_service_... > net/dns/dns_config_service_win_unittest.cc:261: { true, L"primary.dns.suffix" }, > On 2015/05/11 04:08:29, Nico wrote: > > Huh, I thought that using a brace initializer for a struct zero-initializes > all > > fields after the listed ones to 0 (like `mystruct a = {};` sets all fields to > > 0). Is that not the case here? Why not? > > > > If not, I'd just add a few `{ { false }, { false } }` lines in these blocks > > rather than add all these automatic initializers. > > The problem was elsewhere, with these changes fallout from the actual fix. See > next comment for details. > > https://codereview.chromium.org/1132333003/diff/1/net/dns/dns_config_service_... > net/dns/dns_config_service_win_unittest.cc:486: > internal::ConvertSettingsToDnsConfig(settings, &config)); > This was the line causing the error that I investigated. The problem is that > settings.policy_search_list.set is not initialized, because the new default > initializer for DnsSystemSettings initializes policy_search_list with > policy_search_list(). Ah. Is it possible to say `policy_search_list{}` instead to keep aggegate initialization instead of value initialization for that member? (Or maybe `policy_search_list{false}` or just say `policy_search_list.set = false;` in the ctor body? Then all the other stuff isn't needed. > > As RegString has no default values / no constructor this leaves set > uninitialized. > > The actual fix for this was to add the "= false" to RegString and RegDword. The > rest of the change was required to make this test compile.
On 2015/05/11 17:12:47, Nico (mostly OOO this monday) wrote: > On 2015/05/11 05:12:38, benwells wrote: > > > https://codereview.chromium.org/1132333003/diff/1/net/dns/dns_config_service_... > > File net/dns/dns_config_service_win_unittest.cc (right): > > > > > https://codereview.chromium.org/1132333003/diff/1/net/dns/dns_config_service_... > > net/dns/dns_config_service_win_unittest.cc:261: { true, L"primary.dns.suffix" > }, > > On 2015/05/11 04:08:29, Nico wrote: > > > Huh, I thought that using a brace initializer for a struct zero-initializes > > all > > > fields after the listed ones to 0 (like `mystruct a = {};` sets all fields > to > > > 0). Is that not the case here? Why not? > > > > > > If not, I'd just add a few `{ { false }, { false } }` lines in these blocks > > > rather than add all these automatic initializers. > > > > The problem was elsewhere, with these changes fallout from the actual fix. See > > next comment for details. > > > > > https://codereview.chromium.org/1132333003/diff/1/net/dns/dns_config_service_... > > net/dns/dns_config_service_win_unittest.cc:486: > > internal::ConvertSettingsToDnsConfig(settings, &config)); > > This was the line causing the error that I investigated. The problem is that > > settings.policy_search_list.set is not initialized, because the new default > > initializer for DnsSystemSettings initializes policy_search_list with > > policy_search_list(). > > Ah. Is it possible to say `policy_search_list{}` instead to keep aggegate > initialization instead of value initialization for that member? (Or maybe > `policy_search_list{false}` or just say `policy_search_list.set = false;` in the > ctor body? Then all the other stuff isn't needed. How's this? I don't think policy_search_list{false} is allowed due to uniform initialization syntax being banned, but this basically does the same thing. > > > > > As RegString has no default values / no constructor this leaves set > > uninitialized. > > > > The actual fix for this was to add the "= false" to RegString and RegDword. > The > > rest of the change was required to make this test compile.
lgtm, but lbtm with the suggestion. Again thank you very much for doing this for me. https://codereview.chromium.org/1132333003/diff/20001/net/dns/dns_config_serv... File net/dns/dns_config_service_win.cc (right): https://codereview.chromium.org/1132333003/diff/20001/net/dns/dns_config_serv... net/dns/dns_config_service_win.cc:447: append_to_multi_label_name({}), Hm, isn't this uniform initialization too? Nicos-MacBook-Pro-4:src thakis$ clang -c test.cc -std=c++11 Nicos-MacBook-Pro-4:src thakis$ cat test.cc struct A { int a, b; }; struct B { B(); A a_; }; B::B() : a_({}) { } Nicos-MacBook-Pro-4:src thakis$ clang -c test.cc test.cc:10:13: error: expected expression B::B() : a_({}) { ^ 1 error generated. Nicos-MacBook-Pro-4:src thakis$ clang -c test.cc -std=c++11 # works Maybe best to just set all the "set"s to false in the body explicitly :-/
benwells@chromium.org changed reviewers: + rsleevi@chromium.org
On 2015/05/12 00:32:17, Nico (mostly OOO this monday) wrote: > lgtm, but lbtm with the suggestion. > > Again thank you very much for doing this for me. > > https://codereview.chromium.org/1132333003/diff/20001/net/dns/dns_config_serv... > File net/dns/dns_config_service_win.cc (right): > > https://codereview.chromium.org/1132333003/diff/20001/net/dns/dns_config_serv... > net/dns/dns_config_service_win.cc:447: append_to_multi_label_name({}), > Hm, isn't this uniform initialization too? > Nicos-MacBook-Pro-4:src thakis$ clang -c test.cc -std=c++11 > Nicos-MacBook-Pro-4:src thakis$ cat test.cc > struct A { > int a, b; > }; > > struct B { > B(); > A a_; > }; > > B::B() : a_({}) { > } > Nicos-MacBook-Pro-4:src thakis$ clang -c test.cc > test.cc:10:13: error: expected expression > B::B() : a_({}) { > ^ > 1 error generated. > Nicos-MacBook-Pro-4:src thakis$ clang -c test.cc -std=c++11 > # works > > > Maybe best to just set all the "set"s to false in the body explicitly :-/ Ah .. ok. That's a shame.... done. +rsleevi for owners review
lgtm, thanks.
blah, LGTM
The CQ bit was checked by thakis@chromium.org
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1132333003/40001
Message was sent while issue was closed.
Committed patchset #3 (id:40001)
Message was sent while issue was closed.
Patchset 3 (id:??) landed as https://crrev.com/9d04c6ad2ac23314e6dd5d9f9bb6029146fcb4e0 Cr-Commit-Position: refs/heads/master@{#329499} |