2

Fix a leak in libdpkg when querying the deb_packages table by Smjert · Pull Requ...

 2 years ago
source link: https://github.com/osquery/osquery/pull/6892
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Copy link

Member

Smjert commented on Jan 10, 2021

libdpkg is leaking memory on every initialization.
Initialization happens everytime deb_packages gets queried.

The memory leaked is allocated for the "triggersdir"
global variable by "dpkg_db_get_path" called in "trigdef_update_start".
"trigdef_update_start" is called by "trig_incorporate" just after
the memory for "triggersdir" has been allocated.
In some occasions "trigdef_update_start" is also called two times in a
row. In all these cases the memory do not get deallocated in between calls,
so the old memory is lost.

Since the result of "dpkg_db_get_path" depends on the database dir that
has been set, and in the "trigdef_update_start" function it's not possible
to know if it has changed from the previous allocation or not,
it's necessary to always deallocate vs just avoid to call "dpkg_db_get_path".

Fix also a couple of other leaks on error.

Fixes: #6327

This was often hit by oss-fuzz too, though the stack trace would only contain 2 frames, vasprintf and the memory allocation.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK