From 87333537d2e97f2a9cd5b4e6492ba5c386b3c1ed Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 25 Jul 2025 17:31:42 +0200 Subject: [PATCH] pod: also check 0 terminted strings in copy_string Use get_string() to get a pointer to the string in the pod so that we also check if it has a 0 terminator. Fix the test case now that is_string returns true even for non zero-terminated strings. --- spa/include/spa/pod/iter.h | 4 +--- test/test-spa-pod.c | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/spa/include/spa/pod/iter.h b/spa/include/spa/pod/iter.h index e5ce3f719..cf65b8c62 100644 --- a/spa/include/spa/pod/iter.h +++ b/spa/include/spa/pod/iter.h @@ -297,10 +297,8 @@ SPA_API_POD_ITER int spa_pod_get_string(const struct spa_pod *pod, const char ** SPA_API_POD_ITER int spa_pod_copy_string(const struct spa_pod *pod, size_t maxlen, char *dest) { const char *s; - if (!spa_pod_is_string(pod) || maxlen < 1) + if (spa_pod_get_string(pod, &s) < 0 || maxlen < 1) return -EINVAL; - maxlen = SPA_MIN(maxlen, pod->size); - s = (const char *)SPA_POD_CONTENTS(struct spa_pod_string, pod); strncpy(dest, s, maxlen-1); dest[maxlen-1]= '\0'; return 0; diff --git a/test/test-spa-pod.c b/test/test-spa-pod.c index f499e818b..5c4308b46 100644 --- a/test/test-spa-pod.c +++ b/test/test-spa-pod.c @@ -286,7 +286,7 @@ PWTEST(pod_init) spa_assert_se(SPA_POD_SIZE(&pod) == 14); spa_assert_se(SPA_POD_TYPE(&pod) == SPA_TYPE_String); spa_assert_se(SPA_POD_BODY_SIZE(&pod) == 6); - spa_assert_se(!spa_pod_is_string(&pod.pod.pod)); + spa_assert_se(spa_pod_is_string(&pod.pod.pod)); spa_assert_se(spa_pod_copy_string(&pod.pod.pod, sizeof(val), val) < 0); } {