mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
lua/executor: Fix crash when first string contains NUL and second not
This commit is contained in:
@@ -137,15 +137,17 @@ static int nlua_stricmp(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
|
|||||||
nul1 = memchr(s1, NUL, s1_len);
|
nul1 = memchr(s1, NUL, s1_len);
|
||||||
nul2 = memchr(s2, NUL, s2_len);
|
nul2 = memchr(s2, NUL, s2_len);
|
||||||
ret = STRICMP(s1, s2);
|
ret = STRICMP(s1, s2);
|
||||||
|
if (ret == 0) {
|
||||||
// Compare "a\0" greater then "a".
|
// Compare "a\0" greater then "a".
|
||||||
if (ret == 0 && (nul1 == NULL) != (nul2 == NULL)) {
|
if ((nul1 == NULL) != (nul2 == NULL)) {
|
||||||
ret = ((nul1 != NULL) - (nul2 != NULL));
|
ret = ((nul1 != NULL) - (nul2 != NULL));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (nul1 != NULL) {
|
if (nul1 != NULL) {
|
||||||
assert(nul2 != NULL);
|
assert(nul2 != NULL);
|
||||||
// Due to lowercase letter having possibly different byte length then
|
// Due to lowercase letter having possibly different byte length then
|
||||||
// uppercase letter can’t shift both strings by the same amount of bytes.
|
// uppercase letter can’t shift both strings by the same amount of
|
||||||
|
// bytes.
|
||||||
s1_len -= (size_t)(nul1 - s1) + 1;
|
s1_len -= (size_t)(nul1 - s1) + 1;
|
||||||
s2_len -= (size_t)(nul2 - s2) + 1;
|
s2_len -= (size_t)(nul2 - s2) + 1;
|
||||||
s1 = nul1 + 1;
|
s1 = nul1 + 1;
|
||||||
@@ -153,7 +155,10 @@ static int nlua_stricmp(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
|
|||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (ret == 0);
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (true);
|
||||||
lua_pop(lstate, 2);
|
lua_pop(lstate, 2);
|
||||||
lua_pushnumber(lstate, (lua_Number)((ret > 0) - (ret < 0)));
|
lua_pushnumber(lstate, (lua_Number)((ret > 0) - (ret < 0)));
|
||||||
return 1;
|
return 1;
|
||||||
|
@@ -89,6 +89,11 @@ describe('vim.stricmp', function()
|
|||||||
eq(1, funcs.luaeval('vim.stricmp("c\\0", "b\\0")'))
|
eq(1, funcs.luaeval('vim.stricmp("c\\0", "b\\0")'))
|
||||||
eq(1, funcs.luaeval('vim.stricmp("C\\0", "B\\0")'))
|
eq(1, funcs.luaeval('vim.stricmp("C\\0", "B\\0")'))
|
||||||
|
|
||||||
|
eq(1, funcs.luaeval('vim.stricmp("c\\0", "B")'))
|
||||||
|
eq(1, funcs.luaeval('vim.stricmp("C\\0", "b")'))
|
||||||
|
eq(1, funcs.luaeval('vim.stricmp("c\\0", "b")'))
|
||||||
|
eq(1, funcs.luaeval('vim.stricmp("C\\0", "B")'))
|
||||||
|
|
||||||
eq(1, funcs.luaeval('vim.stricmp("\\0c", "\\0B")'))
|
eq(1, funcs.luaeval('vim.stricmp("\\0c", "\\0B")'))
|
||||||
eq(1, funcs.luaeval('vim.stricmp("\\0C", "\\0b")'))
|
eq(1, funcs.luaeval('vim.stricmp("\\0C", "\\0b")'))
|
||||||
eq(1, funcs.luaeval('vim.stricmp("\\0c", "\\0b")'))
|
eq(1, funcs.luaeval('vim.stricmp("\\0c", "\\0b")'))
|
||||||
|
Reference in New Issue
Block a user