Fix various issues, including potential crashes Signed-off-by: Felix Fietkau <nbd@nbd.name> (cherry picked from commit 53eab6198bf87d12055409bc4a38d58b68291b2f)