Skip to content

[UDFS] Initialize all local variables to prevent 0xCCCCCCCC in MSVC debug builds#218

Draft
Copilot wants to merge 7 commits into
udf-devfrom
copilot/udfs-fix-code
Draft

[UDFS] Initialize all local variables to prevent 0xCCCCCCCC in MSVC debug builds#218
Copilot wants to merge 7 commits into
udf-devfrom
copilot/udfs-fix-code

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 6, 2026

MSVC debug builds fill uninitialized stack variables with 0xCCCCCCCC. In kernel drivers this is dangerous: an uninitialized BOOLEAN reads as TRUE (non-zero), causing _SEH2_FINALLY cleanup blocks to release locks or resources that were never acquired.

Changes

  • NTSTATUS variables: initialized to STATUS_SUCCESS
  • BOOLEAN flags: initialized to FALSE
  • ULONG counters/sizes: initialized to 0
  • Pointer variables: initialized to NULL

Covers 31 files across the driver (cleanup.cpp, create.cpp, fileinfo.cpp, fscntrl.cpp, misc.cpp, read.cpp, write.cpp, udf_info/dirtree.cpp, udf_info/extent.cpp, udf_info/mount.cpp, udf_info/udf_info.cpp, and others) as well as the support libraries in the Include/ directory (Sys_spec_lib.cpp, phys_lib.cpp, regtools.cpp, mem_tools.cpp, string_lib.cpp).

Notable bug-class fixes

Acquisition flags in _SEH2_FINALLY blocks — if 0xCCCCCCCC, these appear TRUE and release resources never acquired:

// Before
BOOLEAN Acquired;
Acquired = UDFAcquireResourceExclusiveWithCheck(...);
// ...
_SEH2_FINALLY {
    if (Acquired)  // 0xCCCCCCCC == TRUE if exception before assignment
        UDFReleaseResource(...);
}

// After
BOOLEAN Acquired = FALSE;

UDFSetRenameInfo countersDirRefCount, FileInfoRefCount, IgnoreCase, UseClose used in loop logic before guaranteed assignment.

Include/ support librariesNTSTATUS return values, BOOLEAN status flags, ULONG loop/search variables, and pointer variables in phys_lib.cpp, regtools.cpp, mem_tools.cpp, Sys_spec_lib.cpp, and string_lib.cpp.

Copilot AI linked an issue Apr 6, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix code to prevent MSVC from filling with 0xCCCCCCCC [UDFS] Initialize all local variables to prevent 0xCCCCCCCC in MSVC debug builds Apr 6, 2026
Copilot AI requested a review from Zero3K20 April 6, 2026 18:15
@Zero3K20
Copy link
Copy Markdown
Owner

Zero3K20 commented Apr 6, 2026

@copilot What about the code in the Include directory?

Copy link
Copy Markdown
Author

Copilot AI commented Apr 6, 2026

@copilot What about the code in the Include directory?

Done — commit 7459fd0 initializes all uninitialized local variables in the Include/ directory:

  • Sys_spec_lib.cpp: NTSTATUS status/RC, pointer vars (attr, Flags, Type, FCharact)
  • phys_lib.cpp: NTSTATUS Status/status (6 occurrences), ULONG LocalTrackCount, TocEntry, OldTrkNum, TrkNum, ReadBytes, _ReadBytes, inline SessionStart/SessionEnd
  • regtools.cpp: NTSTATUS status (3 occurrences), ULONG len
  • mem_tools.cpp: BOOLEAN Used, global ULONG FrameCount/LastFrame/MemTotalAllocated, all local ULONG loop/search variables
  • string_lib.cpp: ULONG i

Zero3K20 and others added 5 commits April 27, 2026 01:45
Initialize all uninitialized local variables in the UDFS driver to
prevent MSVC debug builds from filling them with 0xCCCCCCCC:
- NTSTATUS/NTSTATUS variables initialized to STATUS_SUCCESS
- BOOLEAN variables initialized to FALSE
- ULONG/pointer variables initialized to 0/NULL

Also restore accidentally removed code:
- if (!FileInfo) check in UDFIndexDirectory (dirtree.cpp)
- PUDF_FILE_INFO curFileInfo declaration in UDFPackDirectory__ (dirtree.cpp)
- PAGED_CODE() calls in misc.cpp and volinfo.cpp
- Comment in misc.cpp AcquireResource function

Agent-Logs-Url: https://github.com/Zero3K20/reactos/sessions/901376db-4acd-42eb-8122-cce62735117e

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
Initialize all uninitialized local variables in the Include/ support
files: Sys_spec_lib.cpp, phys_lib.cpp, regtools.cpp, mem_tools.cpp,
string_lib.cpp. Covers NTSTATUS, BOOLEAN, ULONG, and pointer variables.

Agent-Logs-Url: https://github.com/Zero3K20/reactos/sessions/a5f32228-fa19-4fba-bf7a-cdde18e904ec

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
@Zero3K20 Zero3K20 force-pushed the copilot/udfs-fix-code branch from 7459fd0 to 39968cb Compare April 27, 2026 06:06
@Zero3K20 Zero3K20 changed the base branch from write to udf-dev April 27, 2026 06:44
Copilot AI added a commit that referenced this pull request May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[UDFS] Fix all code so MSVC doesn’t fill them with 0xCCCCCCCC

3 participants