You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix 64-bit type casting and truncation issues - #762
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.
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.
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: 4
Check name
Status
Explanation
Title check
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
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
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
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.
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.
Thank you for your cooperation; I’m glad to get a quick response.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
3. src/dhcp.c: Remove redundant int cast in VIVSO option size check
4. src/if-options.c: Change u to uint32_t in parse_option