Rose: add handling for unexpected programs

This commit is contained in:
Wang, Xiang W
2019-03-25 12:30:07 -04:00
committed by Wang Xiang W
parent f0bde3721e
commit 6dc9bed310
4 changed files with 63 additions and 9 deletions

View File

@@ -151,7 +151,7 @@ void populateCoreInfo(struct hs_scratch *s, const struct RoseEngine *rose,
}
#define STATUS_VALID_BITS \
(STATUS_TERMINATED | STATUS_EXHAUSTED | STATUS_DELAY_DIRTY)
(STATUS_TERMINATED | STATUS_EXHAUSTED | STATUS_DELAY_DIRTY | STATUS_ERROR)
/** \brief Retrieve status bitmask from stream state. */
static really_inline
@@ -428,7 +428,10 @@ hs_error_t HS_CDECL hs_scan(const hs_database_t *db, const char *data,
}
done_scan:
if (told_to_stop_matching(scratch)) {
if (unlikely(internal_matching_error(scratch))) {
unmarkScratchInUse(scratch);
return HS_UNKNOWN_ERROR;
} else if (told_to_stop_matching(scratch)) {
unmarkScratchInUse(scratch);
return HS_SCAN_TERMINATED;
}
@@ -447,6 +450,11 @@ done_scan:
}
set_retval:
if (unlikely(internal_matching_error(scratch))) {
unmarkScratchInUse(scratch);
return HS_UNKNOWN_ERROR;
}
if (rose->flushCombProgramOffset) {
if (roseRunFlushCombProgram(rose, scratch, ~0ULL) == MO_HALT_MATCHING) {
unmarkScratchInUse(scratch);
@@ -626,7 +634,7 @@ void report_eod_matches(hs_stream_t *id, hs_scratch_t *scratch,
char *state = getMultiState(id);
u8 status = getStreamStatus(state);
if (status & (STATUS_TERMINATED | STATUS_EXHAUSTED)) {
if (status & (STATUS_TERMINATED | STATUS_EXHAUSTED | STATUS_ERROR)) {
DEBUG_PRINTF("stream is broken, just freeing storage\n");
return;
}
@@ -749,6 +757,9 @@ hs_error_t HS_CDECL hs_reset_and_copy_stream(hs_stream_t *to_id,
}
report_eod_matches(to_id, scratch, onEvent, context);
unmarkScratchInUse(scratch);
if (unlikely(internal_matching_error(scratch))) {
return HS_UNKNOWN_ERROR;
}
}
size_t stateSize
@@ -863,9 +874,11 @@ hs_error_t hs_scan_stream_internal(hs_stream_t *id, const char *data,
char *state = getMultiState(id);
u8 status = getStreamStatus(state);
if (status & (STATUS_TERMINATED | STATUS_EXHAUSTED)) {
if (status & (STATUS_TERMINATED | STATUS_EXHAUSTED | STATUS_ERROR)) {
DEBUG_PRINTF("stream is broken, halting scan\n");
if (status & STATUS_TERMINATED) {
if (status & STATUS_ERROR) {
return HS_UNKNOWN_ERROR;
} else if (status & STATUS_TERMINATED) {
return HS_SCAN_TERMINATED;
} else {
return HS_SUCCESS;
@@ -937,7 +950,9 @@ hs_error_t hs_scan_stream_internal(hs_stream_t *id, const char *data,
setStreamStatus(state, scratch->core_info.status);
if (likely(!can_stop_matching(scratch))) {
if (unlikely(internal_matching_error(scratch))) {
return HS_UNKNOWN_ERROR;
} else if (likely(!can_stop_matching(scratch))) {
maintainHistoryBuffer(rose, state, data, length);
id->offset += length; /* maintain offset */
@@ -987,6 +1002,9 @@ hs_error_t HS_CDECL hs_close_stream(hs_stream_t *id, hs_scratch_t *scratch,
}
report_eod_matches(id, scratch, onEvent, context);
unmarkScratchInUse(scratch);
if (unlikely(internal_matching_error(scratch))) {
return HS_UNKNOWN_ERROR;
}
}
if (id->rose->flushCombProgramOffset && !told_to_stop_matching(scratch)) {
@@ -1019,6 +1037,9 @@ hs_error_t HS_CDECL hs_reset_stream(hs_stream_t *id, UNUSED unsigned int flags,
}
report_eod_matches(id, scratch, onEvent, context);
unmarkScratchInUse(scratch);
if (unlikely(internal_matching_error(scratch))) {
return HS_UNKNOWN_ERROR;
}
}
if (id->rose->flushCombProgramOffset && !told_to_stop_matching(scratch)) {
@@ -1139,7 +1160,10 @@ hs_error_t HS_CDECL hs_scan_vector(const hs_database_t *db,
if (onEvent) {
report_eod_matches(id, scratch, onEvent, context);
if (told_to_stop_matching(scratch)) {
if (unlikely(internal_matching_error(scratch))) {
unmarkScratchInUse(scratch);
return HS_UNKNOWN_ERROR;
} else if (told_to_stop_matching(scratch)) {
unmarkScratchInUse(scratch);
return HS_SCAN_TERMINATED;
}
@@ -1238,6 +1262,9 @@ hs_error_t HS_CDECL hs_reset_and_expand_stream(hs_stream_t *to_stream,
}
report_eod_matches(to_stream, scratch, onEvent, context);
unmarkScratchInUse(scratch);
if (unlikely(internal_matching_error(scratch))) {
return HS_UNKNOWN_ERROR;
}
}
if (expand_stream(to_stream, rose, buf, buf_size)) {