diff --git a/sbin/devd/tests/client_test.c b/sbin/devd/tests/client_test.c --- a/sbin/devd/tests/client_test.c +++ b/sbin/devd/tests/client_test.c @@ -22,15 +22,14 @@ * SUCH DAMAGE. */ -#include -#include -#include - #include -#include #include #include +#include +#include +#include + #include const char create_pat[] = "!system=DEVFS subsystem=CDEV type=CREATE cdev=md"; @@ -134,29 +133,33 @@ ATF_TC_WITHOUT_HEAD(stream); ATF_TC_BODY(stream, tc) { + char *event; int s; bool got_create_event = false; bool got_destroy_event = false; - ssize_t len = 0; + size_t len = 0, sz; s = common_setup(SOCK_STREAM, "/var/run/devd.pipe"); + + sz = 1024 * 1024; + event = malloc(sz); + ATF_REQUIRE(event != NULL); + /* * Loop until both events are detected on the same or different reads. * There may be extra events due to unrelated system activity. * If we never get both events, then the test will timeout. */ - while (!(got_create_event && got_destroy_event)) { - char event[1024]; + while (!(got_create_event && got_destroy_event) && len < sz - 1) { ssize_t newlen; char *create_pos, *destroy_pos; /* Read 1 less than sizeof(event) to allow space for NULL */ - newlen = read(s, &event[len], sizeof(event) - len - 1); - ATF_REQUIRE(newlen != -1); + newlen = read(s, &event[len], sz - len - 1); + ATF_REQUIRE(newlen >= 0); len += newlen; /* NULL terminate the result */ event[len] = '\0'; - printf("%s", event); create_pos = strstr(event, create_pat); if (create_pos != NULL) @@ -166,7 +169,11 @@ if (destroy_pos != NULL) got_destroy_event = true; } + printf("%s", event); + if (len >= sz - 1) + atf_tc_fail("Event buffer overflowed"); + free(event); close(s); }