Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(prefix): fix bug when buffer realloc occurs during prefix lookup #61

Merged
merged 1 commit into from
Nov 22, 2024

Conversation

dndx
Copy link
Member

@dndx dndx commented Nov 21, 2024

Prefix based lookup may need to reallocate the key/value buffer when the buffer size exceeds the default (currently 1MB).

However, because we use the ops[0] and ops[1] passed in is used for both providing the after and prefix, in case of NGX_AGAIN, these will be overwritten by the ngx_lua_resty_lmdb_ffi_prefix() function to the first and second key respectively, which breaks the retry and causing the second call to ngx_lua_resty_lmdb_ffi_prefix() to return empty.

This commit fixes the above issue by always resetting ops[0] and ops[1] between retries, therefore the above issue no longer occurs.

Also, this commit fixes a use-after-free bug for db_drop() operation when map is full.

KAG-5874

@dndx dndx requested a review from chronolaw November 21, 2024 12:25
Copy link

github-actions bot commented Nov 21, 2024

Luacheck Report

2 tests  ±0   0 ✅ ±0   0s ⏱️ ±0s
1 suites ±0   0 💤 ±0 
1 files   ±0   2 ❌ ±0 

For more details on these failures, see this check.

Results for commit d66f376. ± Comparison against base commit 890b3ca.

♻️ This comment has been updated with latest results.

@dndx dndx requested a review from StarlightIbuki November 21, 2024 12:38
t/10-prefix.t Outdated Show resolved Hide resolved
t/10-prefix.t Outdated Show resolved Hide resolved
t/10-prefix.t Outdated Show resolved Hide resolved
Prefix based lookup may need to reallocate the key/value buffer when the
buffer size exceeds the default (currently 1MB).

However, because we use the `ops[0]` and `ops[1]` passed in is used for both
providing the `after` and `prefix`, in case of `NGX_AGAIN`, these will
be overwritten by the `ngx_lua_resty_lmdb_ffi_prefix()` function to the
first and second key respectively, which breaks the retry and causing
the second call to `ngx_lua_resty_lmdb_ffi_prefix()` to return empty.

This commit fixes the above issue by always resetting `ops[0]` and
`ops[1]` between retries, therefore the above issue no longer occurs.

Also, this commit fixes a use-after-free bug for `db_drop()` operation when
map is full.
@dndx dndx merged commit 1967f92 into master Nov 22, 2024
6 checks passed
@dndx dndx deleted the fix/page_realloc branch November 22, 2024 02:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants