Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
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" | |
3 | |
4 using namespace AdblockPlus; | |
5 | |
6 /** | |
7 * Internal implementation of the IE version string. | |
8 * | |
9 * This version throws exceptions for its errors, relying on its caller to handl e them. | |
10 * | |
11 * 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 * [EH 2014-06-20] My current version of IE 11 is reporting these values: | |
14 * Version 9.11.9600.17041 | |
15 * svcVersion 11.0.9600.17041 | |
16 * | |
17 * 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
| |
18 */ | |
19 std::wstring IE_version_string() | |
20 { | |
21 Registry_Key IE_key(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Internet Explor er"); | |
22 std::wstring version(IE_key.value_wstring(L"Version")); | |
23 /* | |
24 * 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. | |
26 */ | |
27 if (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 { | |
29 throw std::runtime_error("IE version string has unexpected format"); | |
30 } | |
31 if (version[0] != L'9') | |
32 { | |
33 return version; | |
34 } | |
35 // Assert the major version in the "Version" value is 9. | |
36 /* | |
37 * Version 9 might either be an actual version 9 or it might represent a vers ion >= 10 | |
38 * If the value named "svcVersion" exists, we'll report that instead. | |
39 */ | |
40 try | |
41 { | |
42 return IE_key.value_wstring(L"svcVersion"); | |
43 } | |
44 catch (...) | |
45 { | |
46 return version; | |
47 } | |
48 } | |
49 | |
50 std::wstring AdblockPlus::IE::installed_version_string() | |
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 { | |
52 try | |
53 { | |
54 return IE_version_string(); | |
55 } | |
56 catch (...) | |
57 { | |
58 return L""; | |
59 } | |
60 } | |
61 | |
62 int AdblockPlus::IE::installed_major_version() | |
63 { | |
64 try | |
65 { | |
66 std::wstring version = IE_version_string(); | |
67 /* | |
68 * If the second character is a period, we assume that the major version is a single digit. | |
69 */ | |
70 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 { | |
72 return version[ 0 ] - L'0'; | |
73 } | |
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 } | |
85 catch (...) | |
86 { | |
87 return 0; | |
88 } | |
89 } | |
OLD | NEW |