diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c index 9b1aa537..cc96015f 100644 --- a/tests/modetest/modetest.c +++ b/tests/modetest/modetest.c @@ -817,7 +817,7 @@ struct pipe_arg { unsigned int num_cons; uint32_t crtc_id; char mode_str[64]; - char format_str[5]; + char format_str[8]; /* need to leave room for "_BE" and terminating \0 */ float vrefresh; unsigned int fourcc; drmModeModeInfo *mode; @@ -841,7 +841,7 @@ struct plane_arg { unsigned int old_fb_id; struct bo *bo; struct bo *old_bo; - char format_str[5]; /* need to leave room for terminating \0 */ + char format_str[8]; /* need to leave room for "_BE" and terminating \0 */ unsigned int fourcc; }; @@ -2032,8 +2032,9 @@ static int parse_connector(struct pipe_arg *pipe, const char *arg) } if (*p == '@') { - strncpy(pipe->format_str, p + 1, 4); - pipe->format_str[4] = '\0'; + len = sizeof(pipe->format_str) - 1; + strncpy(pipe->format_str, p + 1, len); + pipe->format_str[len] = '\0'; } pipe->fourcc = util_format_fourcc(pipe->format_str); @@ -2047,6 +2048,7 @@ static int parse_connector(struct pipe_arg *pipe, const char *arg) static int parse_plane(struct plane_arg *plane, const char *p) { + unsigned int len; char *end; plane->plane_id = strtoul(p, &end, 10); @@ -2085,8 +2087,9 @@ static int parse_plane(struct plane_arg *plane, const char *p) } if (*end == '@') { - strncpy(plane->format_str, end + 1, 4); - plane->format_str[4] = '\0'; + len = sizeof(plane->format_str) - 1; + strncpy(plane->format_str, end + 1, len); + plane->format_str[len] = '\0'; } else { strcpy(plane->format_str, "XR24"); }