1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2024-11-13 11:04:27 -05:00

Change and test cmdline

This commit is contained in:
Alex Kotov 2022-01-22 03:07:05 +05:00
parent ede299ad8b
commit 8038b50000
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
2 changed files with 33 additions and 33 deletions

View file

@ -140,7 +140,7 @@ bool kernaux_cmdline(
state = FINAL; state = FINAL;
*(buffer++) = '\0'; *(buffer++) = '\0';
buffer_pos = 0; ++buffer_pos;
} else if (cur == ' ') { } else if (cur == ' ') {
if (buffer_pos >= buffer_size) { if (buffer_pos >= buffer_size) {
strcpy(error_msg, "buffer overflow"); strcpy(error_msg, "buffer overflow");
@ -149,7 +149,7 @@ bool kernaux_cmdline(
state = WHITESPACE; state = WHITESPACE;
*(buffer++) = '\0'; *(buffer++) = '\0';
buffer_pos = 0; ++buffer_pos;
} else if (cur == '\\') { } else if (cur == '\\') {
state = BACKSLASH; state = BACKSLASH;
} else if (cur == '"') { } else if (cur == '"') {
@ -196,7 +196,7 @@ bool kernaux_cmdline(
state = WHITESPACE; state = WHITESPACE;
*(buffer++) = '\0'; *(buffer++) = '\0';
buffer_pos = 0; ++buffer_pos;
} else { } else {
if (buffer_pos >= buffer_size) { if (buffer_pos >= buffer_size) {
strcpy(error_msg, "buffer overflow"); strcpy(error_msg, "buffer overflow");

View file

@ -101,21 +101,21 @@ int main()
test(" \"foo\" \"bar\" ", 0, 0, true, "", 2, argv_foo_bar); test(" \"foo\" \"bar\" ", 0, 0, true, "", 2, argv_foo_bar);
test("\"foo\" \"bar\" \"car\"", 0, 0, true, "", 3, argv_foo_bar_car); test("\"foo\" \"bar\" \"car\"", 0, 0, true, "", 3, argv_foo_bar_car);
test("foo bar car", 3, 0, true, "", 3, argv_foo_bar_car); test("foo bar car", 3, 0, true, "", 3, argv_foo_bar_car);
test("foo bar car", 0, 4, true, "", 3, argv_foo_bar_car); test("foo bar car", 0, 12, true, "", 3, argv_foo_bar_car);
test("foo bar car", 3, 4, true, "", 3, argv_foo_bar_car); test("foo bar car", 3, 12, true, "", 3, argv_foo_bar_car);
test("foo bar car", 2, 0, false, "too many args", 0, NULL); test("foo bar car", 2, 0, false, "too many args", 0, NULL);
test("foo bar car", 0, 3, false, "buffer overflow", 0, NULL); test("foo bar car", 0, 11, false, "buffer overflow", 0, NULL);
test("foo bar car", 2, 3, false, "buffer overflow", 0, NULL); test("foo bar car", 2, 11, false, "too many args", 0, NULL);
test("\"foo\" \"bar\" \"car\"", 3, 0, true, "", 3, argv_foo_bar_car); test("\"foo\" \"bar\" \"car\"", 3, 0, true, "", 3, argv_foo_bar_car);
test("\"foo\" \"bar\" \"car\"", 0, 4, true, "", 3, argv_foo_bar_car); test("\"foo\" \"bar\" \"car\"", 0, 12, true, "", 3, argv_foo_bar_car);
test("\"foo\" \"bar\" \"car\"", 3, 4, true, "", 3, argv_foo_bar_car); test("\"foo\" \"bar\" \"car\"", 3, 12, true, "", 3, argv_foo_bar_car);
test("\"foo\" \"bar\" \"car\"", 2, 0, false, "too many args", 0, NULL); test("\"foo\" \"bar\" \"car\"", 2, 0, false, "too many args", 0, NULL);
test("\"foo\" \"bar\" \"car\"", 0, 3, false, "buffer overflow", 0, NULL); test("\"foo\" \"bar\" \"car\"", 0, 11, false, "buffer overflow", 0, NULL);
test("\"foo\" \"bar\" \"car\"", 2, 3, false, "buffer overflow", 0, NULL); test("\"foo\" \"bar\" \"car\"", 2, 11, false, "too many args", 0, NULL);
test("\\ ", 0, 0, true, "", 1, argv_space); test("\\ ", 0, 0, true, "", 1, argv_space);
test("\"\\ \"", 0, 0, true, "", 1, argv_space); test("\"\\ \"", 0, 0, true, "", 1, argv_space);
@ -191,25 +191,25 @@ int main()
test("foo \"bar car\"", 0, 0, true, "", 2, argv_foo_barspacecar); test("foo \"bar car\"", 0, 0, true, "", 2, argv_foo_barspacecar);
test("\"foo\" \"bar car\"", 0, 0, true, "", 2, argv_foo_barspacecar); test("\"foo\" \"bar car\"", 0, 0, true, "", 2, argv_foo_barspacecar);
test("\\ \\ \\ \\ \\ \\ \\ \\ \\ ", 3, 0, true, "", 3, argv_spaceX3_X3); test("\\ \\ \\ \\ \\ \\ \\ \\ \\ ", 3, 0, true, "", 3, argv_spaceX3_X3);
test("\\\\\\\\\\\\ \\\\\\\\\\\\ \\\\\\\\\\\\", 3, 0, true, "", 3, argv_backslashX3_X3); test("\\\\\\\\\\\\ \\\\\\\\\\\\ \\\\\\\\\\\\", 3, 0, true, "", 3, argv_backslashX3_X3);
test("\\\"\\\"\\\" \\\"\\\"\\\" \\\"\\\"\\\"", 3, 0, true, "", 3, argv_quotmarkX3_X3); test("\\\"\\\"\\\" \\\"\\\"\\\" \\\"\\\"\\\"", 3, 0, true, "", 3, argv_quotmarkX3_X3);
test("\\ \\ \\ \\ \\ \\ \\ \\ \\ ", 0, 4, true, "", 3, argv_spaceX3_X3); test("\\ \\ \\ \\ \\ \\ \\ \\ \\ ", 0, 12, true, "", 3, argv_spaceX3_X3);
test("\\\\\\\\\\\\ \\\\\\\\\\\\ \\\\\\\\\\\\", 0, 4, true, "", 3, argv_backslashX3_X3); test("\\\\\\\\\\\\ \\\\\\\\\\\\ \\\\\\\\\\\\", 0, 12, true, "", 3, argv_backslashX3_X3);
test("\\\"\\\"\\\" \\\"\\\"\\\" \\\"\\\"\\\"", 0, 4, true, "", 3, argv_quotmarkX3_X3); test("\\\"\\\"\\\" \\\"\\\"\\\" \\\"\\\"\\\"", 0, 12, true, "", 3, argv_quotmarkX3_X3);
test("\\ \\ \\ \\ \\ \\ \\ \\ \\ ", 3, 4, true, "", 3, argv_spaceX3_X3); test("\\ \\ \\ \\ \\ \\ \\ \\ \\ ", 3, 12, true, "", 3, argv_spaceX3_X3);
test("\\\\\\\\\\\\ \\\\\\\\\\\\ \\\\\\\\\\\\", 3, 4, true, "", 3, argv_backslashX3_X3); test("\\\\\\\\\\\\ \\\\\\\\\\\\ \\\\\\\\\\\\", 3, 12, true, "", 3, argv_backslashX3_X3);
test("\\\"\\\"\\\" \\\"\\\"\\\" \\\"\\\"\\\"", 3, 4, true, "", 3, argv_quotmarkX3_X3); test("\\\"\\\"\\\" \\\"\\\"\\\" \\\"\\\"\\\"", 3, 12, true, "", 3, argv_quotmarkX3_X3);
test("\\ \\ \\ \\ \\ \\ \\ \\ \\ ", 2, 0, false, "too many args", 0, NULL); test("\\ \\ \\ \\ \\ \\ \\ \\ \\ ", 2, 0, false, "too many args", 0, NULL);
test("\\\\\\\\\\\\ \\\\\\\\\\\\ \\\\\\\\\\\\", 2, 0, false, "too many args", 0, NULL); test("\\\\\\\\\\\\ \\\\\\\\\\\\ \\\\\\\\\\\\", 2, 0, false, "too many args", 0, NULL);
test("\\\"\\\"\\\" \\\"\\\"\\\" \\\"\\\"\\\"", 2, 0, false, "too many args", 0, NULL); test("\\\"\\\"\\\" \\\"\\\"\\\" \\\"\\\"\\\"", 2, 0, false, "too many args", 0, NULL);
test("\\ \\ \\ \\ \\ \\ \\ \\ \\ ", 0, 3, false, "buffer overflow", 0, NULL); test("\\ \\ \\ \\ \\ \\ \\ \\ \\ ", 0, 11, false, "buffer overflow", 0, NULL);
test("\\\\\\\\\\\\ \\\\\\\\\\\\ \\\\\\\\\\\\", 0, 3, false, "buffer overflow", 0, NULL); test("\\\\\\\\\\\\ \\\\\\\\\\\\ \\\\\\\\\\\\", 0, 11, false, "buffer overflow", 0, NULL);
test("\\\"\\\"\\\" \\\"\\\"\\\" \\\"\\\"\\\"", 0, 3, false, "buffer overflow", 0, NULL); test("\\\"\\\"\\\" \\\"\\\"\\\" \\\"\\\"\\\"", 0, 11, false, "buffer overflow", 0, NULL);
test("\\ \\ \\ \\ \\ \\ \\ \\ \\ ", 2, 3, false, "buffer overflow", 0, NULL); test("\\ \\ \\ \\ \\ \\ \\ \\ \\ ", 2, 11, false, "too many args", 0, NULL);
test("\\\\\\\\\\\\ \\\\\\\\\\\\ \\\\\\\\\\\\", 2, 3, false, "buffer overflow", 0, NULL); test("\\\\\\\\\\\\ \\\\\\\\\\\\ \\\\\\\\\\\\", 2, 11, false, "too many args", 0, NULL);
test("\\\"\\\"\\\" \\\"\\\"\\\" \\\"\\\"\\\"", 2, 3, false, "buffer overflow", 0, NULL); test("\\\"\\\"\\\" \\\"\\\"\\\" \\\"\\\"\\\"", 2, 11, false, "too many args", 0, NULL);
test("\\", 0, 0, false, "EOL after backslash", 0, NULL); test("\\", 0, 0, false, "EOL after backslash", 0, NULL);
test(" \\", 0, 0, false, "EOL after backslash", 0, NULL); test(" \\", 0, 0, false, "EOL after backslash", 0, NULL);