Skip to content

(release/25.1) xf86: prevent passing NULL pointer as strcat() destination - #3588

Open
metux wants to merge 1 commit into
release/25.1from
pr/release/25.1-xf86-prevent-passing-null-pointer-as-strcat-destination-_2026-08-20_16-17-53
Open

(release/25.1) xf86: prevent passing NULL pointer as strcat() destination#3588
metux wants to merge 1 commit into
release/25.1from
pr/release/25.1-xf86-prevent-passing-null-pointer-as-strcat-destination-_2026-08-20_16-17-53

Conversation

@metux

@metux metux commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Reported by gcc 16.1:
hw/xfree86/parser/Files.c:119:17: warning: use of NULL where non-null
expected [CWE-476] [-Wanalyzer-null-argument]
119 | strcat(ptr->file_fontpath, ",");
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
117 | ptr->file_fontpath = realloc(ptr->file_fontpath, i);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| | (9) when ‘realloc’ fails
| (10) using NULL here
118 | if (j)
| ~
| |
| (11) following ‘true’ branch (when ‘j != 0’)... ─>─┐
| │
| │
|┌──────────────────────────────────────────────────────────────────┘
119 |│ strcat(ptr->file_fontpath, ",");
|│ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|│ |
|└───────────────>(12) ...to here
| (13) ⚠ argument 1 (‘realloc(*ptr.file_fontpath, (long unsigned int)i)’) NULL where non-null expected
: note: argument 1 of ‘__builtin_strlen’ must be non-null
......
| │
|┌──────────────────────────────────────────────────────────────────┘
121 |│ strcat(ptr->file_fontpath, str);
|│ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|│ | |
|│ | (10) using NULL here
|└───────────>(9) ...to here
| (11) ⚠ argument 1 (‘*ptr.file_fontpath’) NULL where non-null expected
note: argument 1 of ‘strcat’ must be non-null

hw/xfree86/parser/Files.c:144:17: warning: use of NULL where non-null expected [CWE-476] [-Wanalyzer-null-argument]
144 | strcat(ptr->file_modulepath, ",");
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
142 | ptr->file_modulepath = realloc(ptr->file_modulepath, k);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| | (9) when ‘realloc’ fails
| (10) using NULL here
143 | if (l)
| ~
| |
| (11) following ‘true’ branch (when ‘l != 0’)... ─>─┐
| │
| │
|┌──────────────────────────────────────────────────────────────────┘
144 |│ strcat(ptr->file_modulepath, ",");
|│ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|│ |
|└───────────────>(12) ...to here
| (13) ⚠ argument 1 (‘realloc(*ptr.file_modulepath, (long unsigned int)k)’) NULL where non-null expected
: note: argument 1 of ‘__builtin_strlen’ must be non-null
......
| │
|┌──────────────────────────────────────────────────────────────────┘
146 |│ strcat(ptr->file_modulepath, str);
|│ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|│ | |
|│ | (10) using NULL here
|└───────────>(9) ...to here
| (11) ⚠ argument 1 (‘*ptr.file_modulepath’) NULL where non-null expected
note: argument 1 of ‘strcat’ must be non-null

Also clears two -Wanalyzer-malloc-leak warnings for leaking the old
pointer when realloc() failed, now that realloc() cannot fail.

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

Reported by gcc 16.1:
hw/xfree86/parser/Files.c:119:17: warning: use of NULL where non-null
 expected [CWE-476] [-Wanalyzer-null-argument]
  119 |                 strcat(ptr->file_fontpath, ",");
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
  117 |             ptr->file_fontpath = realloc(ptr->file_fontpath, i);
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                | |
      |                                | (9) when ‘realloc’ fails
      |                                (10) using NULL here
  118 |             if (j)
      |                ~
      |                |
      |                (11) following ‘true’ branch (when ‘j != 0’)... ─>─┐
      |                                                                   │
      |                                                                   │
      |┌──────────────────────────────────────────────────────────────────┘
  119 |│                strcat(ptr->file_fontpath, ",");
      |│                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |│                |
      |└───────────────>(12) ...to here
      |                 (13) ⚠  argument 1 (‘realloc(*ptr.file_fontpath, (long unsigned int)i)’) NULL where non-null expected
<built-in>: note: argument 1 of ‘__builtin_strlen’ must be non-null
......
      |                                                                   │
      |┌──────────────────────────────────────────────────────────────────┘
  121 |│            strcat(ptr->file_fontpath, str);
      |│            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |│            |         |
      |│            |         (10) using NULL here
      |└───────────>(9) ...to here
      |             (11) ⚠  argument 1 (‘*ptr.file_fontpath’) NULL where non-null expected
note: argument 1 of ‘strcat’ must be non-null

hw/xfree86/parser/Files.c:144:17: warning: use of NULL where non-null expected [CWE-476] [-Wanalyzer-null-argument]
  144 |                 strcat(ptr->file_modulepath, ",");
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
  142 |             ptr->file_modulepath = realloc(ptr->file_modulepath, k);
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                  | |
      |                                  | (9) when ‘realloc’ fails
      |                                  (10) using NULL here
  143 |             if (l)
      |                ~
      |                |
      |                (11) following ‘true’ branch (when ‘l != 0’)... ─>─┐
      |                                                                   │
      |                                                                   │
      |┌──────────────────────────────────────────────────────────────────┘
  144 |│                strcat(ptr->file_modulepath, ",");
      |│                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |│                |
      |└───────────────>(12) ...to here
      |                 (13) ⚠  argument 1 (‘realloc(*ptr.file_modulepath, (long unsigned int)k)’) NULL where non-null expected
<built-in>: note: argument 1 of ‘__builtin_strlen’ must be non-null
......
      |                                                                   │
      |┌──────────────────────────────────────────────────────────────────┘
  146 |│            strcat(ptr->file_modulepath, str);
      |│            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |│            |         |
      |│            |         (10) using NULL here
      |└───────────>(9) ...to here
      |             (11) ⚠  argument 1 (‘*ptr.file_modulepath’) NULL where non-null expected
note: argument 1 of ‘strcat’ must be non-null

Also clears two -Wanalyzer-malloc-leak warnings for leaking the old
pointer when realloc() failed, now that realloc() cannot fail.

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 14:19
metux pushed a commit that referenced this pull request Aug 20, 2026
Reported by gcc 16.1:
hw/xfree86/parser/Files.c:119:17: warning: use of NULL where non-null
 expected [CWE-476] [-Wanalyzer-null-argument]
  119 |                 strcat(ptr->file_fontpath, ",");
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
  117 |             ptr->file_fontpath = realloc(ptr->file_fontpath, i);
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                | |
      |                                | (9) when ‘realloc’ fails
      |                                (10) using NULL here
  118 |             if (j)
      |                ~
      |                |
      |                (11) following ‘true’ branch (when ‘j != 0’)... ─>─┐
      |                                                                   │
      |                                                                   │
      |┌──────────────────────────────────────────────────────────────────┘
  119 |│                strcat(ptr->file_fontpath, ",");
      |│                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |│                |
      |└───────────────>(12) ...to here
      |                 (13) ⚠  argument 1 (‘realloc(*ptr.file_fontpath, (long unsigned int)i)’) NULL where non-null expected
<built-in>: note: argument 1 of ‘__builtin_strlen’ must be non-null
......
      |                                                                   │
      |┌──────────────────────────────────────────────────────────────────┘
  121 |│            strcat(ptr->file_fontpath, str);
      |│            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |│            |         |
      |│            |         (10) using NULL here
      |└───────────>(9) ...to here
      |             (11) ⚠  argument 1 (‘*ptr.file_fontpath’) NULL where non-null expected
note: argument 1 of ‘strcat’ must be non-null

hw/xfree86/parser/Files.c:144:17: warning: use of NULL where non-null expected [CWE-476] [-Wanalyzer-null-argument]
  144 |                 strcat(ptr->file_modulepath, ",");
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
  142 |             ptr->file_modulepath = realloc(ptr->file_modulepath, k);
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                  | |
      |                                  | (9) when ‘realloc’ fails
      |                                  (10) using NULL here
  143 |             if (l)
      |                ~
      |                |
      |                (11) following ‘true’ branch (when ‘l != 0’)... ─>─┐
      |                                                                   │
      |                                                                   │
      |┌──────────────────────────────────────────────────────────────────┘
  144 |│                strcat(ptr->file_modulepath, ",");
      |│                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |│                |
      |└───────────────>(12) ...to here
      |                 (13) ⚠  argument 1 (‘realloc(*ptr.file_modulepath, (long unsigned int)k)’) NULL where non-null expected
<built-in>: note: argument 1 of ‘__builtin_strlen’ must be non-null
......
      |                                                                   │
      |┌──────────────────────────────────────────────────────────────────┘
  146 |│            strcat(ptr->file_modulepath, str);
      |│            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |│            |         |
      |│            |         (10) using NULL here
      |└───────────>(9) ...to here
      |             (11) ⚠  argument 1 (‘*ptr.file_modulepath’) NULL where non-null expected
note: argument 1 of ‘strcat’ must be non-null

Also clears two -Wanalyzer-malloc-leak warnings for leaking the old
pointer when realloc() failed, now that realloc() cannot fail.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2272>
PR: #3588
@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 companion fix to #3567 — no objections.

What it does: replaces bare realloc() + assert() with XNFrealloc() in two font/module path allocation sites in xf86parseFilesSection(). Same pattern as PR #3567 (strcpy case in xf86Configure.c): XNFrealloc aborts on OOM, eliminating the NULL-dereference on strcat() and the malloc-leak on realloc failure. Also adds #include "os.h" for the XNFrealloc declaration.

Fixes gcc 16.1 warnings:

  • Two -Wanalyzer-null-argument (realloc NULL passed to strcat)
  • Two -Wanalyzer-malloc-leak (old pointer leaked when realloc failed)

ABI impact: none. Parser-internal, no struct or export changes.

Backport candidate: yes — NULL-dereference fix (CWE-476), same rationale as #3567. Likely applies to release/25.0 as well.

Verdict: passes review.

@metux metux added the bot-review-passed Automated bot review found no blocking issues label Aug 20, 2026
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