kernelkit / infix

Linux :yellow_heart: NETCONF = Infix
https://kernelkit.org
GNU General Public License v2.0
52 stars 12 forks source link

confd: fix double free of container hostname #716

Closed rical closed 1 month ago

rical commented 1 month ago

Description

Fix a double free in the memory minefield surrounding container hostname provisioning. The hostnamefmt() function already does free() on success.

This caused all sorts of mayhem when working with multiple containers. However it mainly manifested itself by some containers not starting due to there activation script being polluted with gibberish name data. Your symptom might be different..

Example of polluted activation script

container --hostname foobar --net veth0k -r always \ create ^S@`M-}^G docker://ghcr.io/kernelkit/curios:edge

Side note

I haven't looked into it but is it really legit to free memory returned from the various lydx_ functions used here? It seems to work as intended but it looks risky at a glance.

Checklist

Tick relevant boxes, this PR is-a or has-a:

troglobit commented 1 month ago

Ouch, nice catch! Although I cannot cannot reproduce in my limited setup, I agree that the current code needs work, and your fix is a good start, so let's merge this.

I'll submit a PR later that refactors int hostnamefmt(struct confd *confd, char **fmt) into int hostnamefmt(struct confd *confd, const char *fmt, char *buf, size_t len). Because we know that a hostname in Linux can only be 64 chars long, so a stack buffer for the return value is a much safer alternative.