Skip to content

(release/25.0) xf86: prevent passing NULL pointer as strcat() destination - #3602

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

(release/25.0) xf86: prevent passing NULL pointer as strcat() destination#3602
metux wants to merge 1 commit into
release/25.0from
pr/release/25.0-xf86-prevent-passing-null-pointer-as-strcat-destination-_2026-08-20_16-23-19

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:25
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: #3602
@metux

metux commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

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

Clean fix. Replaces realloc() + assert() with XNFrealloc(), which is the server's no-fail realloc wrapper (aborts via FatalError on OOM instead of returning NULL). This eliminates:

  1. Two -Wanalyzer-null-argument warnings from GCC 16 — the static analyzer traced the realloc-fail → strcat(NULL) path.
  2. Two -Wanalyzer-malloc-leak warnings — the old realloc() pattern leaked the original pointer on failure; XNFrealloc cannot fail, so no leak is possible.

The assert() was redundant with XNFrealloc's FatalError path and is correctly removed.

ABI: xf86parseFilesSection is a static function in the parser. Not exported, not referenced by any NVIDIA blob. ABI-safe.

@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