Skip to content

Commit a927c9c

Browse files
committed
Add tests for path_norm in auparse
Added a fuzz test for path normalization that generates all permutations of “/”, “a”, and “.”, converts each to hexadecimal, and feeds it through auparse_do_interpretation to ensure path_norm can process unusual paths without crashing. Needs address sanitizer to catch bugs.
1 parent 44ad9cc commit a927c9c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

auparse/test/auparse_extra_test.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <stdlib.h>
66
#include "libaudit.h"
77
#include "auparse.h"
8+
#include "auparse-idata.h"
89

910
static void test_new_buffer(void)
1011
{
@@ -100,13 +101,50 @@ static void test_timestamp_milli(void)
100101
auparse_destroy(au);
101102
}
102103

104+
/* Fuzz path_norm via AUPARSE_TYPE_ESCAPED_FILE interpretations. */
105+
static void test_path_norm(void)
106+
{
107+
const char chars[] = "/a.";
108+
char fuzz[10];
109+
unsigned seeds = 1;
110+
size_t i;
111+
idata id = {
112+
.name = "name",
113+
};
114+
char *out, val[2*sizeof(fuzz)+1];
115+
auparse_state_t *au;
116+
117+
id.cwd = strdup("2F");
118+
for (i = 0; i < sizeof(fuzz) - 1; i++)
119+
seeds *= 3;
120+
au = auparse_init(AUSOURCE_FILE, "/dev/null");
121+
assert(au != NULL);
122+
for (unsigned s = 0; s < seeds; s++) {
123+
unsigned k = s;
124+
for (i = 0; i < sizeof(fuzz) - 1; i++, k /= 3)
125+
fuzz[i] = chars[k % 3];
126+
127+
fuzz[sizeof(fuzz) - 1] = '\0';
128+
audit_encode_value(val, fuzz, sizeof(fuzz));
129+
id.val = val;
130+
out = auparse_do_interpretation(au, AUPARSE_TYPE_ESCAPED_FILE,
131+
&id, AUPARSE_ESC_RAW);
132+
assert(out != NULL);
133+
printf("Normalizing path %s to %s\n", val, out);
134+
free(out);
135+
}
136+
free(id.cwd);
137+
auparse_destroy(au);
138+
}
139+
103140
int main(void)
104141
{
105142
test_new_buffer();
106143
test_feed_state();
107144
test_normalize();
108145
test_compare();
109146
test_timestamp_milli();
147+
test_path_norm();
110148
printf("extra auparse tests: all passed\n");
111149
return 0;
112150
}

0 commit comments

Comments
 (0)