]> git.ipfire.org Git - thirdparty/systemd.git/commit
sd-device: fix crash if a device has many tags or devlinks 2955/head
authorMartin Pitt <martin.pitt@ubuntu.com>
Mon, 4 Apr 2016 09:09:00 +0000 (11:09 +0200)
committerMartin Pitt <martin.pitt@ubuntu.com>
Tue, 5 Apr 2016 06:55:34 +0000 (08:55 +0200)
commit1d88a271a69119635158bdc4009c38fbc4199997
tree6d67e9518598fbd94639e169cfad0bed56a31577
parent77384fb0edda2e9d826c1e6786faae607b48e47d
sd-device: fix crash if a device has many tags or devlinks

strjoina() is unsafe to be used in an unbounded loop as alloca() has no error
reporting. Thus devices with a large number of tags or devlinks trigger a
segfault in device_properties_prepare() due to overflowing the stack.

Rewrite the building of the "tags" and "devlinks" strings using
GREEDY_REALLOC() and strpcpy() to work with arbitrarily long strings. This also
avoids re-copying the entire string in each loop iteration.

Before this commit we always appended one final ":" to "tags". Change this to
start with an iniital ":" and for each tag append instead of prepend a ":".
This unifies what happens for the first and all subsequent tags so that we can
use a for loop.

Fixes #2954
src/libsystemd/sd-device/sd-device.c