Skip to content

(release/25.2) xf86: prevent passing NULL pointer as strcpy destination - #3567

Open
metux wants to merge 1 commit into
release/25.2from
pr/release/25.2-xf86-prevent-passing-null-pointer-as-strcpy-destination-_2026-08-20_15-41-36
Open

(release/25.2) xf86: prevent passing NULL pointer as strcpy destination#3567
metux wants to merge 1 commit into
release/25.2from
pr/release/25.2-xf86-prevent-passing-null-pointer-as-strcpy-destination-_2026-08-20_15-41-36

Conversation

@metux

@metux metux commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Backport of #3567 (master)

Reported by gcc 16.1:
hw/xfree86/common/xf86Configure.c:463:9: warning: use of NULL where non-null
expected [CWE-476] [-Wanalyzer-null-argument]
463 | strcpy(ptr->mon_modelname, (char *) (det_mon->section.name));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
‘handle_detailed_input’: events 1-5
458 | switch (det_mon->type) {
| ^~~~~~
| |
| (1) following ‘case 252:’ branch... ─>─┐
| │
| │
|┌───────────────────────────────────────────┘
459 |│ case DS_NAME:
|│ ~~~~
|│ |
|└───>(2) ...to here
460 | ptr->mon_modelname = realloc(ptr->mon_modelname,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| | (3) when ‘realloc’ fails
| (4) using NULL here
461 | strlen((char *) (det_mon->section.name)) +
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
462 | 1);
| ~~
463 | strcpy(ptr->mon_modelname, (char ) (det_mon->section.name));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| (5) ⚠ argument 1 (‘realloc(
(struct *)data.mon_modelname, strlen(&*det_mon.section.name) + 1)’) NULL where non-null expected

note: argument 1 of ‘strcpy’ must be non-null

Signed-off-by: Alan Coopersmith alan.coopersmith@oracle.com
Part-of: https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2272

@metux metux self-assigned this Aug 20, 2026
@metux
metux requested a review from a team August 20, 2026 13:43
metux pushed a commit that referenced this pull request Aug 20, 2026
Reported by gcc 16.1:
hw/xfree86/common/xf86Configure.c:463:9: warning: use of NULL where non-null
 expected [CWE-476] [-Wanalyzer-null-argument]
  463 |         strcpy(ptr->mon_modelname, (char *) (det_mon->section.name));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ‘handle_detailed_input’: events 1-5
  458 |     switch (det_mon->type) {
      |     ^~~~~~
      |     |
      |     (1) following ‘case 252:’ branch... ─>─┐
      |                                            │
      |                                            │
      |┌───────────────────────────────────────────┘
  459 |│    case DS_NAME:
      |│    ~~~~
      |│    |
      |└───>(2) ...to here
  460 |         ptr->mon_modelname = realloc(ptr->mon_modelname,
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                            | |
      |                            | (3) when ‘realloc’ fails
      |                            (4) using NULL here
  461 |                                      strlen((char *) (det_mon->section.name)) +
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  462 |                                      1);
      |                                      ~~
  463 |         strcpy(ptr->mon_modelname, (char *) (det_mon->section.name));
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |         |
      |         (5) ⚠  argument 1 (‘realloc(*(struct <anonymous> *)data.mon_modelname,  strlen(&*det_mon.section.name) + 1)’) NULL where non-null expected

note: argument 1 of ‘strcpy’ must be non-null

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2272>
PR: #3567
@metux

metux commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Automated review — generated by Starfleet ship Discovery on behalf of @metux. Not a human review.

Clean one-liner fix — no objections.

What it does: replaces bare realloc() with XNFrealloc() in the EDID monitor-name parsing path (handle_detailed_input, DS_NAME case). XNFrealloc is the standard X pattern for non-recoverable allocations — it aborts the server cleanly on OOM instead of returning NULL and crashing on the subsequent strcpy.

ABI impact: none. No struct layout changes, no export changes. NVIDIA blobs unaffected.

Backport candidate: yes — NULL-dereference / crash fix (CWE-476). Likely applies to release/25.1 and release/25.0 as well. Applicability per branch to be confirmed — maintainer decides.

Verdict: passes review.

@metux metux added the bot-review-passed Automated bot review found no blocking issues label Aug 20, 2026
Reported by gcc 16.1:
hw/xfree86/common/xf86Configure.c:463:9: warning: use of NULL where non-null
 expected [CWE-476] [-Wanalyzer-null-argument]
  463 |         strcpy(ptr->mon_modelname, (char *) (det_mon->section.name));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ‘handle_detailed_input’: events 1-5
  458 |     switch (det_mon->type) {
      |     ^~~~~~
      |     |
      |     (1) following ‘case 252:’ branch... ─>─┐
      |                                            │
      |                                            │
      |┌───────────────────────────────────────────┘
  459 |│    case DS_NAME:
      |│    ~~~~
      |│    |
      |└───>(2) ...to here
  460 |         ptr->mon_modelname = realloc(ptr->mon_modelname,
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                            | |
      |                            | (3) when ‘realloc’ fails
      |                            (4) using NULL here
  461 |                                      strlen((char *) (det_mon->section.name)) +
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  462 |                                      1);
      |                                      ~~
  463 |         strcpy(ptr->mon_modelname, (char *) (det_mon->section.name));
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |         |
      |         (5) ⚠  argument 1 (‘realloc(*(struct <anonymous> *)data.mon_modelname,  strlen(&*det_mon.section.name) + 1)’) NULL where non-null expected

note: argument 1 of ‘strcpy’ must be non-null

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2272>
@metux
metux force-pushed the pr/release/25.2-xf86-prevent-passing-null-pointer-as-strcpy-destination-_2026-08-20_15-41-36 branch from 6b9c6c0 to ef19ca3 Compare August 24, 2026 12:02
metux pushed a commit that referenced this pull request Aug 25, 2026
Reported by gcc 16.1:
hw/xfree86/common/xf86Configure.c:463:9: warning: use of NULL where non-null
 expected [CWE-476] [-Wanalyzer-null-argument]
  463 |         strcpy(ptr->mon_modelname, (char *) (det_mon->section.name));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ‘handle_detailed_input’: events 1-5
  458 |     switch (det_mon->type) {
      |     ^~~~~~
      |     |
      |     (1) following ‘case 252:’ branch... ─>─┐
      |                                            │
      |                                            │
      |┌───────────────────────────────────────────┘
  459 |│    case DS_NAME:
      |│    ~~~~
      |│    |
      |└───>(2) ...to here
  460 |         ptr->mon_modelname = realloc(ptr->mon_modelname,
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                            | |
      |                            | (3) when ‘realloc’ fails
      |                            (4) using NULL here
  461 |                                      strlen((char *) (det_mon->section.name)) +
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  462 |                                      1);
      |                                      ~~
  463 |         strcpy(ptr->mon_modelname, (char *) (det_mon->section.name));
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |         |
      |         (5) ⚠  argument 1 (‘realloc(*(struct <anonymous> *)data.mon_modelname,  strlen(&*det_mon.section.name) + 1)’) NULL where non-null expected

note: argument 1 of ‘strcpy’ must be non-null

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2272>
PR: #3567
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-review-passed Automated bot review found no blocking issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants