Skip to content

Fix 64-bit type casting and truncation issues - #762

Merged
rsmarples merged 4 commits into
NetworkConfiguration:masterfrom
GermanAizek:fix-static-analyzer-64bit
Nov 20, 2026
Merged

rsmarples merged 4 commits into
NetworkConfiguration:masterfrom
GermanAizek:fix-static-analyzer-64bit

Conversation

@GermanAizek

Copy link
Copy Markdown
Contributor

This continue first PR program "Patch the Planet" #761

I divided this PR because this is more about the compatibility 32‑bit/64‑bit systems.

1. src/dhcpcd.h: Use uintptr_t in ALIGN macro

  • Problem: The fallback ALIGN(p) macro cast p to (unsigned int):
    #define ALIGN(p) (((unsigned int)(p) + ALIGNBYTES) & ~ALIGNBYTES)
    In src/privsep-root.c, this macro is used to compute alignment for buffer sizes (size_t) and pointers (uint8_t * / bp). On 64-bit systems, casting to unsigned int truncates 64-bit pointers and size_t values to 32 bits.

  • Fix: Redefined ALIGN(p) to use uintptr_t (matching BSD <sys/param.h> semantics) and included <stdint.h>:
    #define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) & ~(uintptr_t)ALIGNBYTES)

2. src/auth.c: Cast return value to ssize_t in dhcp_auth_encode

  • Problem: dhcp_auth_encode returns ssize_t, and dlen is size_t. Line 756 cast (dlen - sizeof(hmac_code)) to (int) before returning, causing a 64-bit size_t difference to be truncated to a 32-bit int prior to promotion to ssize_t
  • Fix: Changed the return cast to (ssize_t)(dlen - sizeof(hmac_code)) to match the function signature and the other return statements in the function

3. src/dhcp.c: Remove redundant int cast in VIVSO option size check

  • Problem: pl is size_t. The check pl <= (int)sizeof(uint32_t) cast sizeof(uint32_t) to a signed 32-bit int, causing unnecessary size_t -> int -> size_t conversions and a signed/unsigned comparison.
  • Fix: Removed the (int) cast: pl <= sizeof(uint32_t)

4. src/if-options.c: Change u to uint32_t in parse_option

  • Problem: unsigned long u was declared at the top of parse_option, but was only used to store 32-bit unsigned values (uint32_t enterprise numbers and DHCP option codes). This caused unnecessary conversions (uintmax_t from strtou -> uint32_t -> unsigned long -> (uint32_t)u)
  • Fix: Declared uint32_t u; and removed redundant (uint32_t) casts at assignment/comparison points.

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The changes update integer types in DHCP option parsing, pointer alignment, and authentication length handling. They also remove an int cast from a DHCP option length comparison.

Changes

DHCP integer type updates

Layer / File(s) Summary
Header integer types
src/dhcpcd.h
The header includes <stdint.h>. The ALIGN(p) macro uses uintptr_t for its alignment calculation.
Option parsing integer types
src/if-options.c
parse_option stores parsed values in uint32_t. Enterprise-number comparisons and assignments, and DHCP option assignment, use that value without redundant casts.
DHCP length and return types
src/auth.c, src/dhcp.c
dhcp_auth_encode() casts its computed return value to ssize_t. The DHO_VIVSO length check compares pl with sizeof(uint32_t) without casting the size to int.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: rsmarples

Merge Risk: Minimal · up to d066a

This change fixes integer type handling for 32-bit and 64-bit compatibility in DHCP option parsing, alignment, and authentication. No concrete regression was identified, and the risk of merging is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main theme of the changeset: fixing 64-bit type casting and truncation problems. The four changes in src/dhcpcd.h, src/auth.c, src/dhcp.c and src/if-options.c all remove casts that…
Description check Passed The description relates directly to the changeset. It explains the 32-bit/64-bit compatibility goal and describes each of the four edits: the ALIGN macro in src/dhcpcd.h, the return cast in src/auth.c…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main theme of the changeset: fixing 64-bit type casting and truncation problems. The four changes in src/dhcpcd.h, src/auth.c, src/dhcp.c and src/if-options.c all remove casts that truncate size_t or pointer values on 64-bit systems, so the title matches the change.

Full details: Description check

Explanation

The description relates directly to the changeset. It explains the 32-bit/64-bit compatibility goal and describes each of the four edits: the ALIGN macro in src/dhcpcd.h, the return cast in src/auth.c, the VIVSO size check in src/dhcp.c, and the u type change in src/if-options.c.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b05b0843-b1bb-48da-a57a-4d8c7937e6f3
Commits

Reviewing files that changed from the base of the PR and between 3d33a7c and d066ac1.

Files selected for processing: 4

  • src/auth.c
  • src/dhcp.c
  • src/dhcpcd.h
  • src/if-options.c

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@rsmarples

Copy link
Copy Markdown
Member

Looks good to me, thanks!

@rsmarples
rsmarples merged commit e2ad2ce into NetworkConfiguration:master Nov 20, 2026
18 checks passed
@GermanAizek

Copy link
Copy Markdown
Contributor Author

Looks good to me, thanks!

Thank you for your cooperation; I’m glad to get a quick response.

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