conf: strncat => strlcat

parent 3ebe2fbd
...@@ -76,6 +76,10 @@ ...@@ -76,6 +76,10 @@
#include <sys/personality.h> #include <sys/personality.h>
#endif #endif
#ifndef HAVE_STRLCAT
#include "include/strlcat.h"
#endif
#if IS_BIONIC #if IS_BIONIC
#include <../include/lxcmntent.h> #include <../include/lxcmntent.h>
#else #else
...@@ -841,6 +845,7 @@ static int lxc_setup_dev_symlinks(const struct lxc_rootfs *rootfs) ...@@ -841,6 +845,7 @@ static int lxc_setup_dev_symlinks(const struct lxc_rootfs *rootfs)
static bool append_ttyname(char **pp, char *name) static bool append_ttyname(char **pp, char *name)
{ {
char *p; char *p;
size_t size;
if (!*pp) { if (!*pp) {
*pp = malloc(strlen(name) + strlen("container_ttys=") + 1); *pp = malloc(strlen(name) + strlen("container_ttys=") + 1);
...@@ -851,13 +856,14 @@ static bool append_ttyname(char **pp, char *name) ...@@ -851,13 +856,14 @@ static bool append_ttyname(char **pp, char *name)
return true; return true;
} }
p = realloc(*pp, strlen(*pp) + strlen(name) + 2); size = strlen(*pp) + strlen(name) + 2;
p = realloc(*pp, size);
if (!p) if (!p)
return false; return false;
*pp = p; *pp = p;
strncat(p, " ", 1); (void)strlcat(p, " ", size);
strncat(p, name, strlen(name)); (void)strlcat(p, name, size);
return true; return true;
} }
...@@ -1791,7 +1797,6 @@ static int lxc_setup_console(const struct lxc_rootfs *rootfs, ...@@ -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) static void parse_mntopt(char *opt, unsigned long *flags, char **data, size_t size)
{ {
struct mount_opt *mo; struct mount_opt *mo;
size_t cursize;
/* If opt is found in mount_opt, set or clear flags. /* If opt is found in mount_opt, set or clear flags.
* Otherwise append it to data. */ * Otherwise append it to data. */
...@@ -1806,16 +1811,10 @@ static void parse_mntopt(char *opt, unsigned long *flags, char **data, size_t si ...@@ -1806,16 +1811,10 @@ static void parse_mntopt(char *opt, unsigned long *flags, char **data, size_t si
} }
} }
cursize = strlen(*data); if (strlen(*data))
if (cursize) (void)strlcat(*data, ",", size);
cursize += 1;
if (size - cursize > 1) { (void)strlcat(*data, opt, size);
if (cursize)
strncat(*data, ",", 1);
strncat(*data, opt, size - cursize - 1);
}
} }
int parse_mntopts(const char *mntopts, unsigned long *mntflags, char **mntdata) int parse_mntopts(const char *mntopts, unsigned long *mntflags, char **mntdata)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment