Update OutputClass.c to Fix Double Free found in CodeQL

added the newpath variable and restructured if else loop with a strdup(xf86_lex_val.str); to populate newpath separately to avoid bug
This commit is contained in:
Collin 2025-06-26 20:07:17 -05:00 committed by GitHub
parent 3e1c2d5456
commit 005b26456b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -123,16 +123,21 @@ xf86parseOutputClassSection(void)
ptr->driver = xf86_lex_val.str;
break;
case MODULEPATH:
if (xf86getSubToken(&(ptr->comment)) != XF86_TOKEN_STRING)
if (xf86getSubToken(&ptr->comment) != XF86_TOKEN_STRING)
Error(QUOTE_MSG, "ModulePath");
{
char *newpath;
if (ptr->modulepath) {
char *path;
XNFasprintf(&path, "%s,%s", ptr->modulepath, xf86_lex_val.str);
free(xf86_lex_val.str);
free(ptr->modulepath);
ptr->modulepath = path;
} else {
ptr->modulepath = xf86_lex_val.str;
XNFasprintf(&newpath, "%s,%s",
ptr->modulepath,
xf86_lex_val.str);
free(ptr->modulepath);
}
else {
newpath = strdup(xf86_lex_val.str);
}
free(xf86_lex_val.str);
ptr->modulepath = newpath;
}
break;
case OPTION: