summaryrefslogtreecommitdiff
path: root/lib/variables.c
diff options
context:
space:
mode:
authorLaszlo Ersek <lersek@redhat.com>2020-01-28 23:33:46 +0100
committerPeter Jones <pjones@redhat.com>2020-07-23 20:53:24 -0400
commitc6bedd5b83529925c3ec08f96a3bf61c81bff0ae (patch)
treed484d5b7aff9596190f5c90e08c432e5f66a971e /lib/variables.c
parent959f5e4e993a82020fef48c7e7c012a44074645c (diff)
downloadefi-boot-shim-c6bedd5b83529925c3ec08f96a3bf61c81bff0ae.tar.gz
efi-boot-shim-c6bedd5b83529925c3ec08f96a3bf61c81bff0ae.zip
translate_slashes(): don't write to string literals
Currently, all three invocations of the translate_slashes() function may lead to writes to the string literal that is #defined with the DEFAULT_LOADER_CHAR macro. According to ISO C99 6.4.5p6, this is undefined behavior ("If the program attempts to modify such an array, the behavior is undefined"). This bug crashes shim on e.g. the 64-bit ArmVirtQemu platform ("Data abort: Permission fault"), where the platform firmware maps the .text section (which contains the string literal) read-only. Modify translate_slashes() so that it copies and translates characters from an input array of "char" to an output array of "CHAR8". While at it, fix another bug. Before this patch, if translate_slashes() ever encountered a double backslash (translating it to a single forward slash), then the output would end up shorter than the input. However, the output was not NUL-terminated in-place, therefore the original string length (and according trailing garbage) would be preserved. After this patch, the NUL-termination on contraction is automatic, as the output array's contents are indeterminate when entering the function, and so we must NUL-terminate it anyway. Fixes: 8e9124227d18475d3bc634c33518963fc8db7c98 Fixes: e62b69a5b0b87c6df7a4fc23906134945309e927 Fixes: 3d79bcb2651b9eae809b975b3e03e2f96c067072 Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1795654 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Upstream-commit-id: 9813e8bc8b3
Diffstat (limited to 'lib/variables.c')
0 files changed, 0 insertions, 0 deletions