Add str len check in config_sortlist to avoid stack overflow - #497
Conversation
In ares_set_sortlist, it calls config_sortlist(..., sortstr) to parse the input str and initialize a sortlist configuration. However, ares_set_sortlist has not any checks about the validity of the input str. It is very easy to create an arbitrary length stack overflow with the unchecked `memcpy(ipbuf, str, q-str);` and `memcpy(ipbufpfx, str, q-str);` statements in the config_sortlist call, which could potentially cause severe security impact in practical programs. This commit add necessary check for `ipbuf` and `ipbufpfx` which avoid the potential stack overflows. fixes c-ares#496 Signed-off-by: hopper-vul <hopper.vul@gmail.com>
|
I'm not aware of any users of this interface, but in general it just looks broken to me. It looks like via the documentation its supposed to only take ip addresses or ip addresses with subnet masks, however looking at the pre-existing test cases, its accepting garbage and actively being tested to ensure it accepts garbage ??? |
|
Yes, the In current change, if it detects overflow (or means bad input string), it will return with a |
|
JFTR, this was assigned CVE-2022-4904 (via https://bugzilla.redhat.com/show_bug.cgi?id=2168631) |
|
@mmuehlenhoff thanks for maintaining the record :) |
In
ares_set_sortlist, it callsconfig_sortlist(..., sortstr)to parse the input str and initialize a sortlist configuration.However,
ares_set_sortlisthas not any checks about the validity of the input str. It is very easy to create an arbitrary length stack overflow with the uncheckedmemcpy(ipbuf, str, q-str);andmemcpy(ipbufpfx, str, q-str);statements in the config_sortlist call, which could potentially cause severe security impact in practical programs.This commit add necessary check for
ipbufandipbufpfxwhich avoid the potential stack overflows.fixes #496
Signed-off-by: hopper-vul hopper.vul@gmail.com