Compare commits

...

3 Commits

Author SHA1 Message Date
Enrico Weigelt, metux IT consult 51f72b2a7f xkb: fix uninitialized variables in XkmReadFile()
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-05-14 18:40:01 +02:00
Enrico Weigelt, metux IT consult 3ed3a47f76 xkb: maprules: fix potential NULL pointer dereference warnings
Even though the cases might be hypothetical, it's still better having some
tiny extra checks (that might be even optimized-out) and reduce the analyzer
noise a bit.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-05-14 18:39:59 +02:00
Enrico Weigelt, metux IT consult 39a52b1e03 xkb: fix NULL pointer dereference in XkbDDXLoadKeymapByNames()
In the rare case that NULL kbd is passed and also no components provided,
the corresponding error message code crashes on NULL pointer dereference.

| ../xkb/ddxLoad.c: In function ‘XkbDDXLoadKeymapByNames’:
| ../xkb/ddxLoad.c:393:25: warning: dereference of NULL ‘keybd’ [CWE-476] [-Wanalyzer-null-dereference]
|   393 |                    keybd->name ? keybd->name : "(unnamed keyboard)");
|       |                    ~~~~~^~~~~~

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-05-14 18:19:06 +02:00
3 changed files with 6 additions and 4 deletions

View File

@ -389,7 +389,7 @@ XkbDDXLoadKeymapByNames(DeviceIntPtr keybd,
(names->compat == NULL) && (names->symbols == NULL) && (names->compat == NULL) && (names->symbols == NULL) &&
(names->geometry == NULL)) { (names->geometry == NULL)) {
LogMessage(X_ERROR, "XKB: No components provided for device %s\n", LogMessage(X_ERROR, "XKB: No components provided for device %s\n",
keybd->name ? keybd->name : "(unnamed keyboard)"); keybd && keybd->name ? keybd->name : "(unnamed keyboard)");
return 0; return 0;
} }
else if (!XkbDDXCompileKeymapByNames(xkb, names, want, need, else if (!XkbDDXCompileKeymapByNames(xkb, names, want, need,

View File

@ -93,7 +93,9 @@ InputLineAddChar(InputLine * line, int ch)
{ {
if (line->num_line >= line->sz_line) { if (line->num_line >= line->sz_line) {
if (line->line == line->buf) { if (line->line == line->buf) {
line->line = xallocarray(line->sz_line, 2); line->line = calloc(line->sz_line, 2);
if (line->line == NULL)
return -1;
memcpy(line->line, line->buf, line->sz_line); memcpy(line->line, line->buf, line->sz_line);
} }
else { else {
@ -379,7 +381,7 @@ CheckLine(InputLine * line,
_Xstrtokparams strtok_buf; _Xstrtokparams strtok_buf;
Bool append = FALSE; Bool append = FALSE;
if (line->line[0] == '!') { if (line && line->line && line->line[0] == '!') {
if (line->line[1] == '$' || if (line->line[1] == '$' ||
(line->line[1] == ' ' && line->line[2] == '$')) { (line->line[1] == ' ' && line->line[2] == '$')) {
char *gname = strchr(line->line, '$'); char *gname = strchr(line->line, '$');

View File

@ -1209,7 +1209,7 @@ unsigned
XkmReadFile(FILE * file, unsigned need, unsigned want, XkbDescPtr *xkb) XkmReadFile(FILE * file, unsigned need, unsigned want, XkbDescPtr *xkb)
{ {
register unsigned i; register unsigned i;
xkmSectionInfo toc[MAX_TOC], tmpTOC; xkmSectionInfo toc[MAX_TOC] = { 0 }, tmpTOC = { 0 };
xkmFileInfo fileInfo; xkmFileInfo fileInfo;
unsigned tmp, nRead = 0; unsigned tmp, nRead = 0;
unsigned which = need | want; unsigned which = need | want;