Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 #include "IE_version.h" | 1 #include "IE_version.h" |
sergei
2014/07/28 11:46:27
I don't think it should be in shared, because it's
Eric
2014/07/29 12:42:25
See #404. This code is destined to move again soon
sergei
2014/07/29 14:45:56
Clear, it should be here. But why will it be moved
Eric
2014/07/29 15:17:22
Go read #404 again. Fixing that ticket requires a
sergei
2014/07/30 10:42:04
In #404 there is nothing about any problems with l
Eric
2014/07/30 13:02:04
Yes, that's because the ticket states what the pro
| |
2 #include "Registry.h" | 2 #include "Registry.h" |
3 #include <cstdlib> | |
3 | 4 |
4 using namespace AdblockPlus; | 5 using namespace AdblockPlus; |
5 | 6 |
6 /** | 7 /** |
7 * Internal implementation of the IE version string. | 8 * Internal implementation of the IE version string. |
8 * | 9 * |
9 * This version throws exceptions for its errors, relying on its caller to handl e them. | 10 * This version throws exceptions for its errors, relying on its caller to handl e them. |
10 * | 11 * |
11 * Quoting http://support.microsoft.com/kb/969393: | 12 * Quoting http://support.microsoft.com/kb/969393: |
12 * "Note The version string value for Internet Explorer 10 is 9.10.9200.16384, and the svcVersion string value is 10.0.9200.16384." | 13 * "Note The version string value for Internet Explorer 10 is 9.10.9200.16384, and the svcVersion string value is 10.0.9200.16384." |
13 * [EH 2014-06-20] My current version of IE 11 is reporting these values: | 14 * [EH 2014-06-20] My current version of IE 11 is reporting these values: |
14 * Version 9.11.9600.17041 | 15 * Version 9.11.9600.17041 |
15 * svcVersion 11.0.9600.17041 | 16 * svcVersion 11.0.9600.17041 |
16 * | 17 * |
17 * Warning: IE version 12 and later might not behave the same, so this function should be reviewed with each new release. | 18 * Warning: IE version 12 and later might not behave the same, so this function should be reviewed with each new release. |
sergei
2014/07/28 11:46:27
Tests should run on all machines with all IE versi
Eric
2014/07/29 12:42:25
If that's the case, the best you can get is a sani
| |
19 * | |
20 * \par postcondition | |
21 * Return value matches regex `^[0-9]{1,2}\.$`; this is a sanity check on the format. | |
18 */ | 22 */ |
19 std::wstring IE_version_string() | 23 std::wstring IeVersionString() |
20 { | 24 { |
21 Registry_Key IE_key(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Internet Explor er"); | 25 RegistryKey ieKey(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Internet Explorer "); |
22 std::wstring version(IE_key.value_wstring(L"Version")); | 26 std::wstring version(ieKey.value_wstring(L"Version")); |
23 /* | 27 /* |
24 * We're expecting a version string that matches the regex "^[1-9]\.". | 28 * We're expecting a version string that matches the regex "^[1-9]\.". |
sergei
2014/07/28 11:46:27
It's also mentioned in tests, why do we need the p
Eric
2014/07/29 12:42:25
We're validating the format of the version string.
| |
25 * Since IE versions 10 and 11 use a version string that begins with "9.", th is simplistic parsing method works adequately. | 29 * Since IE versions 10 and 11 use a version string that begins with "9.", thi s simplistic parsing method works adequately. |
26 */ | 30 */ |
27 if (version[1] != '.' || version[0] < L'0' || version[0] > L'9') | 31 if (version.length() < 2 || version[1] != '.' || version[0] < L'0' || version[ 0] > L'9') |
sergei
2014/07/28 11:46:27
strictly speaking we have to check the length of `
Eric
2014/07/29 12:42:25
You're right; this is a defect, since if the regis
sergei
2014/07/29 14:45:56
How can you make an assumption that the most likel
Eric
2014/07/29 15:17:22
It's beyond the scope of this class to defend agai
sergei
2014/07/30 10:42:04
All code should be safe.
Eric
2014/07/30 13:02:04
OK. That's what I'll agree with. But "safe" and "d
| |
28 { | 32 { |
29 throw std::runtime_error("IE version string has unexpected format"); | 33 throw std::runtime_error("IE version string has unexpected format"); |
30 } | 34 } |
31 if (version[0] != L'9') | 35 if (version[0] != L'9') |
32 { | 36 { |
33 return version; | 37 return version; |
34 } | 38 } |
35 // Assert the major version in the "Version" value is 9. | 39 // Assert the major version in the "Version" value is 9. |
36 /* | 40 /* |
37 * Version 9 might either be an actual version 9 or it might represent a vers ion >= 10 | 41 * Version 9 might either be an actual version 9 or it might represent a versi on >= 10 |
38 * If the value named "svcVersion" exists, we'll report that instead. | 42 * If the value named "svcVersion" exists, we'll report that instead. |
39 */ | 43 */ |
40 try | 44 try |
41 { | 45 { |
42 return IE_key.value_wstring(L"svcVersion"); | 46 version = ieKey.value_wstring(L"svcVersion"); // throws if value not found |
43 } | 47 } |
44 catch (...) | 48 catch (...) |
45 { | 49 { |
50 // Assert svcVersion value not found | |
51 // Thus the major version is 9 | |
46 return version; | 52 return version; |
53 } | |
54 // Assert major version is >= 10 | |
55 if (version.length() < 3 || version[0] < L'0' || version[0] > L'9' || version[ 1] < L'0' || version[1] > L'9' || version[2] != L'.') | |
56 { | |
57 throw std::runtime_error("IE version string has unexpected format"); | |
47 } | 58 } |
59 return version; | |
48 } | 60 } |
49 | 61 |
50 std::wstring AdblockPlus::IE::installed_version_string() | 62 std::wstring AdblockPlus::IE::InstalledVersionString() |
sergei
2014/07/28 11:46:27
What is the aim of this method? I think we can get
Eric
2014/07/29 12:42:25
It's called in engine/Main.cpp to fix #41.
sergei
2014/07/29 14:45:56
If it's only the place, then do try-catch where it
| |
51 { | 63 { |
52 try | 64 try |
53 { | 65 { |
54 return IE_version_string(); | 66 return IeVersionString(); |
55 } | 67 } |
56 catch (...) | 68 catch (...) |
57 { | 69 { |
58 return L""; | 70 return L""; |
59 } | 71 } |
60 } | 72 } |
61 | 73 |
62 int AdblockPlus::IE::installed_major_version() | 74 int AdblockPlus::IE::InstalledMajorVersion() |
63 { | 75 { |
64 try | 76 try |
65 { | 77 { |
66 std::wstring version = IE_version_string(); | 78 std::wstring version = IeVersionString(); |
67 /* | 79 /* |
68 * If the second character is a period, we assume that the major version is a single digit. | 80 * The version number is either one or two digits, |
81 * and thus either the second or third character is a period, | |
69 */ | 82 */ |
70 if (version[ 1 ] == L'.') | 83 if (version[1] == L'.') |
Oleksandr
2014/07/27 22:13:30
Nit: The array index should not be enclosed in whi
sergei
2014/07/28 11:46:27
I would like to check the size.
Eric
2014/07/28 11:48:43
I reformatted this code with Artistic Style. (It's
Eric
2014/07/29 12:42:25
Yes; same kind of defect as above.
| |
71 { | 84 { |
72 return version[ 0 ] - L'0'; | 85 return version[0] - L'0'; |
86 } | |
87 else if (version[2] == L'.') | |
88 { | |
89 return 10 * (version[0] - L'0') + (version[1] - L'0'); | |
73 } | 90 } |
74 // Assert IE_version_string() did not verify the syntax of the version strin g. | |
75 /* | |
76 * In this case, we'll assume that the version returned is two digits follow ed by a period. | |
77 * If not, we'll assume an error. | |
78 */ | |
79 if (version[ 0 ] < L'0' || version[ 0 ] > L'9' || version[ 1 ] < L'0' || ver sion[ 1 ] > L'9' || version[ 2 ] != L'.') | |
sergei
2014/07/28 11:46:27
Is it really better than atoi?
Eric
2014/07/29 12:42:25
The condition is validating the format, which we n
sergei
2014/07/29 14:45:56
We don't need to truncate it, anyway it looks good
| |
80 { | |
81 return 0; | |
82 } | |
83 return 10 * (version[ 0 ] - L'0') + (version[ 1 ] - L'0'); | |
84 } | 91 } |
85 catch (...) | 92 catch (...) |
86 { | 93 { |
87 return 0; | |
88 } | 94 } |
95 return 0; | |
89 } | 96 } |
LEFT | RIGHT |