]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
tool_utils: strncat => strlcat
authorDonghwa Jeong <dh48.jeong@samsung.com>
Thu, 21 Jun 2018 04:20:17 +0000 (13:20 +0900)
committerDonghwa Jeong <dh48.jeong@samsung.com>
Fri, 22 Jun 2018 05:13:36 +0000 (14:13 +0900)
Signed-off-by: Donghwa Jeong <dh48.jeong@samsung.com>
src/lxc/tools/tool_utils.c

index 594e9ae22be7668086b0961a87a2d996bf8e16c4..89382f67c9db25762160f2911ff61321753bd73e 100644 (file)
 #include "include/strlcpy.h"
 #endif
 
+#ifndef HAVE_STRLCAT
+#include "include/strlcat.h"
+#endif
+
 int lxc_fill_elevated_privileges(char *flaglist, int *flags)
 {
        char *token, *saveptr = NULL;
@@ -503,22 +507,24 @@ char *lxc_string_join(const char *sep, const char **parts, bool use_as_prefix)
        char **p;
        size_t sep_len = strlen(sep);
        size_t result_len = use_as_prefix * sep_len;
+       size_t buf_len;
 
        /* calculate new string length */
        for (p = (char **)parts; *p; p++)
                result_len += (p > (char **)parts) * sep_len + strlen(*p);
 
-       result = calloc(result_len + 1, 1);
+       buf_len = result_len + 1;
+       result = calloc(buf_len, 1);
        if (!result)
                return NULL;
 
        if (use_as_prefix)
-               (void)strlcpy(result, sep, result_len + 1);
+               (void)strlcpy(result, sep, buf_len);
 
        for (p = (char **)parts; *p; p++) {
                if (p > (char **)parts)
-                       strncat(result, sep, sep_len);
-               strncat(result, *p, strlen(*p));
+                       (void)strlcat(result, sep, buf_len);
+               (void)strlcat(result, *p, buf_len);
        }
 
        return result;
@@ -1071,6 +1077,7 @@ char *must_make_path(const char *first, ...)
        va_list args;
        char *cur, *dest;
        size_t full_len = strlen(first);
+       size_t buf_len;
 
        dest = must_copy_string(first);
 
@@ -1080,11 +1087,12 @@ char *must_make_path(const char *first, ...)
                if (cur[0] != '/')
                        full_len++;
 
-               dest = must_realloc(dest, full_len + 1);
+               buf_len = full_len + 1;
+               dest = must_realloc(dest, buf_len);
 
                if (cur[0] != '/')
-                       strncat(dest, "/", 1);
-               strncat(dest, cur, strlen(cur));
+                       (void)strlcat(dest, "/", buf_len);
+               (void)strlcat(dest, cur, buf_len);
        }
        va_end(args);