]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
conf: strncat => strlcat
authorDonghwa Jeong <dh48.jeong@samsung.com>
Thu, 21 Jun 2018 02:30:18 +0000 (11:30 +0900)
committerDonghwa Jeong <dh48.jeong@samsung.com>
Fri, 22 Jun 2018 05:12:32 +0000 (14:12 +0900)
Signed-off-by: Donghwa Jeong <dh48.jeong@samsung.com>
src/lxc/conf.c

index 2aff0530017fe4d6cc175fed84bc88df58d3cb34..4e7dc379b64287a25c1f6bcf7bc5beb971fe297b 100644 (file)
 #include <sys/personality.h>
 #endif
 
+#ifndef HAVE_STRLCAT
+#include "include/strlcat.h"
+#endif
+
 #if IS_BIONIC
 #include <../include/lxcmntent.h>
 #else
@@ -841,6 +845,7 @@ static int lxc_setup_dev_symlinks(const struct lxc_rootfs *rootfs)
 static bool append_ttyname(char **pp, char *name)
 {
        char *p;
+       size_t size;
 
        if (!*pp) {
                *pp = malloc(strlen(name) + strlen("container_ttys=") + 1);
@@ -851,13 +856,14 @@ static bool append_ttyname(char **pp, char *name)
                return true;
        }
 
-       p = realloc(*pp, strlen(*pp) + strlen(name) + 2);
+       size = strlen(*pp) + strlen(name) + 2;
+       p = realloc(*pp, size);
        if (!p)
                return false;
 
        *pp = p;
-       strncat(p, " ", 1);
-       strncat(p, name, strlen(name));
+       (void)strlcat(p, " ", size);
+       (void)strlcat(p, name, size);
 
        return true;
 }
@@ -1791,7 +1797,6 @@ static int lxc_setup_console(const struct lxc_rootfs *rootfs,
 static void parse_mntopt(char *opt, unsigned long *flags, char **data, size_t size)
 {
        struct mount_opt *mo;
-       size_t cursize;
 
        /* If opt is found in mount_opt, set or clear flags.
         * Otherwise append it to data. */
@@ -1806,16 +1811,10 @@ static void parse_mntopt(char *opt, unsigned long *flags, char **data, size_t si
                }
        }
 
-       cursize = strlen(*data);
-       if (cursize)
-               cursize += 1;
+       if (strlen(*data))
+               (void)strlcat(*data, ",", size);
 
-       if (size - cursize > 1) {
-               if (cursize)
-                       strncat(*data, ",", 1);
-
-               strncat(*data, opt, size - cursize - 1);
-       }
+       (void)strlcat(*data, opt, size);
 }
 
 int parse_mntopts(const char *mntopts, unsigned long *mntflags, char **mntdata)