]> git.eshelyaron.com Git - emacs.git/commitdiff
Check for snprintf truncation in pgtkterm
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 22 Jan 2025 06:19:08 +0000 (22:19 -0800)
committerEshel Yaron <me@eshelyaron.com>
Thu, 23 Jan 2025 10:25:08 +0000 (11:25 +0100)
* src/pgtkterm.c (pgtk_enumerate_devices):
Abort if snprintf truncated.

(cherry picked from commit db9ea9b77a0d03342bfe2a976b3943de5e5a4518)

src/pgtkterm.c

index 413cbd86c0d58e67d2122ef94f78b7c85a8d4df6..30679353c1b26beda9c450a67adf6700c00c11a3 100644 (file)
@@ -183,9 +183,10 @@ pgtk_enumerate_devices (struct pgtk_display_info *dpyinfo,
          rec->seat = g_object_ref (seat);
          rec->device = GDK_DEVICE (t1->data);
 
-         snprintf (printbuf, 1026, "%u:%s",
-                   gdk_device_get_source (rec->device),
-                   gdk_device_get_name (rec->device));
+         int len = snprintf (printbuf, sizeof printbuf, "%u:%s",
+                             gdk_device_get_source (rec->device),
+                             gdk_device_get_name (rec->device));
+         eassert (len < sizeof printbuf);
 
          rec->name = build_string (printbuf);
          rec->next = dpyinfo->devices;