Skip to content

Check build version numbers on Windows. - #7824

Closed
wyattoday wants to merge 4 commits into
curl:masterfrom
wyday:win-ver-buildnum
Closed

wyattoday wants to merge 4 commits into
curl:masterfrom
wyday:win-ver-buildnum

Conversation

@wyattoday

Copy link
Copy Markdown
Contributor

Check build version numbers on Windows. Required for enabling "evergreen" Windows 10/11 features (like TLS 1.3).

Builds upon @jay 's PR: #7810

This is required for: #7784

Less controversial version of #7727

@MarcelRaad

Copy link
Copy Markdown
Member

Apart from the checksrc failures, this looks good to me.

Comment thread lib/version_win32.c Resolved
@jay jay added the Windows Windows-specific label Oct 7, 2021

@jay jay left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this and it doesn't work the way I expected. For example, if I have Windows 7 which is 6.1 (major.minor) build 7601 and I try to match a higher build number but a lower version it will return false. For example:

  if(curlx_verify_windows_version(6, 0, 7602, PLATFORM_WINNT,
                                  VERSION_GREATER_THAN_EQUAL))
// won't happen because 7602 > 7601, even though 6.0 < 6.1

That does not make sense to me but is because of the way MS implemented the function. OTOH build numbers seem to only increase but I don't know where that's guaranteed. (edit: to clarify I mean I don't know what's to say windows 10 can't have a build number higher than a windows 11 build number)

I think we would need to call the verifyversion function more than once. Changes would also be needed to the separate legacy code that uses XXX_THAN_EQUAL , for example

    case VERSION_GREATER_THAN_EQUAL:
      if(osver.dwMajorVersion > majorVersion ||
        (osver.dwMajorVersion == majorVersion &&
         osver.dwMinorVersion >= minorVersion) ||
        (buildVersion != 0 &&
         (osver.dwMajorVersion == majorVersion &&
          osver.dwMinorVersion == minorVersion &&
          osver.dwBuildNumber >= buildVersion)))

should probably be this:

    case VERSION_GREATER_THAN_EQUAL:
      if(osver.dwMajorVersion > majorVersion ||
        (osver.dwMajorVersion == majorVersion &&
         osver.dwMinorVersion > minorVersion) ||
        ((osver.dwMajorVersion == majorVersion &&
          osver.dwMinorVersion == minorVersion &&
          osver.dwBuildNumber >= buildVersion)))

@jay

jay commented Oct 8, 2021

Copy link
Copy Markdown
Member

should probably be this:

actually probably this:

diff --git a/lib/version_win32.c b/lib/version_win32.c
index 3eb3c20..a7ad487 100644
--- a/lib/version_win32.c
+++ b/lib/version_win32.c
@@ -132,10 +132,10 @@ bool curlx_verify_windows_version(const unsigned int majorVersion,
     case VERSION_LESS_THAN_EQUAL:
       if(osver.dwMajorVersion < majorVersion ||
         (osver.dwMajorVersion == majorVersion &&
-         osver.dwMinorVersion <= minorVersion) ||
-        (buildVersion != 0 &&
-         (osver.dwMajorVersion == majorVersion &&
-          osver.dwMinorVersion == minorVersion &&
+         osver.dwMinorVersion < minorVersion) ||
+        (osver.dwMajorVersion == majorVersion &&
+         osver.dwMinorVersion == minorVersion &&
+         (buildVersion == 0 ||
           osver.dwBuildNumber <= buildVersion)))
         matched = TRUE;
       break;
@@ -151,10 +151,10 @@ bool curlx_verify_windows_version(const unsigned int majorVersion,
     case VERSION_GREATER_THAN_EQUAL:
       if(osver.dwMajorVersion > majorVersion ||
         (osver.dwMajorVersion == majorVersion &&
-         osver.dwMinorVersion >= minorVersion) ||
-        (buildVersion != 0 &&
-         (osver.dwMajorVersion == majorVersion &&
-          osver.dwMinorVersion == minorVersion &&
+         osver.dwMinorVersion > minorVersion) ||
+        (osver.dwMajorVersion == majorVersion &&
+         osver.dwMinorVersion == minorVersion &&
+         (buildVersion == 0 ||
           osver.dwBuildNumber >= buildVersion)))
         matched = TRUE;
       break;

I will see if I can do something similar for the VerifyVersionInfo call. I don't see any way to get around calling it more than once.

@wyattoday

wyattoday commented Oct 8, 2021 •

Copy link
Copy Markdown
Contributor Author

@jay

That does not make sense to me but is because of the way MS implemented the function. OTOH build numbers seem to only increase but I don't know where that's guaranteed. (edit: to clarify I mean I don't know what's to say windows 10 can't have a build number higher than a windows 11 build number)

For our purposes (and as things are right now), this is fine. Windows 11 is really Windows 10.0 with a build number higher than the newest Windows 10.

But more broadly, this is why in my original PR I dropped the half of the algorithm that used VerifyVersionInfoW and just built on the other implementation (one in which we control all the details).

Ultimately, I think that's the better design decision, but there was pushback on that PR, and one person in particular didn't like that I made that choice.

Changes would also be needed to the separate legacy code that uses XXX_THAN_EQUAL , for example [...]

I'm a bit confused on that suggestion. Are you suggesting that change so it more closely matches the quirky behavior of VerifyVersionInfoW()?

If so, wouldn't the better option just be to just coalesce around one non-quirky algorithm rather than splitting it into 2 and trying to match the quirky behavior? I mentioned this in the other PR as a way to reduce bugs and increase security (less divergent paths & more eyeball on one algo).

@jay

jay commented Oct 11, 2021 •

Copy link
Copy Markdown
Member

Changes would also be needed to the separate legacy code that uses XXX_THAN_EQUAL , for example [...]

I'm a bit confused on that suggestion. Are you suggesting that change so it more closely matches the quirky behavior of VerifyVersionInfoW()?

No what I'm suggesting is for example 10.0 build 222 should compare less than 11.0 build 111. VerifyVersionInfoW cannot do that comparison correctly (IMO) in a single call. See master...jay:pr_7824_modified, the squashme commit for the changes I think are needed. Basically multiple comparisons are needed if the build number needs to be compared. (edit: squashme commit updated this afternoon)

If so, wouldn't the better option just be to just coalesce around one non-quirky algorithm rather than splitting it into 2 and trying to match the quirky behavior? I mentioned this in the other PR as a way to reduce bugs and increase security (less divergent paths & more eyeball on one algo).

I don't know why it was necessary to keep GetVersionEx but I assume very old Windows systems. I really don't know why we need two paths but other project members have spoken up for those legacy systems in the past, and in particular separating GetVersionEx (because MS said they will remove it) from VerifyVersionInfo. I sympathize but I'm not interested in having that discussion right now because it might stop this from moving forward.

@MarcelRaad

Copy link
Copy Markdown
Member

I don't know why it was necessary to keep GetVersionEx but I assume very old Windows systems. I really don't know why we need two paths but other project members have spoken up for those legacy systems in the past, and in particular separating GetVersionEx (because MS said they will remove it) from VerifyVersionInfo.

I think it's needed for Windows Embedded Compact (formerly CE), which is not based on Windows NT.

@jay

jay commented Oct 18, 2021

Copy link
Copy Markdown
Member

See master...jay:pr_7824_modified, the squashme commit for the changes I think are needed.

Since there hasn't been any reply I intend to land that version and I've moved it to #7867 to run CI. Normally I would force push to the existing PR branch but I didn't here because it looks like the head branch is in your organization's repo.

@wyattoday

Copy link
Copy Markdown
Contributor Author

Either way, Jay.

Sorry for not getting back to this. Hadn’t had a free second in a while.

jay pushed a commit to jay/curl that referenced this pull request Dec 1, 2021
Prior to this change the build number was not checked during version
comparison, and the platform id was supposed to be checked but wasn't.

Checking the build number is required for enabling "evergreen"
Windows 10/11 features (like TLS 1.3).

Ref: curl#7784

Closes curl#7824
@jay

jay commented Dec 1, 2021

Copy link
Copy Markdown
Member

Closing in favor of #7867

@jay jay closed this Dec 1, 2021
jay pushed a commit that referenced this pull request Dec 2, 2021
Prior to this change the build number was not checked during version
comparison, and the platform id was supposed to be checked but wasn't.

Checking the build number is required for enabling "evergreen"
Windows 10/11 features (like TLS 1.3).

Ref: #7784

Closes #7824
Closes #7867
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Windows Windows-specific

Development

Successfully merging this pull request may close these issues.

3 participants