Skip to content

strerr: correct the strerror_s() return code condition#20955

Closed
bagder wants to merge 1 commit intomasterfrom
bagder/win-strerror
Closed

strerr: correct the strerror_s() return code condition#20955
bagder wants to merge 1 commit intomasterfrom
bagder/win-strerror

Conversation

@bagder
Copy link
Copy Markdown
Member

@bagder bagder commented Mar 17, 2026

In curlx_strerror on Windows, the condition checks !strerror_s(...) (true on success) and therefore always evaluates the fallback block. Even when strerror_s successfully produced a valid errno message.

Follow-up to 1eca08a

Pointed out by Codex Security

In curlx_strerror on Windows, the condition checks `!strerror_s(...)`
(true on success) and therefore always evaluates the fallback block.
Even when strerror_s successfully produced a valid errno message.

Follow-up to 1eca08a

Pointed out by Codex Security
@bagder bagder requested review from Copilot and vszakats March 17, 2026 12:25
@bagder bagder added the Windows Windows-specific label Mar 17, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes Windows error-string formatting in curlx_strerror() by correcting the strerror_s() return-code check so that the Winsock/WinAPI fallback path is only used when strerror_s() fails or yields "Unknown error".

Changes:

  • Correct the strerror_s() success/failure condition in the Windows branch of curlx_strerror().
  • Prevent valid CRT errno messages from being overwritten by the fallback logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@bagder bagder marked this pull request as ready for review March 17, 2026 12:43
@vszakats
Copy link
Copy Markdown
Member

vszakats commented Mar 17, 2026

I did test this locally because I'm prone to get such conditions
wrong. Turns out the value I chose to test the lower range EINVAL,
had a plausibly good, but wrong output. Some are identical. Nice catch!

Here are the difference before and after (with WINE):

bef|0|Success.|
aft|0|Success|
bef|1|Invalid function.|
aft|1|Operation not permitted|
bef|2|File not found.|
aft|2|No such file or directory|
bef|3|Path not found.|
aft|3|No such process|
bef|4|Too many open files.|
aft|4|Interrupted system call|
bef|5|Access denied.|
aft|5|Input/output error|
bef|6|Invalid handle.|
aft|6|No such device or address|
bef|7|Memory trashed.|
aft|7|Argument list too long|
bef|8|Not enough memory.|
aft|8|Exec format error|
bef|9|Invalid block.|
aft|9|Bad file descriptor|
bef|10|Bad environment.|
aft|10|No child processes|
bef|11|Bad format.|
aft|11|Resource temporarily unavailable|
bef|12|Invalid access.|
aft|12|Cannot allocate memory|
bef|13|Invalid data.|
aft|13|Permission denied|
bef|14|Out of memory.|
aft|14|Bad address|
bef|15|Invalid drive.|
aft|15|Invalid drive.|
bef|16|Can't delete current directory.|
aft|16|Device or resource busy|
bef|17|Not same device.|
aft|17|File exists|
bef|18|No more files.|
aft|18|Invalid cross-device link|
bef|19|Write protected.|
aft|19|No such device|
bef|20|Bad unit.|
aft|20|Not a directory|
bef|21|Not ready.|
aft|21|Is a directory|
bef|22|Bad command.|
aft|22|Invalid argument|
bef|23|CRC error.|
aft|23|Too many open files in system|
bef|24|Bad length.|
aft|24|Too many open files|
bef|25|Seek error.|
aft|25|Inappropriate ioctl for device|
bef|26|Not DOS disk.|
aft|26|Not DOS disk.|
bef|27|Sector not found.|
aft|27|File too large|
bef|28|Out of paper.|
aft|28|No space left on device|
bef|29|Write fault.|
aft|29|Illegal seek|
bef|30|Read fault.|
aft|30|Read-only file system|
bef|31|General failure.|
aft|31|Too many links|
bef|32|Sharing violation.|
aft|32|Broken pipe|
bef|33|Lock violation.|
aft|33|Numerical argument out of domain|
bef|34|Wrong disk.|
aft|34|Numerical result out of range|
bef|35|Unknown error 35 (0x23)|
aft|35|Unknown error 35 (0x23)|
bef|36|Sharing buffer exceeded.|
aft|36|Resource deadlock avoided|
bef|37|Unknown error 37 (0x25)|
aft|37|Unknown error 37 (0x25)|
bef|38|End of file.|
aft|38|File name too long|
bef|39|Disk full.|
aft|39|No locks available|
bef|40|Unknown error 40 (0x28)|
aft|40|Function not implemented|
bef|41|Unknown error 41 (0x29)|
aft|41|Directory not empty|
bef|42|Unknown error 42 (0x2a)|
aft|42|Invalid or incomplete multibyte or wide character|
bef|43|Unknown error 43 (0x2b)|
aft|43|Unknown error 43 (0x2b)|
bef|44|Unknown error 44 (0x2c)|
aft|44|Unknown error 44 (0x2c)|
bef|45|Unknown error 45 (0x2d)|
aft|45|Unknown error 45 (0x2d)|
bef|46|Unknown error 46 (0x2e)|
aft|46|Unknown error 46 (0x2e)|
bef|47|Unknown error 47 (0x2f)|
aft|47|Unknown error 47 (0x2f)|
bef|48|Unknown error 48 (0x30)|
aft|48|Unknown error 48 (0x30)|
bef|49|Unknown error 49 (0x31)|
aft|49|Unknown error 49 (0x31)|
bef|50|Request not supported.|
aft|50|Request not supported.|
bef|51|Remote machine not listening.|
aft|51|Remote machine not listening.|
bef|52|Duplicate network name.|
aft|52|Duplicate network name.|
bef|53|Bad network path.|
aft|53|Bad network path.|
bef|54|Network busy.|
aft|54|Network busy.|
bef|55|Device does not exist.|
aft|55|Device does not exist.|
bef|56|Too many commands.|
aft|56|Too many commands.|
bef|57|Adapter hardware error.|
aft|57|Adapter hardware error.|
bef|58|Bad network response.|
aft|58|Bad network response.|
bef|59|Unexpected network error.|
aft|59|Unexpected network error.|
bef|60|Bad remote adapter.|
aft|60|Bad remote adapter.|
bef|61|Print queue full.|
aft|61|Print queue full.|
bef|62|No spool space.|
aft|62|No spool space.|
bef|63|Print canceled.|
aft|63|Print canceled.|
bef|64|Network name deleted.|
aft|64|Network name deleted.|
bef|65|Network access denied.|
aft|65|Network access denied.|
bef|66|Bad device type.|
aft|66|Bad device type.|
bef|67|Bad network name.|
aft|67|Bad network name.|
bef|68|Too many network names.|
aft|68|Too many network names.|
bef|69|Too many network sessions.|
aft|69|Too many network sessions.|
bef|70|Sharing paused.|
aft|70|Sharing paused.|
bef|71|Request not accepted.|
aft|71|Request not accepted.|
bef|72|Redirector paused.|
aft|72|Redirector paused.|
bef|73|Unknown error 73 (0x49)|
aft|73|Unknown error 73 (0x49)|
bef|74|Unknown error 74 (0x4a)|
aft|74|Unknown error 74 (0x4a)|
bef|75|Unknown error 75 (0x4b)|
aft|75|Unknown error 75 (0x4b)|
bef|76|Unknown error 76 (0x4c)|
aft|76|Unknown error 76 (0x4c)|
bef|77|Unknown error 77 (0x4d)|
aft|77|Unknown error 77 (0x4d)|
bef|78|Unknown error 78 (0x4e)|
aft|78|Unknown error 78 (0x4e)|
bef|79|Unknown error 79 (0x4f)|
aft|79|Unknown error 79 (0x4f)|
bef|80|File exists.|
aft|80|File exists.|
bef|81|Unknown error 81 (0x51)|
aft|81|Unknown error 81 (0x51)|
bef|82|Cannot create.|
aft|82|Cannot create.|
bef|83|Int24 failure.|
aft|83|Int24 failure.|
bef|84|Out of structures.|
aft|84|Out of structures.|
bef|85|Already assigned.|
aft|85|Already assigned.|
bef|86|Invalid password.|
aft|86|Invalid password.|
bef|87|Invalid parameter.|
aft|87|Invalid parameter.|
bef|88|Net write fault.|
aft|88|Net write fault.|
bef|89|No process slots.|
aft|89|No process slots.|
bef|90|Unknown error 90 (0x5a)|
aft|90|Unknown error 90 (0x5a)|
bef|91|Unknown error 91 (0x5b)|
aft|91|Unknown error 91 (0x5b)|
bef|92|Unknown error 92 (0x5c)|
aft|92|Unknown error 92 (0x5c)|
bef|93|Unknown error 93 (0x5d)|
aft|93|Unknown error 93 (0x5d)|
bef|94|Unknown error 94 (0x5e)|
aft|94|Unknown error 94 (0x5e)|
bef|95|Unknown error 95 (0x5f)|
aft|95|Unknown error 95 (0x5f)|
bef|96|Unknown error 96 (0x60)|
aft|96|Unknown error 96 (0x60)|
bef|97|Unknown error 97 (0x61)|
aft|97|Unknown error 97 (0x61)|
bef|98|Unknown error 98 (0x62)|
aft|98|Unknown error 98 (0x62)|
bef|99|Unknown error 99 (0x63)|
aft|99|Unknown error 99 (0x63)|
bef|100|Too many semaphores.|
aft|100|Too many semaphores.|
bef|101|Exclusive semaphore already owned.|
aft|101|Exclusive semaphore already owned.|
bef|102|Semaphore is set.|
aft|102|Semaphore is set.|
bef|103|Too many semaphore requests.|
aft|103|Too many semaphore requests.|
bef|104|Invalid at interrupt time.|
aft|104|Invalid at interrupt time.|
bef|105|Semaphore owner died.|
aft|105|Semaphore owner died.|
bef|106|Semaphore user limit.|
aft|106|Semaphore user limit.|
bef|107|Insert disk for drive %1.|
aft|107|Insert disk for drive %1.|
bef|108|Drive locked.|
aft|108|Drive locked.|
bef|109|Broken pipe.|
aft|109|Broken pipe.|
bef|110|Open failed.|
aft|110|Open failed.|
bef|111|Buffer overflow.|
aft|111|Buffer overflow.|
bef|112|Disk full.|
aft|112|Disk full.|
bef|113|No more search handles.|
aft|113|No more search handles.|
bef|114|Invalid target handle.|
aft|114|Invalid target handle.|
bef|115|Unknown error 115 (0x73)|
aft|115|Unknown error 115 (0x73)|
bef|116|Unknown error 116 (0x74)|
aft|116|Unknown error 116 (0x74)|
bef|117|Invalid IOCTL.|
aft|117|Invalid IOCTL.|
bef|118|Invalid verify switch.|
aft|118|Invalid verify switch.|
bef|119|Bad driver level.|
aft|119|Bad driver level.|
bef|120|Call not implemented.|
aft|120|Call not implemented.|
bef|121|Semaphore timeout.|
aft|121|Semaphore timeout.|
bef|122|Insufficient buffer.|
aft|122|Insufficient buffer.|
bef|123|Invalid name.|
aft|123|Invalid name.|
bef|124|Invalid level.|
aft|124|Invalid level.|
bef|125|No volume label.|
aft|125|No volume label.|
bef|126|Module not found.|
aft|126|Module not found.|
bef|127|Procedure not found.|
aft|127|Procedure not found.|

vszakats added a commit to curl/curl-for-win that referenced this pull request Mar 17, 2026
@bagder bagder closed this in e894699 Mar 17, 2026
@bagder bagder deleted the bagder/win-strerror branch March 17, 2026 13:45
vszakats added a commit to curl/curl-for-win that referenced this pull request Mar 18, 2026
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