[PATCH i-g-t v2 02/21] lib/igt_drm_fdinfo: Assert pdev is not truncated

Lucas De Marchi lucas.demarchi at intel.com
Tue Apr 23 23:44:12 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.

Reviewed-by: Umesh Nerlige Ramappa <umesh.nerlige.ramappa at intel.com>
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 a1f4ad10d..bc3082d42 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,
 			good++;
 		} else if ((v = find_kv(l, "drm-pdev", strlen("drm-pdev")))) {
 			/* optional */
+			assert(strlen(v) < sizeof(info->pdev));
 			strncpy(info->pdev, v, sizeof(info->pdev) - 1);
 		} else if (!strncmp(l, "drm-engine-capacity-", 20)) {
 			idx = parse_engine(l, info,
-- 
2.43.0



More information about the igt-dev mailing list