All of lore.kernel.org
 help / color / mirror / Atom feed
* [igt-dev] [PATCH i-g-t 1/4] lib/igt_device_scan: Fix dangling pointer usage
@ 2022-06-02  8:22 Ryszard Knop
  2022-06-02  8:22 ` [igt-dev] [PATCH i-g-t 2/4] tests/drm_read: pthread_yield -> sched_yield Ryszard Knop
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Ryszard Knop @ 2022-06-02  8:22 UTC (permalink / raw)
  To: Development mailing list for IGT GPU Tools

When the attribute value is duplicated in g_hash_table_insert, v may be
a pointer to linkto, which is no longer in scope at that point.

Signed-off-by: Ryszard Knop <ryszard.knop@intel.com>
---
 lib/igt_device_scan.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/igt_device_scan.c b/lib/igt_device_scan.c
index a1cee7a4..b07268db 100644
--- a/lib/igt_device_scan.c
+++ b/lib/igt_device_scan.c
@@ -337,7 +337,7 @@ static void igt_device_add_prop(struct igt_device *dev,
 static void igt_device_add_attr(struct igt_device *dev,
 				const char *key, const char *value)
 {
-	const char *v = value;
+	char *v;
 
 	if (!key)
 		return;
@@ -345,11 +345,13 @@ static void igt_device_add_attr(struct igt_device *dev,
 	/* It's possible we have symlink at key filename, but udev
 	 * library resolves only few of them
 	 */
-	if (!v) {
+	if (value) {
+		v = strdup(value);
+	} else {
 		struct stat st;
 		char path[PATH_MAX];
 		char linkto[PATH_MAX];
-		int len;
+		ssize_t len;
 
 		snprintf(path, sizeof(path), "%s/%s", dev->syspath, key);
 		if (lstat(path, &st) != 0)
@@ -362,10 +364,11 @@ static void igt_device_add_attr(struct igt_device *dev,
 		v = strrchr(linkto, '/');
 		if (v == NULL)
 			return;
-		v++;
+
+		v = strdup(v + 1);
 	}
 
-	g_hash_table_insert(dev->attrs_ht, strdup(key), strdup(v));
+	g_hash_table_insert(dev->attrs_ht, strdup(key), v);
 }
 
 /* Iterate over udev properties list and rewrite it to igt_device properties
-- 
2.36.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-06-02 11:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-02  8:22 [igt-dev] [PATCH i-g-t 1/4] lib/igt_device_scan: Fix dangling pointer usage Ryszard Knop
2022-06-02  8:22 ` [igt-dev] [PATCH i-g-t 2/4] tests/drm_read: pthread_yield -> sched_yield Ryszard Knop
2022-06-02  8:22 ` [igt-dev] [PATCH i-g-t 3/4] tests/kms_cursor_crc: Increase space for the resolution name Ryszard Knop
2022-06-02  8:22 ` [igt-dev] [PATCH i-g-t 4/4] tests/i915/gem_eio: Fix use after free Ryszard Knop
2022-06-02  9:39 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/4] lib/igt_device_scan: Fix dangling pointer usage Patchwork
2022-06-02 11:15 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.