Skip to content

Array out of bounds fix - #471

Closed
keerthimuvva52 wants to merge 1 commit into
masterfrom
security_fixes
Closed

Array out of bounds fix#471
keerthimuvva52 wants to merge 1 commit into
masterfrom
security_fixes

Conversation

@keerthimuvva52

Copy link
Copy Markdown

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Adds additional validation during database deserialization to prevent out-of-bounds access at scan time by ensuring LimEx reach-map indices are within the associated reach table size.

Changes:

  • Introduces db_validate_limex_reach_map() to validate LimEx reachMap[] entries against reachSize.
  • Hooks the new validation into db_validate_rose_offsets() so corrupted databases fail validation earlier.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/database.c
Comment on lines +306 to +320
if (!isNfaType(nfa->type)) {
continue;
}

if (unlikely(ni->nfaOffset + nfa->length > rose_size)) {
return HS_INVALID;
}

if (unlikely(nfa->length <= sizeof(struct NFA))) {
return HS_INVALID;
}

const char *limex_base = (const char *)getImplNfa(nfa);
u32 limex_len = nfa->length - (u32)sizeof(struct NFA);

Comment thread src/database.c
Comment on lines +329 to +330
const struct LimExNFA32 *limex =
(const struct LimExNFA32 *)limex_base;
Comment thread src/database.c
Comment on lines +321 to +327
/* Ensure we can read reachMap[256] and reachSize. */
const u32 reach_prefix_end =
(u32)(N_CHARS + sizeof(u32)); /* reachMap + reachSize */
if (unlikely(limex_len < reach_prefix_end)) {
DEBUG_PRINTF("LimEx[%u] too small for reachMap\n", qi);
return HS_INVALID;
}
Comment thread src/database.c
Comment on lines +281 to +283
if (!rose->nfaInfoOffset || rose->nfaInfoOffset >= rose_size) {
return HS_SUCCESS; /* no NFA engines - nothing to check */
}
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.

2 participants