multipath-tools: Fix more strncpy(X, Y, size - 1) calls
authorMartin Wilck <mwilck@suse.com>
Mon, 24 Jun 2019 09:27:31 +0000 (11:27 +0200)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Wed, 3 Jul 2019 06:30:42 +0000 (08:30 +0200)
The compiler emitted no warnings for these, but for consistency
it makes sense to fix them, too.

Signed-off-by: Martin Wilck <mwilck@suse.com>
libmpathpersist/mpath_persist.c
libmultipath/configure.c
libmultipath/prio.c
libmultipath/structs_vec.c
multipathd/waiter.c

index 4abcaed..53022f5 100644 (file)
@@ -618,7 +618,7 @@ int send_prout_activepath(char * dev, int rq_servact, int rq_scope,
        int rc;
 
        memset(&thread, 0, sizeof(thread));
-       strncpy(param.dev, dev, FILE_NAME_SIZE - 1);
+       strlcpy(param.dev, dev, FILE_NAME_SIZE);
        /* Initialize and set thread joinable attribute */
        pthread_attr_init(&attr);
        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
index 0648c0d..52afa37 100644 (file)
@@ -650,7 +650,7 @@ select_action (struct multipath * mpp, vector curmp, int force_reload)
                if (cmpp) {
                        condlog(2, "%s: rename %s to %s", mpp->wwid,
                                cmpp->alias, mpp->alias);
-                       strncpy(mpp->alias_old, cmpp->alias, WWID_SIZE - 1);
+                       strlcpy(mpp->alias_old, cmpp->alias, WWID_SIZE);
                        mpp->action = ACT_RENAME;
                        if (force_reload) {
                                mpp->force_udev_reload = 1;
@@ -1257,7 +1257,7 @@ int coalesce_paths (struct vectors * vecs, vector newmp, char * refwwid,
                        if (!deadmap(mpp))
                                continue;
 
-                       strncpy(alias, mpp->alias, WWID_SIZE - 1);
+                       strlcpy(alias, mpp->alias, WWID_SIZE);
 
                        vector_del_slot(newmp, i);
                        i--;
index 0590218..87de1f9 100644 (file)
@@ -5,6 +5,7 @@
 #include <sys/stat.h>
 
 #include "debug.h"
+#include "util.h"
 #include "prio.h"
 
 static LIST_HEAD(prioritizers);
@@ -166,7 +167,7 @@ void prio_get (char *multipath_dir, struct prio * dst, char * name, char * args)
 
        strncpy(dst->name, src->name, PRIO_NAME_LEN);
        if (args)
-               strncpy(dst->args, args, PRIO_ARGS_LEN - 1);
+               strlcpy(dst->args, args, PRIO_ARGS_LEN);
        dst->getprio = src->getprio;
        dst->handle = NULL;
 
index db5d19d..c43b58f 100644 (file)
@@ -2,6 +2,7 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "util.h"
 #include "checkers.h"
 #include "vector.h"
 #include "defaults.h"
@@ -350,7 +351,7 @@ find_existing_alias (struct multipath * mpp,
 
        vector_foreach_slot (vecs->mpvec, mp, i)
                if (strncmp(mp->wwid, mpp->wwid, WWID_SIZE - 1) == 0) {
-                       strncpy(mpp->alias_old, mp->alias, WWID_SIZE - 1);
+                       strlcpy(mpp->alias_old, mp->alias, WWID_SIZE);
                        return;
                }
 }
index 5895f15..eb8d699 100644 (file)
@@ -11,6 +11,7 @@
 #include <signal.h>
 #include <urcu.h>
 
+#include "util.h"
 #include "vector.h"
 #include "memory.h"
 #include "checkers.h"
@@ -210,7 +211,7 @@ int start_waiter_thread (struct multipath *mpp, struct vectors *vecs)
        if (!wp)
                goto out;
 
-       strncpy(wp->mapname, mpp->alias, WWID_SIZE - 1);
+       strlcpy(wp->mapname, mpp->alias, WWID_SIZE);
        wp->vecs = vecs;
 
        if (pthread_create(&wp->thread, &waiter_attr, waitevent, wp)) {