Skip to content

fix: stop ctlwizchip() from dereferencing NULL arguments (AUD-005) - #184

Open
occamsshavingkit wants to merge 1 commit into
Wiznet:masterfrom
occamsshavingkit:fix/aud-005-ctlwizchip-null-deref
Open

fix: stop ctlwizchip() from dereferencing NULL arguments (AUD-005)#184
occamsshavingkit wants to merge 1 commit into
Wiznet:masterfrom
occamsshavingkit:fix/aud-005-ctlwizchip-null-deref

Conversation

@occamsshavingkit

Copy link
Copy Markdown

Summary

Fixes unconditional NULL dereference in ctlwizchip() for documented no-argument commands.

Problem

Ethernet/wizchip_conf.c:436 unconditionally evaluated uint8_t tmp = *(uint8_t*) arg before dispatching to the command case:

int8_t ctlwizchip(ctlwizchip_type cwtype, void* arg) {
    uint8_t tmp = *(uint8_t*) arg;   // <-- dereferences before dispatch
    ...
    case CW_RESET_WIZCHIP:            // requires no argument
        wizchip_sw_reset();
        break;
    case CW_INIT_WIZCHIP:             // explicitly supports arg == NULL
        if (arg != 0) { ... }

CW_RESET_WIZCHIP requires no argument and CW_INIT_WIZCHIP explicitly supports arg == NULL for default socket buffers, so a documented no-argument call could dereference NULL.

Fix

  • Remove the unconditional uint8_t tmp = *(uint8_t*) arg at the top of the function
  • Move guarded dereferences inside only the cases that require arg:
    • CW_SYS_LOCK, CW_SYS_UNLOCK, CW_GET_SYSLOCK (W6100/W6300)
    • CW_GET_PHYPOWMODE, CW_GET_PHYLINK (W5100S/W5200/W5500/W6100/W6300)
  • Each case returns -1 when arg == NULL
  • CW_RESET_WIZCHIP and CW_INIT_WIZCHIP proceed without dereferencing

Verification

  • Multi-chip compile check: passes for all 7 _WIZCHIP_ values
  • ASan/UBSan: ctlwizchip(CW_RESET_WIZCHIP, NULL) and ctlwizchip(CW_INIT_WIZCHIP, NULL) do not fault; CW_SYS_LOCK with NULL returns -1

ctlwizchip() unconditionally evaluated uint8_t tmp = *(uint8_t*)arg
before dispatching to the command case. CW_RESET_WIZCHIP requires no
argument and CW_INIT_WIZCHIP explicitly supports arg == NULL for default
socket buffers, so a documented no-argument call could dereference NULL.

Fix: remove the unconditional dereference and move guarded reads into
only the cases that require arg (CW_SYS_LOCK, CW_SYS_UNLOCK,
CW_GET_SYSLOCK, CW_GET_PHYPOWMODE, CW_GET_PHYLINK). Each case returns
-1 when arg == NULL. No-argument and default-argument commands proceed
without dereferencing.
niansa added a commit to niansa/ioLibrary_Driver that referenced this pull request Jul 29, 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.

1 participant