Bug 870 - ASAN: Memory leak
ASAN: Memory leak
Status: RESOLVED WORKSFORME
Product: Sudo
Classification: Unclassified
Component: Sudo
1.8.27
PC Linux
: low security
Assigned To: Todd C. Miller
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2019-01-22 04:44 MST by Dhiraj
Modified: 2019-04-08 13:52 MDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dhiraj 2019-01-22 04:44:20 MST
Hi Team, 

I have build sudo-1.8.27 with clang 6.0 with ASAN, however direct/in-direct memory leak was observed in 'sudo'

Vulnerable code from sudo.c

    /* Allocate and fill in. */
    plugin_settings = reallocarray(NULL, plugin_settings_size, sizeof(char *));
    if (plugin_settings == NULL)
	goto bad;
    plugin_settings[i] = sudo_new_key_val("plugin_path", plugin->path);
    if (plugin_settings[i] == NULL)
	goto bad;
    for (setting = sudo_settings; setting->name != NULL; setting++) {
        if (setting->value != NULL) {
            sudo_debug_printf(SUDO_DEBUG_INFO, "settings: %s=%s",
                setting->name, setting->value);
	    plugin_settings[++i] =
		sudo_new_key_val(setting->name, setting->value);
	    if (plugin_settings[i] == NULL)
		goto bad;
        }
    }
    if (plugin->debug_files != NULL) {

ASAN:

==123445==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 200 byte(s) in 1 object(s) allocated from:
    #0 0x55fca6af6985 in realloc (/home/zero/Downloads/sudo-1.8.27/src/sudo+0x127985)
    #1 0x55fca6b6186b in format_plugin_settings /home/zero/Downloads/sudo-1.8.27/src/./sudo.c:1043:23

Indirect leak of 56 byte(s) in 3 object(s) allocated from:
    #0 0x55fca6af6560 in malloc (/home/zero/Downloads/sudo-1.8.27/src/sudo+0x127560)
    #1 0x55fca6b73e00 in sudo_new_key_val_v1 /home/zero/Downloads/sudo-1.8.27/lib/util/./key_val.c:51:16

SUMMARY: AddressSanitizer: 256 byte(s) leaked in 4 allocation(s).
Comment 1 Todd C. Miller 2019-01-22 06:20:24 MST
If you run configure with the --enable-asan option it will also set NO_LEAKS in config.h which will cause this memory to be freed before exit.