summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2022-05-22 13:00:46 -0400
committerNiels De Graef <nielsdegraef@gmail.com>2022-05-31 05:02:26 +0000
commit6c4ad4cff086ba7fd79ef406311a283c6a942baf (patch)
treecea07d6525e5a6c424037200e97d5beb75c34d95
parenta76ebb68bc5d7b9176603902d329283c33422522 (diff)
downloadgnome-keyring-6c4ad4cff086ba7fd79ef406311a283c6a942baf.tar.gz
pkcs11: Don't use strncpy when copying paths
Using strncpy produces the following warning, which indicates that the destination string could be left unterminated. CC daemon/control/gkd-control-server.lo CCLD libgkd-control.la CC pkcs11/rpc-layer/libgkm_rpc_layer_la-gkm-rpc-dispatch.lo In file included from /usr/include/string.h:519, from /usr/include/glib-2.0/glib/galloca.h:33, from /usr/include/glib-2.0/glib.h:30, from ./egg/egg-error.h:24, from pkcs11/rpc-layer/gkm-rpc-dispatch.c:31: In function ‘strncpy’, inlined from ‘gkm_rpc_layer_startup’ at pkcs11/rpc-layer/gkm-rpc-dispatch.c:2382:2: /usr/include/bits/string_fortified.h:95:10: warning: ‘__builtin_strncpy’ specified bound 108 equals destination size [-Wstringop-truncation] 95 | return __builtin___strncpy_chk (__dest, __src, __len, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 96 | __glibc_objsize (__dest)); | ~~~~~~~~~~~~~~~~~~~~~~~~~
-rw-r--r--pkcs11/rpc-layer/gkm-rpc-dispatch.c4
-rw-r--r--pkcs11/rpc-layer/gkm-rpc-module.c4
2 files changed, 6 insertions, 2 deletions
diff --git a/pkcs11/rpc-layer/gkm-rpc-dispatch.c b/pkcs11/rpc-layer/gkm-rpc-dispatch.c
index 72d2ced1..dbedb355 100644
--- a/pkcs11/rpc-layer/gkm-rpc-dispatch.c
+++ b/pkcs11/rpc-layer/gkm-rpc-dispatch.c
@@ -31,6 +31,8 @@
#include "egg/egg-error.h"
#include "egg/egg-unix-credentials.h"
+#include <glib.h>
+
#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
@@ -2379,7 +2381,7 @@ gkm_rpc_layer_startup (const char *prefix)
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
unlink (pkcs11_socket_path);
- strncpy (addr.sun_path, pkcs11_socket_path, sizeof (addr.sun_path));
+ g_strlcpy (addr.sun_path, pkcs11_socket_path, sizeof (addr.sun_path));
if (bind (sock, (struct sockaddr*)&addr, sizeof (addr)) < 0) {
gkm_rpc_warn ("couldn't bind to pkcs11 socket: %s: %s",
pkcs11_socket_path, strerror (errno));
diff --git a/pkcs11/rpc-layer/gkm-rpc-module.c b/pkcs11/rpc-layer/gkm-rpc-module.c
index 24457ce1..515b18a4 100644
--- a/pkcs11/rpc-layer/gkm-rpc-module.c
+++ b/pkcs11/rpc-layer/gkm-rpc-module.c
@@ -29,6 +29,8 @@
#include "egg/egg-unix-credentials.h"
+#include <glib.h>
+
#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
@@ -233,7 +235,7 @@ call_connect (CallState *cs)
debug (("connecting to: %s", pkcs11_socket_path));
addr.sun_family = AF_UNIX;
- strncpy (addr.sun_path, pkcs11_socket_path, sizeof (addr.sun_path));
+ g_strlcpy (addr.sun_path, pkcs11_socket_path, sizeof (addr.sun_path));
sock = socket (AF_UNIX, SOCK_STREAM, 0);
if (sock < 0) {