Skip to content

Commit

Permalink
fixup! retry a3168fd
Browse files Browse the repository at this point in the history
  • Loading branch information
catenacyber committed Jul 6, 2023
1 parent 756a81d commit 161a53e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 51 deletions.
32 changes: 15 additions & 17 deletions src/detect-fileext.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ typedef struct DetectFileextData_ {
uint32_t flags;
} DetectFileextData;

static int DetectFileextMatch (DetectEngineThreadCtx *, Flow *,
uint8_t, File *, const Signature *, const SigMatchCtx *);
static int DetectFileextSetup (DetectEngineCtx *, Signature *, const char *);
static int DetectFileextMatch(
DetectEngineThreadCtx *, Flow *, uint8_t, File *, const Signature *, const SigMatchCtx *);
static int DetectFileextSetup(DetectEngineCtx *, Signature *, const char *);
#ifdef UNITTESTS
static void DetectFileextRegisterTests(void);
#endif
Expand All @@ -76,16 +76,16 @@ void DetectFileextRegister(void)
sigmatch_table[DETECT_FILEEXT].url = "/rules/file-keywords.html#fileext";
sigmatch_table[DETECT_FILEEXT].FileMatch = DetectFileextMatch;
sigmatch_table[DETECT_FILEEXT].Setup = DetectFileextSetup;
sigmatch_table[DETECT_FILEEXT].Free = DetectFileextFree;
sigmatch_table[DETECT_FILEEXT].Free = DetectFileextFree;
#ifdef UNITTESTS
sigmatch_table[DETECT_FILEEXT].RegisterTests = DetectFileextRegisterTests;
#endif
sigmatch_table[DETECT_FILEEXT].flags = SIGMATCH_QUOTES_OPTIONAL|SIGMATCH_HANDLE_NEGATION;
sigmatch_table[DETECT_FILEEXT].flags = SIGMATCH_QUOTES_OPTIONAL | SIGMATCH_HANDLE_NEGATION;
sigmatch_table[DETECT_FILEEXT].alternative = DETECT_FILE_NAME;

g_file_match_list_id = DetectBufferTypeRegister("files");

SCLogDebug("registering fileext rule option");
SCLogDebug("registering fileext rule option");
return;
}

Expand All @@ -103,8 +103,8 @@ void DetectFileextRegister(void)
* \retval 0 no match
* \retval 1 match
*/
static int DetectFileextMatch (DetectEngineThreadCtx *det_ctx,
Flow *f, uint8_t flags, File *file, const Signature *s, const SigMatchCtx *m)
static int DetectFileextMatch(DetectEngineThreadCtx *det_ctx, Flow *f, uint8_t flags, File *file,
const Signature *s, const SigMatchCtx *m)
{
SCEnter();
int ret = 0;
Expand All @@ -121,8 +121,7 @@ static int DetectFileextMatch (DetectEngineThreadCtx *det_ctx,

/* fileext->ext is already in lowercase, as SCMemcmpLowercase requires */
if (file->name[offset - 1] == '.' &&
SCMemcmpLowercase(fileext->ext, file->name + offset, fileext->len) == 0)
{
SCMemcmpLowercase(fileext->ext, file->name + offset, fileext->len) == 0) {
if (!(fileext->flags & DETECT_CONTENT_NEGATED)) {
ret = 1;
SCLogDebug("File ext found");
Expand All @@ -144,7 +143,7 @@ static int DetectFileextMatch (DetectEngineThreadCtx *det_ctx,
* \retval pointer to DetectFileextData on success
* \retval NULL on failure
*/
static DetectFileextData *DetectFileextParse (DetectEngineCtx *de_ctx, const char *str, bool negate)
static DetectFileextData *DetectFileextParse(DetectEngineCtx *de_ctx, const char *str, bool negate)
{
DetectFileextData *fileext = NULL;

Expand Down Expand Up @@ -189,7 +188,6 @@ static DetectFileextData *DetectFileextParse (DetectEngineCtx *de_ctx, const cha
if (fileext != NULL)
DetectFileextFree(de_ctx, fileext);
return NULL;

}

/**
Expand All @@ -203,7 +201,7 @@ static DetectFileextData *DetectFileextParse (DetectEngineCtx *de_ctx, const cha
* \retval 0 on Success
* \retval -1 on Failure
*/
static int DetectFileextSetup (DetectEngineCtx *de_ctx, Signature *s, const char *str)
static int DetectFileextSetup(DetectEngineCtx *de_ctx, Signature *s, const char *str)
{
DetectFileextData *fileext = DetectFileextParse(de_ctx, str, s->init_data->negated);
if (fileext == NULL)
Expand All @@ -220,7 +218,7 @@ static int DetectFileextSetup (DetectEngineCtx *de_ctx, Signature *s, const char

SigMatchAppendSMToList(s, sm, g_file_match_list_id);

s->file_flags |= (FILE_SIG_NEED_FILE|FILE_SIG_NEED_FILENAME);
s->file_flags |= (FILE_SIG_NEED_FILE | FILE_SIG_NEED_FILENAME);
return 0;

error:
Expand Down Expand Up @@ -250,7 +248,7 @@ static void DetectFileextFree(DetectEngineCtx *de_ctx, void *ptr)
/**
* \test DetectFileextTestParse01
*/
static int DetectFileextTestParse01 (void)
static int DetectFileextTestParse01(void)
{
DetectFileextData *dfd = DetectFileextParse(NULL, "doc", false);
FAIL_IF_NULL(dfd);
Expand All @@ -262,7 +260,7 @@ static int DetectFileextTestParse01 (void)
/**
* \test DetectFileextTestParse02
*/
static int DetectFileextTestParse02 (void)
static int DetectFileextTestParse02(void)
{
DetectFileextData *dfd = DetectFileextParse(NULL, "tar.gz", false);
FAIL_IF_NULL(dfd);
Expand All @@ -276,7 +274,7 @@ static int DetectFileextTestParse02 (void)
/**
* \test DetectFileextTestParse03
*/
static int DetectFileextTestParse03 (void)
static int DetectFileextTestParse03(void)
{
DetectFileextData *dfd = DetectFileextParse(NULL, "pdf", false);
FAIL_IF_NULL(dfd);
Expand Down
2 changes: 1 addition & 1 deletion src/detect-fileext.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
#define __DETECT_FILEEXT_H__

/* prototypes */
void DetectFileextRegister (void);
void DetectFileextRegister(void);

#endif /* __DETECT_FILEEXT_H__ */
34 changes: 17 additions & 17 deletions src/detect-filemagic.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ typedef struct DetectFilemagicData {
uint32_t flags;
} DetectFilemagicData;

static int DetectFilemagicMatch (DetectEngineThreadCtx *, Flow *,
uint8_t, File *, const Signature *, const SigMatchCtx *);
static int DetectFilemagicSetup (DetectEngineCtx *, Signature *, const char *);
static int DetectFilemagicMatch(
DetectEngineThreadCtx *, Flow *, uint8_t, File *, const Signature *, const SigMatchCtx *);
static int DetectFilemagicSetup(DetectEngineCtx *, Signature *, const char *);
#ifdef UNITTESTS
static void DetectFilemagicRegisterTests(void);
#endif
Expand Down Expand Up @@ -121,7 +121,7 @@ void DetectFilemagicRegister(void)
sigmatch_table[DETECT_FILEMAGIC].url = "/rules/file-keywords.html#filemagic";
sigmatch_table[DETECT_FILEMAGIC].FileMatch = DetectFilemagicMatch;
sigmatch_table[DETECT_FILEMAGIC].Setup = DetectFilemagicSetup;
sigmatch_table[DETECT_FILEMAGIC].Free = DetectFilemagicFree;
sigmatch_table[DETECT_FILEMAGIC].Free = DetectFilemagicFree;
#ifdef UNITTESTS
sigmatch_table[DETECT_FILEMAGIC].RegisterTests = DetectFilemagicRegisterTests;
#endif
Expand Down Expand Up @@ -208,15 +208,16 @@ int FilemagicThreadLookup(magic_t *ctx, File *file)
* \retval 0 no match
* \retval 1 match
*/
static int DetectFilemagicMatch (DetectEngineThreadCtx *det_ctx,
Flow *f, uint8_t flags, File *file, const Signature *s, const SigMatchCtx *m)
static int DetectFilemagicMatch(DetectEngineThreadCtx *det_ctx, Flow *f, uint8_t flags, File *file,
const Signature *s, const SigMatchCtx *m)
{
SCEnter();
int ret = 0;
DetectFilemagicData *filemagic = (DetectFilemagicData *)m;

DetectFilemagicThreadData *tfilemagic =
(DetectFilemagicThreadData *)DetectThreadCtxGetKeywordThreadCtx(det_ctx, g_magic_thread_ctx_id);
(DetectFilemagicThreadData *)DetectThreadCtxGetKeywordThreadCtx(
det_ctx, g_magic_thread_ctx_id);
if (tfilemagic == NULL) {
SCReturnInt(0);
}
Expand All @@ -231,8 +232,7 @@ static int DetectFilemagicMatch (DetectEngineThreadCtx *det_ctx,
/* we include the \0 in the inspection, so patterns can match on the
* end of the string. */
if (BoyerMooreNocase(filemagic->name, filemagic->len, (uint8_t *)file->magic,
strlen(file->magic) + 1, filemagic->bm_ctx) != NULL)
{
strlen(file->magic) + 1, filemagic->bm_ctx) != NULL) {
#ifdef DEBUG
if (SCLogDebugEnabled()) {
char *name = SCMalloc(filemagic->len + 1);
Expand Down Expand Up @@ -266,7 +266,8 @@ static int DetectFilemagicMatch (DetectEngineThreadCtx *det_ctx,
* \retval filemagic pointer to DetectFilemagicData on success
* \retval NULL on failure
*/
static DetectFilemagicData *DetectFilemagicParse (DetectEngineCtx *de_ctx, const char *str, bool negate)
static DetectFilemagicData *DetectFilemagicParse(
DetectEngineCtx *de_ctx, const char *str, bool negate)
{
DetectFilemagicData *filemagic = NULL;

Expand All @@ -277,7 +278,7 @@ static DetectFilemagicData *DetectFilemagicParse (DetectEngineCtx *de_ctx, const

memset(filemagic, 0x00, sizeof(DetectFilemagicData));

if (DetectContentDataParse ("filemagic", str, &filemagic->name, &filemagic->len) == -1) {
if (DetectContentDataParse("filemagic", str, &filemagic->name, &filemagic->len) == -1) {
goto error;
}

Expand Down Expand Up @@ -381,7 +382,7 @@ static int DetectFilemagicSetup (DetectEngineCtx *de_ctx, Signature *s, const ch

SigMatchAppendSMToList(s, sm, g_file_match_list_id);

s->file_flags |= (FILE_SIG_NEED_FILE|FILE_SIG_NEED_MAGIC);
s->file_flags |= (FILE_SIG_NEED_FILE | FILE_SIG_NEED_MAGIC);
return 0;

error:
Expand Down Expand Up @@ -582,7 +583,7 @@ static int PrefilterMpmFilemagicRegister(DetectEngineCtx *de_ctx, SigGroupHead *
/**
* \test DetectFilemagicTestParse01
*/
static int DetectFilemagicTestParse01 (void)
static int DetectFilemagicTestParse01(void)
{
DetectFilemagicData *dnd = DetectFilemagicParse(NULL, "secret.pdf", false);
FAIL_IF_NULL(dnd);
Expand All @@ -593,7 +594,7 @@ static int DetectFilemagicTestParse01 (void)
/**
* \test DetectFilemagicTestParse02
*/
static int DetectFilemagicTestParse02 (void)
static int DetectFilemagicTestParse02(void)
{
DetectFilemagicData *dnd = DetectFilemagicParse(NULL, "backup.tar.gz", false);
FAIL_IF_NULL(dnd);
Expand All @@ -606,7 +607,7 @@ static int DetectFilemagicTestParse02 (void)
/**
* \test DetectFilemagicTestParse03
*/
static int DetectFilemagicTestParse03 (void)
static int DetectFilemagicTestParse03(void)
{
DetectFilemagicData *dnd = DetectFilemagicParse(NULL, "cmd.exe", false);
FAIL_IF_NULL(dnd);
Expand All @@ -625,6 +626,5 @@ void DetectFilemagicRegisterTests(void)
UtRegisterTest("DetectFilemagicTestParse02", DetectFilemagicTestParse02);
UtRegisterTest("DetectFilemagicTestParse03", DetectFilemagicTestParse03);
}
#endif /* UNITTESTS */
#endif /* UNITTESTS */
#endif /* HAVE_MAGIC */

28 changes: 14 additions & 14 deletions src/detect-filename.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ typedef struct DetectFilenameData {
uint32_t flags;
} DetectFilenameData;

static int DetectFilenameMatch (DetectEngineThreadCtx *, Flow *,
uint8_t, File *, const Signature *, const SigMatchCtx *);
static int DetectFilenameMatch(
DetectEngineThreadCtx *, Flow *, uint8_t, File *, const Signature *, const SigMatchCtx *);
static int DetectFilenameSetup (DetectEngineCtx *, Signature *, const char *);
static int DetectFilenameSetupSticky(DetectEngineCtx *de_ctx, Signature *s, const char *str);
#ifdef UNITTESTS
Expand All @@ -90,7 +90,7 @@ void DetectFilenameRegister(void)
sigmatch_table[DETECT_FILENAME].url = "/rules/file-keywords.html#filename";
sigmatch_table[DETECT_FILENAME].FileMatch = DetectFilenameMatch;
sigmatch_table[DETECT_FILENAME].Setup = DetectFilenameSetup;
sigmatch_table[DETECT_FILENAME].Free = DetectFilenameFree;
sigmatch_table[DETECT_FILENAME].Free = DetectFilenameFree;
#ifdef UNITTESTS
sigmatch_table[DETECT_FILENAME].RegisterTests = DetectFilenameRegisterTests;
#endif
Expand Down Expand Up @@ -159,8 +159,8 @@ void DetectFilenameRegister(void)
* \retval 0 no match
* \retval 1 match
*/
static int DetectFilenameMatch (DetectEngineThreadCtx *det_ctx,
Flow *f, uint8_t flags, File *file, const Signature *s, const SigMatchCtx *m)
static int DetectFilenameMatch(DetectEngineThreadCtx *det_ctx, Flow *f, uint8_t flags, File *file,
const Signature *s, const SigMatchCtx *m)
{
SCEnter();
int ret = 0;
Expand All @@ -170,9 +170,8 @@ static int DetectFilenameMatch (DetectEngineThreadCtx *det_ctx,
if (file->name == NULL)
SCReturnInt(0);

if (BoyerMooreNocase(filename->name, filename->len, file->name,
file->name_len, filename->bm_ctx) != NULL)
{
if (BoyerMooreNocase(filename->name, filename->len, file->name, file->name_len,
filename->bm_ctx) != NULL) {
#ifdef DEBUG
if (SCLogDebugEnabled()) {
char *name = SCMalloc(filename->len + 1);
Expand Down Expand Up @@ -207,13 +206,14 @@ static int DetectFilenameMatch (DetectEngineThreadCtx *det_ctx,
* \retval filename pointer to DetectFilenameData on success
* \retval NULL on failure
*/
static DetectFilenameData *DetectFilenameParse (DetectEngineCtx *de_ctx, const char *str, bool negate)
static DetectFilenameData *DetectFilenameParse(
DetectEngineCtx *de_ctx, const char *str, bool negate)
{
DetectFilenameData *filename = SCCalloc(1, sizeof(DetectFilenameData));
if (unlikely(filename == NULL))
return NULL;

if (DetectContentDataParse ("filename", str, &filename->name, &filename->len) == -1) {
if (DetectContentDataParse("filename", str, &filename->name, &filename->len) == -1) {
goto error;
}

Expand Down Expand Up @@ -281,7 +281,7 @@ static int DetectFilenameSetup (DetectEngineCtx *de_ctx, Signature *s, const cha

SigMatchAppendSMToList(s, sm, g_file_match_list_id);

s->file_flags |= (FILE_SIG_NEED_FILE|FILE_SIG_NEED_FILENAME);
s->file_flags |= (FILE_SIG_NEED_FILE | FILE_SIG_NEED_FILENAME);
return 0;

error:
Expand Down Expand Up @@ -480,7 +480,7 @@ static int DetectFilenameSignatureParseTest01(void)
/**
* \test DetectFilenameTestParse01
*/
static int DetectFilenameTestParse01 (void)
static int DetectFilenameTestParse01(void)
{
DetectFilenameData *dnd = DetectFilenameParse(NULL, "secret.pdf", false);
FAIL_IF_NULL(dnd);
Expand All @@ -491,7 +491,7 @@ static int DetectFilenameTestParse01 (void)
/**
* \test DetectFilenameTestParse02
*/
static int DetectFilenameTestParse02 (void)
static int DetectFilenameTestParse02(void)
{
DetectFilenameData *dnd = DetectFilenameParse(NULL, "backup.tar.gz", false);
FAIL_IF_NULL(dnd);
Expand All @@ -504,7 +504,7 @@ static int DetectFilenameTestParse02 (void)
/**
* \test DetectFilenameTestParse03
*/
static int DetectFilenameTestParse03 (void)
static int DetectFilenameTestParse03(void)
{
DetectFilenameData *dnd = DetectFilenameParse(NULL, "cmd.exe", false);
FAIL_IF_NULL(dnd);
Expand Down
4 changes: 2 additions & 2 deletions src/detect-tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ typedef struct DetectTlsData_ {
uint16_t ver; /** tls version to match */
uint32_t flags; /** flags containing match variant (Negation for example) */
char * subject; /** tls certificate subject substring to match */
char * issuerdn; /** tls certificate issuerDN substring to match */
char * fingerprint; /** tls fingerprint substring to match */
char *issuerdn; /** tls certificate issuerDN substring to match */
char *fingerprint; /** tls fingerprint substring to match */
} DetectTlsData;

/* prototypes */
Expand Down

0 comments on commit 161a53e

Please sign in to comment.