detect/reference: allow undefined references

References are currently not used in Suricata, so erroring out on
rules using a undefined reference is too harsh.

Just issue a warning once per unique missing reference.
pull/4288/head
Victor Julien 7 years ago
parent 61185cc9ba
commit 0b40d4ae93

@ -134,10 +134,17 @@ static DetectReference *DetectReferenceParse(const char *rawstr, DetectEngineCtx
if (lookup_ref_conf != NULL) { if (lookup_ref_conf != NULL) {
ref->key = lookup_ref_conf->url; ref->key = lookup_ref_conf->url;
} else { } else {
SCLogError(SC_ERR_REFERENCE_UNKNOWN, "unknown reference key \"%s\". " SCLogWarning(SC_ERR_REFERENCE_UNKNOWN,
"Supported keys are defined in reference.config file. Please " "unknown reference key \"%s\"", key);
"have a look at the conf param \"reference-config-file\"", key);
goto error; char str[2048];
snprintf(str, sizeof(str), "config reference: %s undefined\n", key);
if (SCRConfAddReference(de_ctx, str) < 0)
goto error;
lookup_ref_conf = SCRConfGetReference(key, de_ctx);
if (lookup_ref_conf == NULL)
goto error;
} }
/* make a copy so we can free pcre's substring */ /* make a copy so we can free pcre's substring */
@ -282,7 +289,7 @@ static int DetectReferenceParseTest03(void)
Signature *s = DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any " Signature *s = DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
"(msg:\"invalid ref\"; " "(msg:\"invalid ref\"; "
"reference:unknownkey,001-2010; sid:2;)"); "reference:unknownkey,001-2010; sid:2;)");
FAIL_IF_NOT_NULL(s); FAIL_IF_NULL(s);
DetectEngineCtxFree(de_ctx); DetectEngineCtxFree(de_ctx);
PASS; PASS;
} }

@ -100,13 +100,13 @@ void SCReferenceConfDeinit(void)
* *
* \param de_ctx Pointer to the Detection Engine Context. * \param de_ctx Pointer to the Detection Engine Context.
* *
* \note if file open fails, we leave de_ctx->reference_conf_ht initialized
*
* \retval 0 On success. * \retval 0 On success.
* \retval -1 On failure. * \retval -1 On failure.
*/ */
static FILE *SCRConfInitContextAndLocalResources(DetectEngineCtx *de_ctx, FILE *fd) static FILE *SCRConfInitContextAndLocalResources(DetectEngineCtx *de_ctx, FILE *fd)
{ {
const char *filename = NULL;
/* init the hash table to be used by the reference config references */ /* init the hash table to be used by the reference config references */
de_ctx->reference_conf_ht = HashTableInit(128, SCRConfReferenceHashFunc, de_ctx->reference_conf_ht = HashTableInit(128, SCRConfReferenceHashFunc,
SCRConfReferenceHashCompareFunc, SCRConfReferenceHashCompareFunc,
@ -114,7 +114,7 @@ static FILE *SCRConfInitContextAndLocalResources(DetectEngineCtx *de_ctx, FILE *
if (de_ctx->reference_conf_ht == NULL) { if (de_ctx->reference_conf_ht == NULL) {
SCLogError(SC_ERR_HASH_TABLE_INIT, "Error initializing the hash " SCLogError(SC_ERR_HASH_TABLE_INIT, "Error initializing the hash "
"table"); "table");
goto error; return NULL;
} }
/* if it is not NULL, use the file descriptor. The hack so that we can /* if it is not NULL, use the file descriptor. The hack so that we can
@ -122,31 +122,19 @@ static FILE *SCRConfInitContextAndLocalResources(DetectEngineCtx *de_ctx, FILE *
* instead use an input stream against a buffer containing the * instead use an input stream against a buffer containing the
* reference strings */ * reference strings */
if (fd == NULL) { if (fd == NULL) {
filename = SCRConfGetConfFilename(de_ctx); const char *filename = SCRConfGetConfFilename(de_ctx);
if ((fd = fopen(filename, "r")) == NULL) { if ((fd = fopen(filename, "r")) == NULL) {
#ifdef UNITTESTS #ifdef UNITTESTS
if (RunmodeIsUnittests()) if (RunmodeIsUnittests())
goto error; // silently fail return NULL; // silently fail
#endif #endif
SCLogError(SC_ERR_FOPEN, "Error opening file: \"%s\": %s", filename, SCLogError(SC_ERR_FOPEN, "Error opening file: \"%s\": %s", filename,
strerror(errno)); strerror(errno));
goto error; return NULL;
} }
} }
return fd; return fd;
error:
if (de_ctx->reference_conf_ht != NULL) {
HashTableFree(de_ctx->reference_conf_ht);
de_ctx->reference_conf_ht = NULL;
}
if (fd != NULL) {
fclose(fd);
fd = NULL;
}
return NULL;
} }

Loading…
Cancel
Save