Repository navigation
Closed
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterplatform-windowsBuilding on or for Windows specificallyBuilding on or for Windows specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-windowsOwned by the Windows platform teamOwned by the Windows platform teamtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.triaged-windowsTriaged by the Windows platform teamTriaged by the Windows platform team
Description
Description
The Windows runner template file packages/flutter_tools/templates/app/windows.tmpl/runner/utils.cpp uses wcslen at line 52, which doesn't handle non-null-terminated strings. While the current usage is safe (input comes from Windows APIs that guarantee null-termination), using wcsnlen would be better defensive programming and resolves security scanner warnings (CWE-126: Buffer Over-read).
Current Code (line 52)
int input_length = (int)wcslen(utf16_string);Proposed Fix
int input_length = (int)wcsnlen(utf16_string, 32767);Why This Matters
- Security Scanners: Tools like Semgrep/GitLab SAST flag this as HIGH severity (CWE-126)
- Defensive Programming: Even though current usage is safe,
wcsnlenprovides an extra safety bound - No Performance Impact:
wcsnlenhas negligible overhead for typical string lengths - Consistency: Aligns with Microsoft's secure CRT recommendations
Related
- Related to Signed/Unsigned mismatch warning in Windows template utils.cpp #134227 (Signed/Unsigned mismatch in same file)
- CWE-126: Buffer Over-read
- Microsoft strnlen documentation
Risk Assessment
LOW - This is a minor defensive improvement. The existing code is functionally correct because:
- Input strings come from
CommandLineToArgvWwhich guarantees null-termination - The null check on line 45 handles the nullptr case
However, the fix follows security best practices and silences legitimate scanner warnings.
Checklist
- I have read the contributor guide
- I have an issue that this PR addresses
- All tests pass locally
Metadata
Metadata
Assignees
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterplatform-windowsBuilding on or for Windows specificallyBuilding on or for Windows specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-windowsOwned by the Windows platform teamOwned by the Windows platform teamtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.triaged-windowsTriaged by the Windows platform teamTriaged by the Windows platform team
Activity
fix(windows): use wcsnlen for defensive programming (CWE-126)
fix(windows): use wcsnlen for all string operations (CWE-126)
fix(windows): use wcsnlen for defensive programming (CWE-126)
fix(windows): use wcsnlen for all string operations (CWE-126)
fix(windows): use wcsnlen for defensive programming (CWE-126)
fix(windows): use wcsnlen for all string operations (CWE-126)
fix(windows): use wcsnlen for defensive programming (CWE-126) (#180419)
fix(windows): use wcsnlen for defensive programming (CWE-126) (flutte…
github-actions commentedon Feb 2, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.fix(windows): use wcsnlen for defensive programming (CWE-126) (flutte…
fix(windows): use wcsnlen for defensive programming (CWE-126) (#180419)