Skip to content

Conversation

@vszakats
Copy link
Member

@vszakats vszakats commented Nov 18, 2025

Replace:

  • curl_sspi: macro _tcsncpy() with _tcsncpy_s().
  • curlx/fopen: wcsncpy() with wcsncpy_s().
  • curlx/fopen: wcscpy() with wcscpy_s().

Use of the pre-existing functions were safe. This patch aims to use the
recommended Windows CRT functions. Handle errors returned by them. Also
to avoid the compiler warnings silenced via _CRT_SECURE_NO_WARNINGS:

lib/curl_sspi.c(152): warning C4996: 'wcsncpy': This function or variable may be unsafe. Consider using wcsncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
lib/curlx/fopen.c(161): warning C4996: 'wcsncpy': This function or variable may be unsafe. Consider using wcsncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
lib/curlx/fopen.c(162): warning C4996: 'wcscpy': This function or variable may be unsafe. Consider using wcscpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
lib/curlx/fopen.c(174): warning C4996: 'wcsncpy': This function or variable may be unsafe. Consider using wcsncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
lib/curlx/fopen.c(175): warning C4996: 'wcscpy': This function or variable may be unsafe. Consider using wcscpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.

Refs:
https://learn.microsoft.com/cpp/c-runtime-library/reference/strncpy-strncpy-l-wcsncpy-wcsncpy-l-mbsncpy-mbsncpy-l
https://learn.microsoft.com/cpp/c-runtime-library/reference/strncpy-s-strncpy-s-l-wcsncpy-s-wcsncpy-s-l-mbsncpy-s-mbsncpy-s-l
https://learn.microsoft.com/cpp/c-runtime-library/security-features-in-the-crt

Cherry-picked from #19581 (in part)


  • replacement functions return an error code. Check them?

@vszakats vszakats added Windows Windows-specific tidy-up labels Nov 18, 2025
@vszakats vszakats changed the title curlx/fopen: replace two CRT functions with their _s counterparts (Windows) curlx/fopen: replace wcsncpy/wcscpy with their _s counterparts (Windows) Nov 19, 2025
@vszakats vszakats changed the title curlx/fopen: replace wcsncpy/wcscpy with their _s counterparts (Windows) lib: replace wcsncpy/wcscpy with their _s counterparts (Windows) Nov 19, 2025
@vszakats vszakats changed the title lib: replace wcsncpy/wcscpy with their _s counterparts (Windows) lib: replace _tcsncpy/wcsncpy/wcscpy with _s counterparts (Windows) Nov 19, 2025
@vszakats vszakats closed this in eaa7651 Nov 21, 2025
@vszakats vszakats deleted the wcs2 branch November 21, 2025 12:50
vszakats added a commit to vszakats/curl that referenced this pull request Nov 21, 2025
vszakats added a commit to vszakats/curl that referenced this pull request Nov 21, 2025
vszakats added a commit to vszakats/curl that referenced this pull request Nov 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tidy-up Windows Windows-specific

Development

Successfully merging this pull request may close these issues.

1 participant