/*
- * Copyright (c) 2018, Intel Corporation
+ * Copyright (c) 2018-2020, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*/
#define CH_SCRATCH_IN_USE (-10)
+/**
+ * Unexpected internal error from Hyperscan.
+ *
+ * This error indicates that there was unexpected matching behaviors from
+ * Hyperscan. This could be related to invalid usage of scratch space or
+ * invalid memory operations by users.
+ *
+ */
+#define CH_UNKNOWN_HS_ERROR (-13)
+
/**
* Returned when pcre_exec (called for some expressions internally from @ref
* ch_scan) failed due to a fatal error.
/*
- * Copyright (c) 2018, Intel Corporation
+ * Copyright (c) 2018-2020, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
DEBUG_PRINTF("user callback told us to skip this pattern\n");
pd->scanStart = hyctx->length;
ret = HS_SUCCESS;
+ hyctx->scratch->ret = ret;
} else if (ret == CH_FAIL_INTERNAL) {
return ret;
}
if (!(db->flags & CHIMERA_FLAG_NO_MULTIMATCH)) {
ret = scanHyperscan(&hyctx, data, length);
- if (ret != HS_SUCCESS && scratch->ret != CH_SUCCESS) {
- DEBUG_PRINTF("Hyperscan returned error %d\n", scratch->ret);
+ // Errors from pcre scan.
+ if (scratch->ret == CH_CALLBACK_TERMINATE) {
+ DEBUG_PRINTF("Pcre terminates scan\n");
+ unmarkScratchInUse(scratch);
+ return CH_SCAN_TERMINATED;
+ } else if (scratch->ret != CH_SUCCESS) {
+ DEBUG_PRINTF("Pcre internal error\n");
unmarkScratchInUse(scratch);
return scratch->ret;
}
+ // Errors from Hyperscan scan. Note Chimera could terminate
+ // Hyperscan callback on purpose so this is not counted as an error.
+ if (ret != HS_SUCCESS && ret != HS_SCAN_TERMINATED) {
+ assert(scratch->ret == CH_SUCCESS);
+ DEBUG_PRINTF("Hyperscan returned error %d\n", ret);
+ unmarkScratchInUse(scratch);
+ return ret;
+ }
}
DEBUG_PRINTF("Flush priority queue\n");