[PATCH i-g-t v2 03/21] lib/igt_drm_fdinfo: Detect invalid drm-client-id
Lucas De Marchi
lucas.demarchi at intel.com
Tue Apr 23 23:44:13 UTC 2024
Use strtol() for string to long conversion which allows us to detect if
there was an invalid number. It also has the advantage that it already
ignores leading spaces.
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 | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/lib/igt_drm_fdinfo.c b/lib/igt_drm_fdinfo.c
index bc3082d42..b700ec317 100644
--- a/lib/igt_drm_fdinfo.c
+++ b/lib/igt_drm_fdinfo.c
@@ -224,6 +224,7 @@ __igt_parse_drm_fdinfo(int dir, const char *fd, struct drm_client_fdinfo *info,
while ((l = strtok_r(_buf, "\n", &ctx))) {
uint64_t val = 0;
const char *v;
+ char *end_ptr;
int idx;
_buf = NULL;
@@ -233,8 +234,9 @@ __igt_parse_drm_fdinfo(int dir, const char *fd, struct drm_client_fdinfo *info,
good++;
} else if ((v = find_kv(l, "drm-client-id",
strlen("drm-client-id")))) {
- info->id = atol(v);
- good++;
+ info->id = strtol(v, &end_ptr, 10);
+ if (end_ptr != v)
+ good++;
} else if ((v = find_kv(l, "drm-pdev", strlen("drm-pdev")))) {
/* optional */
assert(strlen(v) < sizeof(info->pdev));
--
2.43.0
More information about the igt-dev
mailing list