[PATCH i-g-t 04/12] lib/igt_drm_fdinfo: Assert pdev is not truncated

Lucas De Marchi lucas.demarchi at intel.com
Fri Apr 5 06:00:48 UTC 2024


Since strncpy() may truncate the output, just assert we have enough
room for the string. It's not a big problem since we always copy 1 byte
less than the capacity and info->pdev is zero-allocated. But we may as
well be sure we aren't truncating it.

Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>
---
 lib/igt_drm_fdinfo.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/igt_drm_fdinfo.c b/lib/igt_drm_fdinfo.c
index 9b1776775..de1962efa 100644
--- a/lib/igt_drm_fdinfo.c
+++ b/lib/igt_drm_fdinfo.c
@@ -237,6 +237,7 @@ __igt_parse_drm_fdinfo(int dir, const char *fd, struct drm_client_fdinfo *info,
 		} else if (strstartswith(l, "drm-pdev:", &keylen)) {
 			v = l + keylen;
 			v = ignore_space(v);
+			assert(strlen(v) < sizeof(info->pdev));
 			strncpy(info->pdev, v, sizeof(info->pdev) - 1);
 		} else if (strstartswith(l, "drm-engine-capacity-", &keylen)) {
 			idx = parse_engine(l + keylen, info,
-- 
2.44.0



More information about the igt-dev mailing list