mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-18 20:10:29 +01:00
WPrefs: fix memory leak and potential buffer overflow
Coverity pointed that the "text" returned by WMGetTextFieldText was never freed (CID #331578, because WMSetTextFieldText does its own copy, it does not take the pointer as-is). By looking at the code, there is also a potential buffer overflow because the buffer alloc'd for "value" is sized for the exact number of digits before increase, but the +delta can make the number use more digits so we may write past the end of original buffer. We write to a stack-allocated one, so it does not cost anything and does not participates to memory fragmentation. Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
committed by
Carlos R. Mafra
parent
58862300f9
commit
fd56152202
@@ -146,15 +146,16 @@ typedef struct _Panel {
|
||||
static void changeIntTextfield(void *data, int delta)
|
||||
{
|
||||
WMTextField *textfield;
|
||||
char *text;
|
||||
char *text, buffer[12];
|
||||
int value;
|
||||
|
||||
textfield = (WMTextField *)data;
|
||||
text = WMGetTextFieldText(textfield);
|
||||
value = atoi(text);
|
||||
wfree(text);
|
||||
value += delta;
|
||||
sprintf(text, "%d", value);
|
||||
WMSetTextFieldText(textfield, text);
|
||||
sprintf(buffer, "%d", value);
|
||||
WMSetTextFieldText(textfield, buffer);
|
||||
}
|
||||
|
||||
static void downButtonCallback(WMWidget *self, void *data)
|
||||
|
||||
Reference in New Issue
Block a user