(release/25.0) xf86: prevent passing NULL pointer as strcat() destination - #3602
Open
metux wants to merge 1 commit into
Conversation
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
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
Contributor
Author
Clean fix. Replaces
The ABI: |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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