Skip to content

Fix: guard against underflow in gvm_hosts_move_current_host_to_end - #1150

Merged
greenbonebot merged 3 commits into
mainfrom
fix/49-out-of-bounds-read-when-hosts-current-is-0-in-gvm-hosts-move-current-host-to-end
Oct 20, 2026
Merged

greenbonebot merged 3 commits into
mainfrom
fix/49-out-of-bounds-read-when-hosts-current-is-0-in-gvm-hosts-move-current-host-to-end

Conversation

@mattmundell

Copy link
Copy Markdown
Contributor

What

Return early when hosts->current is 0 in both branches of
gvm_hosts_move_current_host_to_end, before decrementing the index.

Why

The function decremented hosts->current unconditionally, so when it was 0
(before the first host, or with an empty set) the size_t wrapped to
SIZE_MAX and the host array was read out of bounds. The fix is needed to
avoid those reads.

Testing

  • gvm_hosts_move_current_host_to_end_before_first_host (hosts-test):
    before the fix, ASan reported a heap-buffer-overflow read in
    gvm_hosts_move_current_host_to_end at base/hosts.c:1369; after the fix
    the case passes clean.
  • gvm_hosts_move_current_host_to_end_empty_hosts (hosts-test): before the
    fix, ASan reported a heap-buffer-overflow read in gvm_hosts_next at
    base/hosts.c:1332; after the fix the case passes clean.

The full gvm-libs unit suite is ASan-clean with the fix.

Without this guard the index wraps to SIZE_MAX and the host array is read
out of bounds.
With an empty set current equals count equals zero, so decrementing wraps
the index and a later next call reads past the host array.
@mattmundell
mattmundell requested review from a team as code owners October 20, 2026 12:38
@greenbonebot
greenbonebot enabled auto-merge (rebase) October 20, 2026 12:38
@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA bc218bb.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Scanned Files

None

@greenbonebot
greenbonebot merged commit 8c6a2db into main Oct 20, 2026
22 checks passed
@greenbonebot
greenbonebot deleted the fix/49-out-of-bounds-read-when-hosts-current-is-0-in-gvm-hosts-move-current-host-to-end branch October 20, 2026 12:53
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