1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-18 20:10:29 +01:00

WPrefs: fix NULL pointer dereference in the Pixmap/Icon path panel (Coverity #50073 + #50150)

As pointed by Coverity, it is possible to dereference the NULL pointer in
the function 'browseForFile'.
This should have been reported by the compiler ("possible use of
uninitialised variable") but the assignation of a default value to the
variable 'lPtr' hides this, but as the default value is not a good one then
the code could crash.
This patch removes the default value, so we may have some info from the
compiler and handles the case smoothly.

It also fixes a potential memory leak pointed also by Coverity in the
case where the string returned by WMGetFilePanelFileName would be a 0
length non-null string.

Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
Christophe CURIS
2014-05-31 19:58:40 +02:00
committed by Carlos R. Mafra
parent c5744aaa8b
commit 4b7bb5bc5c

View File

@@ -149,22 +149,24 @@ static void browseForFile(WMWidget * w, void *data)
len--;
}
if (len > 0) {
WMList *lPtr = NULL;
WMList *lPtr;
int i;
if (w == panel->icoaB)
lPtr = panel->icoL;
else if (w == panel->pixaB)
lPtr = panel->pixL;
else
goto error_unknown_widget;
i = WMGetListSelectedItemRow(lPtr);
if (i >= 0)
i++;
addPathToList(lPtr, i, str);
WMSetListBottomPosition(lPtr, WMGetListNumberOfRows(lPtr));
wfree(str);
}
error_unknown_widget:
wfree(str);
}
}
}