Skip to content

Commit 8f313f4

Browse files
committed
test-conf-parser: add tests for the new long lines, including overflow handling
1 parent a12807a commit 8f313f4

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

src/test/test-conf-parser.c

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ static void test_config_parse_iec_uint64(void) {
225225
assert_se(config_parse_iec_uint64(NULL, "/this/file", 11, "Section", 22, "Size", 0, "4.5M", &offset, NULL) == 0);
226226
}
227227

228+
#define x10(x) x x x x x x x x x x
229+
#define x100(x) x10(x10(x))
230+
#define x1000(x) x10(x100(x))
231+
228232
static const char* const config_file[] = {
229233
"[Section]\n"
230234
"setting1=1\n",
@@ -251,6 +255,24 @@ static const char* const config_file[] = {
251255
"\\\\2\n", /* note that C requires one level of escaping, so the
252256
* parser gets "…1 BS BS BS NL BS BS 2 NL", which
253257
* it translates into "…1 BS BS SP BS BS 2" */
258+
259+
"\n[Section]\n\n"
260+
"setting1=" /* a line above LINE_MAX length */
261+
x1000("ABCD")
262+
"\n",
263+
264+
"[Section]\n"
265+
"setting1=" /* a line above LINE_MAX length, with continuation */
266+
x1000("ABCD") "\\\n"
267+
"foobar",
268+
269+
"[Section]\n"
270+
"setting1=" /* a line above the allowed limit: 9 + 1050000 + 1 */
271+
x1000(x1000("x") x10("abcde")) "\n",
272+
273+
"[Section]\n"
274+
"setting1=" /* many continuation lines, together above the limit */
275+
x1000(x1000("x") x10("abcde") "\\\n") "xxx",
254276
};
255277

256278
static void test_config_parse(unsigned i, const char *s) {
@@ -290,20 +312,37 @@ static void test_config_parse(unsigned i, const char *s) {
290312
"Section\0",
291313
config_item_table_lookup, items,
292314
false, false, true, NULL);
293-
assert_se(r == 0);
294315

295316
switch (i) {
296317
case 0 ... 3:
318+
assert_se(r == 0);
297319
assert_se(streq(setting1, "1"));
298320
break;
299321

300322
case 4:
323+
assert_se(r == 0);
301324
assert_se(streq(setting1, "1 2 3"));
302325
break;
303326

304327
case 5:
328+
assert_se(r == 0);
305329
assert_se(streq(setting1, "1\\\\ \\\\2"));
306330
break;
331+
332+
case 6:
333+
assert_se(r == 0);
334+
assert_se(streq(setting1, x1000("ABCD")));
335+
break;
336+
337+
case 7:
338+
assert_se(r == 0);
339+
assert_se(streq(setting1, x1000("ABCD") " foobar"));
340+
break;
341+
342+
case 8 ... 9:
343+
assert_se(r == -ENOBUFS);
344+
assert_se(setting1 == NULL);
345+
break;
307346
}
308347
}
309348

0 commit comments

Comments
 (0)