Skip to content

Commit e62a849

Browse files
committed
add forward declaration to get rid of compile warning
1 parent f86242b commit e62a849

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

auparse/expression.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,23 +391,39 @@ parse_timestamp_value(struct expr *dest, struct parsing *p)
391391
* On a timestamp field we will do all the parsing ourselves
392392
* rather than use lex(). At the end we will move the internal cursor.
393393
*/
394-
if (sscanf(p->token_start, "ts:%jd.%u:%u", &sec,
395-
&dest->v.p.value.timestamp_ex.milli,
396-
&dest->v.p.value.timestamp_ex.serial) != 3) {
397-
if (sscanf(p->token_start, "ts:%jd.%u", &sec,
398-
&dest->v.p.value.timestamp.milli) != 2) {
394+
int ret;
395+
396+
ret = sscanf(p->token_start, "ts:%jd.%u:%u", &sec,
397+
&dest->v.p.value.timestamp_ex.milli,
398+
&dest->v.p.value.timestamp_ex.serial);
399+
if (ret != 3) {
400+
ret = sscanf(p->token_start, "ts:%jd.%u", &sec,
401+
&dest->v.p.value.timestamp.milli);
402+
if (ret != 2) {
399403
if (asprintf(p->error, "Invalid timestamp value `%.*s'",
400404
p->token_len, p->token_start) < 0)
401405
*p->error = NULL;
402406
return -1;
403407
}
408+
if (dest->v.p.value.timestamp.milli >= 1000) {
409+
if (asprintf(p->error,
410+
"Millisecond out of range in `%.*s'",
411+
p->token_len, p->token_start) < 0)
412+
*p->error = NULL;
413+
return -1;
414+
}
415+
} else if (dest->v.p.value.timestamp_ex.milli >= 1000) {
416+
if (asprintf(p->error,
417+
"Millisecond out of range in `%.*s'",
418+
p->token_len, p->token_start) < 0)
419+
*p->error = NULL;
420+
return -1;
404421
}
405422

406423
/* Move the cursor past what we parsed. */
407424
size_t num = strspn(p->token_start, "ts:0123456789.");
408425
p->src = p->token_start + num;
409426

410-
/* FIXME: validate milli */
411427
dest->v.p.value.timestamp.sec = sec;
412428
if (dest->v.p.value.timestamp.sec != sec) {
413429
if (asprintf(p->error, "Timestamp overflow in `%.*s'",

auparse/test/auparse_extra_test.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <assert.h>
33
#include <stdio.h>
44
#include <string.h>
5+
#include <stdlib.h>
56
#include "libaudit.h"
67
#include "auparse.h"
78

@@ -73,12 +74,39 @@ static void test_compare(void)
7374
auparse_destroy(au);
7475
}
7576

77+
/* Test parsing of timestamp expressions for millisecond range. */
78+
static void test_timestamp_milli(void)
79+
{
80+
auparse_state_t *au;
81+
char *err = NULL;
82+
int rc;
83+
84+
au = auparse_init(AUSOURCE_FILE, "./test.log");
85+
assert(au != NULL);
86+
87+
rc = ausearch_add_expression(au,
88+
"\\timestamp == ts:1.999",
89+
&err, AUSEARCH_RULE_CLEAR);
90+
assert(rc == 0);
91+
assert(err == NULL);
92+
93+
rc = ausearch_add_expression(au,
94+
"\\timestamp == ts:1.1000",
95+
&err, AUSEARCH_RULE_CLEAR);
96+
assert(rc == -1);
97+
assert(err != NULL);
98+
free(err);
99+
100+
auparse_destroy(au);
101+
}
102+
76103
int main(void)
77104
{
78105
test_new_buffer();
79106
test_feed_state();
80107
test_normalize();
81108
test_compare();
109+
test_timestamp_milli();
82110
printf("extra auparse tests: all passed\n");
83111
return 0;
84112
}

lib/private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ const char *audit_perm_to_name(int perm);
135135
AUDIT_HIDDEN_END
136136

137137
// libaudit.c
138+
struct audit_rule_data; // Forward declaration to prevent warnings
138139
int _audit_parse_syscall(const char *optarg, struct audit_rule_data *rule);
139140
extern int _audit_permadded;
140141
extern int _audit_archadded;

0 commit comments

Comments
 (0)