Skip to content

Refactor: Use symbolic constants for volume header magic numbers #1525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

bernardladenthin
Copy link
Contributor

Changes

  • Replaced hardcoded 0x56455241 ('VERA') with TC_HEADER_MAGIC for improved readability and maintainability.
  • Moved existing constant TC_BOOT_DRIVE_FILTER_EXTENSION_MAGIC_NUMBER (64-bit "VERABEXT").
  • Ensured usage of ULL suffix for 64-bit constant correctness.

Replaced hardcoded 0x56455241 ('VERA') with TC_HEADER_MAGIC for better readability and maintainability.
Also replaced 0x5645524142455854 with TC_BOOT_DRIVE_FILTER_EXTENSION_MAGIC and added 'ULL' suffix for 64-bit safety.
@idrassi idrassi requested a review from Copilot April 21, 2025 08:10
Copy link

@Copilot 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

This PR refactors hardcoded volume header magic numbers by replacing them with symbolic constants, improving code readability and maintainability. Key changes include:

  • Replacing hardcoded 32‑bit magic numbers with the TC_HEADER_MAGIC_NUMBER constant in multiple source files.
  • Removing the redundant definition of TC_BOOT_DRIVE_FILTER_EXTENSION_MAGIC_NUMBER from src/Driver/DriveFilter.h.
  • Updating the corresponding comments and ensuring the 64‑bit constant uses the ULL suffix in src/Common/Volumes.h.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Format/InPlace.c Updated magic number check to use TC_HEADER_MAGIC_NUMBER
src/Driver/DriveFilter.h Removed redundant TC_BOOT_DRIVE_FILTER_EXTENSION_MAGIC_NUMBER definition
src/Driver/DriveFilter.c Replaced hardcoded magic value with TC_HEADER_MAGIC_NUMBER
src/Common/Volumes.h Introduced symbolic constants with proper ULL suffix for magic numbers
src/Common/Volumes.c Replaced hardcoded magic values with symbolic constants and updated comments
src/Common/BootEncryption.cpp Replaced hardcoded magic value with TC_HEADER_MAGIC_NUMBER
Comments suppressed due to low confidence (2)

src/Driver/DriveFilter.h:51

  • Ensure that the removal of this macro does not break references to TC_BOOT_DRIVE_FILTER_EXTENSION_MAGIC_NUMBER. Verify that all files now include 'src/Common/Volumes.h' where the new definition is provided.
#define TC_BOOT_DRIVE_FILTER_EXTENSION_MAGIC_NUMBER 0x5645524142455854

src/Common/Volumes.c:461

  • [nitpick] Consider updating the preceding comment to explicitly mention that 'TC_HEADER_MAGIC_NUMBER' is being used as the volume header identifier, reinforcing the connection between the comment and the symbolic constant.
if (GetHeaderField32 (header, TC_HEADER_OFFSET_MAGIC) != TC_HEADER_MAGIC_NUMBER)

@idrassi
Copy link
Member

idrassi commented Apr 21, 2025

Thank you for your contribution. It makes the code clearer.

@idrassi idrassi merged commit 5eb358c into veracrypt:master Apr 21, 2025
1 check passed
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.

2 participants