]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
seq: use safer way to copy strings
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Sat, 28 Aug 2021 02:51:36 +0000 (11:51 +0900)
committer坂本 貴史 <o-takashi@sakamocchi.jp>
Sat, 28 Aug 2021 23:49:45 +0000 (08:49 +0900)
The call of strncpy can results in destination buffer without null as
terminator in the case of truncation. Compiler reports the risk as
warnings, like:

In function ‘strncpy’,
    inlined from ‘alsaseq_get_queue_info_by_name’ at ../src/seq/query.c:670:5:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:95:10: warning: ‘strncpy’ specified bound 64 equals destination size [-Wstringop-truncation]
   95 |   return __builtin___strncpy_chk (__dest, __src, __len,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   96 |       __glibc_objsize (__dest));
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~

This commit uses safer way to copy strings, g_strlcpy(), to fix the bug.

Fixes: 4e8675f631ce ("seq: client_info: add properties and accessor methods")
Fixes: f3457eaf706b ("seq: port_info: add properties")
Fixes: 1eabdf6bc647 ("seq: add global method to get the information of queue")
Fixes: f26342b3ab3d ("seq: queue_info: add properties and constructors")
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
src/seq/client-info.c
src/seq/port-info.c
src/seq/query.c
src/seq/queue-info.c

index 09ef93741b935379c4edbd813127f75ec86ddd28..5e430c8ac013eab922d50f42ec2e567343c91f3a 100644 (file)
@@ -51,7 +51,7 @@ static void seq_client_info_set_property(GObject *obj, guint id,
         priv->info.type = (snd_seq_client_type_t)g_value_get_enum(val);
         break;
     case SEQ_CLIENT_INFO_PROP_NAME:
-        strncpy(priv->info.name, g_value_get_string(val), sizeof(priv->info.name));
+        g_strlcpy(priv->info.name, g_value_get_string(val), sizeof(priv->info.name));
         break;
     case SEQ_CLIENT_INFO_PROP_FILTER_ATTR_FLAGS:
         priv->info.filter &= SNDRV_SEQ_FILTER_USE_EVENT;
index 601ce10c9d42c9ea33ae4245a3ffedd6c54b7742..9092a3d91b5b55795747ee2dcc916c3a00dca38d 100644 (file)
@@ -50,7 +50,7 @@ static void seq_port_info_set_property(GObject *obj, guint id,
         break;
     }
     case SEQ_PORT_INFO_PROP_NAME:
-        strncpy(priv->info.name, g_value_get_string(val), sizeof(priv->info.name));
+        g_strlcpy(priv->info.name, g_value_get_string(val), sizeof(priv->info.name));
         break;
     case SEQ_PORT_INFO_PROP_CAPS:
         priv->info.capability = (unsigned int)g_value_get_flags(val);
index 28d2121cf394db4c5f013d19c722449f7eaa720c..682002cd366d2885910aba9c7085f4cf54272e02 100644 (file)
@@ -667,7 +667,7 @@ void alsaseq_get_queue_info_by_name(const gchar *name,
     *queue_info = g_object_new(ALSASEQ_TYPE_QUEUE_INFO, NULL);
     seq_queue_info_refer_private(*queue_info, &info);
 
-    strncpy(info->name, name, sizeof(info->name));
+    g_strlcpy(info->name, name, sizeof(info->name));
     if (ioctl(fd, SNDRV_SEQ_IOCTL_GET_NAMED_QUEUE, info) < 0) {
         generate_file_error(error, errno, "ioctl(GET_NAMED_QUEUE)");
         g_object_unref(*queue_info);
index 42f3a506cbf45113ede3dbc17a386fb8b22f2977..355757b3e2930d18d17d335963b9449e231f5e54 100644 (file)
@@ -47,7 +47,7 @@ static void seq_queue_info_set_property(GObject *obj, guint id,
         priv->info.locked = g_value_get_boolean(val);
         break;
     case SEQ_QUEUE_INFO_PROP_NAME:
-        strncpy(priv->info.name, g_value_get_string(val), sizeof(priv->info.name));
+        g_strlcpy(priv->info.name, g_value_get_string(val), sizeof(priv->info.name));
         break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec);