mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-22 22:28:02 +01:00
WMaker: rewrote generation of title for the Icon Chooser to avoid problems
The original code did have a few weaknesses, including: - possible buffer overflow, if the translation was too long; - possible crash, if either instance or class is NULL but not both Now the appropriate length is calculated (not counting on a margin) and the string is generated with the available elements. As a side note, the variable was renamed from 'tmp' to 'title' for clarity. This was highlighted by cppcheck (thanks to David Maciejak) and by Coverity (bug #50078). Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
committed by
Carlos R. Mafra
parent
aa1ee24fc0
commit
92ecb3c3ed
38
src/dialog.c
38
src/dialog.c
@@ -1011,22 +1011,40 @@ Bool wIconChooserDialog(WScreen *scr, char **file, const char *instance, const c
|
|||||||
XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
|
XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
|
||||||
|
|
||||||
{
|
{
|
||||||
char *tmp;
|
static const char *prefix = NULL;
|
||||||
int len = (instance ? strlen(instance) : 0)
|
char *title;
|
||||||
+ (class ? strlen(class) : 0) + 32;
|
int len;
|
||||||
WMPoint center;
|
WMPoint center;
|
||||||
|
|
||||||
tmp = wmalloc(len);
|
if (prefix == NULL)
|
||||||
|
prefix = _("Icon Chooser");
|
||||||
|
|
||||||
if (tmp && (instance || class))
|
len = strlen(prefix)
|
||||||
snprintf(tmp, len, "%s [%s.%s]", _("Icon Chooser"), instance, class);
|
+ 2 // " ["
|
||||||
else
|
+ (instance ? strlen(instance) : 0)
|
||||||
strcpy(tmp, _("Icon Chooser"));
|
+ 1 // "."
|
||||||
|
+ (class ? strlen(class) : 0)
|
||||||
|
+ 1 // "]"
|
||||||
|
+ 1; // final NUL
|
||||||
|
|
||||||
|
title = wmalloc(len);
|
||||||
|
strcpy(title, prefix);
|
||||||
|
|
||||||
|
if (instance || class) {
|
||||||
|
strcat(title, " [");
|
||||||
|
if (instance != NULL)
|
||||||
|
strcat(title, instance);
|
||||||
|
if (instance && class)
|
||||||
|
strcat(title, ".");
|
||||||
|
if (class != NULL)
|
||||||
|
strcat(title, class);
|
||||||
|
strcat(title, "]");
|
||||||
|
}
|
||||||
|
|
||||||
center = getCenter(scr, 450, 280);
|
center = getCenter(scr, 450, 280);
|
||||||
|
|
||||||
wwin = wManageInternalWindow(scr, parent, None, tmp, center.x, center.y, 450, 280);
|
wwin = wManageInternalWindow(scr, parent, None, title, center.x, center.y, 450, 280);
|
||||||
wfree(tmp);
|
wfree(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* put icon paths in the list */
|
/* put icon paths in the list */
|
||||||
|
|||||||
Reference in New Issue
Block a user