]> git.ipfire.org Git - thirdparty/vim.git/commit
patch 9.0.1908: undefined behaviour upper/lower function ptrs v9.0.1908
authorYee Cheng Chin <ychin.git@gmail.com>
Mon, 18 Sep 2023 17:51:56 +0000 (19:51 +0200)
committerChristian Brabandt <cb@256bit.org>
Mon, 18 Sep 2023 17:51:56 +0000 (19:51 +0200)
commitd25021cf036c63d539f845a1ee05b03ea21d61ff
tree1519ab104ace6903014a4fcea2c832db7fbb082b
parentd8b86c937a419db69239a8bb879f0050be0f8e1d
patch 9.0.1908: undefined behaviour upper/lower function ptrs

Problem:  undefined behaviour upper/lower function ptrs
Solution: Fix UBSAN error in regexp and simplify upper/lowercase
          modifier code

The implementation of \u / \U / \l / \L modifiers in the substitute
command relies on remembering the state by setting function pointers on
func_all/func_one in the code. The code signature of `fptr_T` is
supposed to return void* (due to C function signatures not being able to
return itself due to type recursion), and the definition of the
functions (e.g. to_Upper) didn't follow this rule, and so the code tries
to cast functions of different signatures, resulting in undefined
behavior error under UBSAN in Clang 17. See #12745.

We could just fix `do_Upper`/etc to just return void*, which would fix
the problem. However, these functions actually do not need to return
anything at all. It used to be the case that there was only one pointer
"func" to store the pointer, which is why the function needs to either
return itself or NULL to indicate whether it's a one time or ongoing
modification. However, c2c355df6f094cdb9e599fd395a78c14486ec697
(7.3.873) already made that obsolete by introducing `func_one` and
`func_all` to store one-time and ongoing operations separately, so these
functions don't actually need to return anything anymore because it's
implicit whether it's a one-time or ongoing operation. Simplify the code
to reflect that.

closes: #13117

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
src/regexp.c
src/version.c