Skip to content

Commit

Permalink
Merge pull request #2675 from brauner/2018-10-07/path_max
Browse files Browse the repository at this point in the history
tree-wide: s/MAXPATHLEN/PATH_MAX/g
  • Loading branch information
Blub committed Oct 7, 2018
2 parents 8b01363 + 3a5996f commit 969e23f
Show file tree
Hide file tree
Showing 25 changed files with 216 additions and 209 deletions.
7 changes: 4 additions & 3 deletions src/lxc/cmd/lxc_init.c
Expand Up @@ -28,6 +28,7 @@
#include <errno.h>
#include <getopt.h>
#include <libgen.h>
#include <limits.h>
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
Expand Down Expand Up @@ -108,7 +109,7 @@ static void prevent_forking(void)
FILE *f;
size_t len = 0;
char *line = NULL;
char path[MAXPATHLEN];
char path[PATH_MAX];

f = fopen("/proc/self/cgroup", "r");
if (!f)
Expand Down Expand Up @@ -202,10 +203,10 @@ static void remove_self(void)
{
int ret;
ssize_t n;
char path[MAXPATHLEN] = {0};
char path[PATH_MAX] = {0};

n = readlink("/proc/self/exe", path, sizeof(path));
if (n < 0 || n >= MAXPATHLEN) {
if (n < 0 || n >= PATH_MAX) {
SYSDEBUG("Failed to readlink \"/proc/self/exe\"");
return;
}
Expand Down
78 changes: 39 additions & 39 deletions src/lxc/conf.c
Expand Up @@ -542,7 +542,7 @@ int run_script(const char *name, const char *section, const char *script, ...)
int pin_rootfs(const char *rootfs)
{
int fd, ret;
char absrootfspin[MAXPATHLEN];
char absrootfspin[PATH_MAX];
char *absrootfs;
struct stat s;
struct statfs sfs;
Expand All @@ -565,9 +565,9 @@ int pin_rootfs(const char *rootfs)
return -2;
}

ret = snprintf(absrootfspin, MAXPATHLEN, "%s/.lxc-keep", absrootfs);
ret = snprintf(absrootfspin, PATH_MAX, "%s/.lxc-keep", absrootfs);
free(absrootfs);
if (ret >= MAXPATHLEN)
if (ret < 0 || ret >= PATH_MAX)
return -1;

fd = open(absrootfspin, O_CREAT | O_RDWR, S_IWUSR | S_IRUSR);
Expand Down Expand Up @@ -639,7 +639,7 @@ unsigned long add_required_remount_flags(const char *s, const char *d,

static int add_shmount_to_list(struct lxc_conf *conf)
{
char new_mount[MAXPATHLEN];
char new_mount[PATH_MAX];
/* Offset for the leading '/' since the path_cont
* is absolute inside the container.
*/
Expand Down Expand Up @@ -833,15 +833,15 @@ static const struct dev_symlinks dev_symlinks[] = {
static int lxc_setup_dev_symlinks(const struct lxc_rootfs *rootfs)
{
int i, ret;
char path[MAXPATHLEN];
char path[PATH_MAX];
struct stat s;

for (i = 0; i < sizeof(dev_symlinks) / sizeof(dev_symlinks[0]); i++) {
const struct dev_symlinks *d = &dev_symlinks[i];

ret = snprintf(path, sizeof(path), "%s/dev/%s",
rootfs->path ? rootfs->mount : "", d->name);
if (ret < 0 || ret >= MAXPATHLEN)
if (ret < 0 || ret >= PATH_MAX)
return -1;

/* Stat the path first. If we don't get an error accept it as
Expand Down Expand Up @@ -897,7 +897,7 @@ static int lxc_setup_ttys(struct lxc_conf *conf)
int i, ret;
const struct lxc_tty_info *ttys = &conf->ttys;
char *ttydir = ttys->dir;
char path[MAXPATHLEN], lxcpath[MAXPATHLEN];
char path[PATH_MAX], lxcpath[PATH_MAX];

if (!conf->rootfs.path)
return 0;
Expand Down Expand Up @@ -1218,13 +1218,13 @@ enum {
static int lxc_fill_autodev(const struct lxc_rootfs *rootfs)
{
int i, ret;
char path[MAXPATHLEN];
char path[PATH_MAX];
mode_t cmask;
int use_mknod = LXC_DEVNODE_MKNOD;

ret = snprintf(path, MAXPATHLEN, "%s/dev",
ret = snprintf(path, PATH_MAX, "%s/dev",
rootfs->path ? rootfs->mount : "");
if (ret < 0 || ret >= MAXPATHLEN)
if (ret < 0 || ret >= PATH_MAX)
return -1;

/* ignore, just don't try to fill in */
Expand All @@ -1235,12 +1235,12 @@ static int lxc_fill_autodev(const struct lxc_rootfs *rootfs)

cmask = umask(S_IXUSR | S_IXGRP | S_IXOTH);
for (i = 0; i < sizeof(lxc_devices) / sizeof(lxc_devices[0]); i++) {
char hostpath[MAXPATHLEN];
char hostpath[PATH_MAX];
const struct lxc_device_node *device = &lxc_devices[i];

ret = snprintf(path, MAXPATHLEN, "%s/dev/%s",
ret = snprintf(path, PATH_MAX, "%s/dev/%s",
rootfs->path ? rootfs->mount : "", device->name);
if (ret < 0 || ret >= MAXPATHLEN)
if (ret < 0 || ret >= PATH_MAX)
return -1;

if (use_mknod >= LXC_DEVNODE_MKNOD) {
Expand Down Expand Up @@ -1292,8 +1292,8 @@ static int lxc_fill_autodev(const struct lxc_rootfs *rootfs)
}

/* Fallback to bind-mounting the device from the host. */
ret = snprintf(hostpath, MAXPATHLEN, "/dev/%s", device->name);
if (ret < 0 || ret >= MAXPATHLEN)
ret = snprintf(hostpath, PATH_MAX, "/dev/%s", device->name);
if (ret < 0 || ret >= PATH_MAX)
return -1;

ret = safe_mount(hostpath, path, 0, MS_BIND, NULL,
Expand Down Expand Up @@ -1747,7 +1747,7 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs,
const struct lxc_terminal *console)
{
int ret;
char path[MAXPATHLEN];
char path[PATH_MAX];
char *rootfs_path = rootfs->path ? rootfs->mount : "";

if (console->path && !strcmp(console->path, "none"))
Expand Down Expand Up @@ -1801,7 +1801,7 @@ static int lxc_setup_ttydir_console(const struct lxc_rootfs *rootfs,
char *ttydir)
{
int ret;
char path[MAXPATHLEN], lxcpath[MAXPATHLEN];
char path[PATH_MAX], lxcpath[PATH_MAX];
char *rootfs_path = rootfs->path ? rootfs->mount : "";

if (console->path && !strcmp(console->path, "none"))
Expand Down Expand Up @@ -2015,15 +2015,15 @@ static int mount_entry(const char *fsname, const char *target,
bool dev, bool relative, const char *rootfs)
{
int ret;
char srcbuf[MAXPATHLEN];
char srcbuf[PATH_MAX];
const char *srcpath = fsname;
#ifdef HAVE_STATVFS
struct statvfs sb;
#endif

if (relative) {
ret = snprintf(srcbuf, MAXPATHLEN, "%s/%s", rootfs ? rootfs : "/", fsname ? fsname : "");
if (ret < 0 || ret >= MAXPATHLEN) {
ret = snprintf(srcbuf, PATH_MAX, "%s/%s", rootfs ? rootfs : "/", fsname ? fsname : "");
if (ret < 0 || ret >= PATH_MAX) {
ERROR("source path is too long");
return -1;
}
Expand Down Expand Up @@ -2257,7 +2257,7 @@ static inline int mount_entry_on_generic(struct mntent *mntent,
static inline int mount_entry_on_systemfs(struct mntent *mntent)
{
int ret;
char path[MAXPATHLEN];
char path[PATH_MAX];

/* For containers created without a rootfs all mounts are treated as
* absolute paths starting at / on the host.
Expand All @@ -2280,7 +2280,7 @@ static int mount_entry_on_absolute_rootfs(struct mntent *mntent,
int offset;
char *aux;
const char *lxcpath;
char path[MAXPATHLEN];
char path[PATH_MAX];
int ret = 0;

lxcpath = lxc_global_config_value("lxc.lxcpath");
Expand All @@ -2290,8 +2290,8 @@ static int mount_entry_on_absolute_rootfs(struct mntent *mntent,
/* If rootfs->path is a blockdev path, allow container fstab to use
* <lxcpath>/<name>/rootfs" as the target prefix.
*/
ret = snprintf(path, MAXPATHLEN, "%s/%s/rootfs", lxcpath, lxc_name);
if (ret < 0 || ret >= MAXPATHLEN)
ret = snprintf(path, PATH_MAX, "%s/%s/rootfs", lxcpath, lxc_name);
if (ret < 0 || ret >= PATH_MAX)
goto skipvarlib;

aux = strstr(mntent->mnt_dir, path);
Expand All @@ -2309,8 +2309,8 @@ static int mount_entry_on_absolute_rootfs(struct mntent *mntent,
offset = strlen(rootfs->path);

skipabs:
ret = snprintf(path, MAXPATHLEN, "%s/%s", rootfs->mount, aux + offset);
if (ret < 0 || ret >= MAXPATHLEN)
ret = snprintf(path, PATH_MAX, "%s/%s", rootfs->mount, aux + offset);
if (ret < 0 || ret >= PATH_MAX)
return -1;

return mount_entry_on_generic(mntent, path, rootfs, lxc_name, lxc_path);
Expand All @@ -2322,7 +2322,7 @@ static int mount_entry_on_relative_rootfs(struct mntent *mntent,
const char *lxc_path)
{
int ret;
char path[MAXPATHLEN];
char path[PATH_MAX];

/* relative to root mount point */
ret = snprintf(path, sizeof(path), "%s/%s", rootfs->mount, mntent->mnt_dir);
Expand Down Expand Up @@ -2662,7 +2662,7 @@ int setup_sysctl_parameters(struct lxc_list *sysctls)
struct lxc_sysctl *elem;
int ret = 0;
char *tmp = NULL;
char filename[MAXPATHLEN] = {0};
char filename[PATH_MAX] = {0};

lxc_list_for_each (it, sysctls) {
elem = it->elem;
Expand Down Expand Up @@ -2697,7 +2697,7 @@ int setup_proc_filesystem(struct lxc_list *procs, pid_t pid)
struct lxc_proc *elem;
int ret = 0;
char *tmp = NULL;
char filename[MAXPATHLEN] = {0};
char filename[PATH_MAX] = {0};

lxc_list_for_each (it, procs) {
elem = it->elem;
Expand Down Expand Up @@ -2806,13 +2806,13 @@ int write_id_mapping(enum idtype idtype, pid_t pid, const char *buf,
size_t buf_size)
{
int fd, ret;
char path[MAXPATHLEN];
char path[PATH_MAX];

if (geteuid() != 0 && idtype == ID_TYPE_GID) {
size_t buflen;

ret = snprintf(path, MAXPATHLEN, "/proc/%d/setgroups", pid);
if (ret < 0 || ret >= MAXPATHLEN)
ret = snprintf(path, PATH_MAX, "/proc/%d/setgroups", pid);
if (ret < 0 || ret >= PATH_MAX)
return -E2BIG;

fd = open(path, O_WRONLY);
Expand All @@ -2835,9 +2835,9 @@ int write_id_mapping(enum idtype idtype, pid_t pid, const char *buf,
}
}

ret = snprintf(path, MAXPATHLEN, "/proc/%d/%cid_map", pid,
ret = snprintf(path, PATH_MAX, "/proc/%d/%cid_map", pid,
idtype == ID_TYPE_UID ? 'u' : 'g');
if (ret < 0 || ret >= MAXPATHLEN)
if (ret < 0 || ret >= PATH_MAX)
return -E2BIG;

fd = open(path, O_WRONLY);
Expand Down Expand Up @@ -2938,7 +2938,7 @@ int lxc_map_ids(struct lxc_list *idmap, pid_t pid)
int fill, left;
char u_or_g;
char *pos;
char cmd_output[MAXPATHLEN];
char cmd_output[PATH_MAX];
struct id_map *map;
struct lxc_list *iterator;
enum idtype type;
Expand Down Expand Up @@ -3171,7 +3171,7 @@ int chown_mapped_root(const char *path, struct lxc_conf *conf)
"-m", map5,
"--", "chown", ugid, path,
NULL};
char cmd_output[MAXPATHLEN];
char cmd_output[PATH_MAX];

hostuid = geteuid();
hostgid = getegid();
Expand Down Expand Up @@ -3507,18 +3507,18 @@ int lxc_setup_rootfs_prepare_root(struct lxc_conf *conf, const char *name,

static bool verify_start_hooks(struct lxc_conf *conf)
{
char path[MAXPATHLEN];
char path[PATH_MAX];
struct lxc_list *it;

lxc_list_for_each (it, &conf->hooks[LXCHOOK_START]) {
int ret;
struct stat st;
char *hookname = it->elem;

ret = snprintf(path, MAXPATHLEN, "%s%s",
ret = snprintf(path, PATH_MAX, "%s%s",
conf->rootfs.path ? conf->rootfs.mount : "",
hookname);
if (ret < 0 || ret >= MAXPATHLEN)
if (ret < 0 || ret >= PATH_MAX)
return false;

ret = stat(path, &st);
Expand Down
6 changes: 3 additions & 3 deletions src/lxc/confile.c
Expand Up @@ -2068,7 +2068,7 @@ static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf)
{
struct dirent *direntp;
DIR *dir;
char path[MAXPATHLEN];
char path[PATH_MAX];
int len;
int ret = -1;

Expand All @@ -2090,8 +2090,8 @@ static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf)
if (len < 6 || strncmp(fnam + len - 5, ".conf", 5) != 0)
continue;

len = snprintf(path, MAXPATHLEN, "%s/%s", dirp, fnam);
if (len < 0 || len >= MAXPATHLEN) {
len = snprintf(path, PATH_MAX, "%s/%s", dirp, fnam);
if (len < 0 || len >= PATH_MAX) {
ret = -1;
goto out;
}
Expand Down
12 changes: 6 additions & 6 deletions src/lxc/log.h
Expand Up @@ -339,7 +339,7 @@ ATTR_UNUSED static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \

#ifdef STRERROR_R_CHAR_P
#define lxc_log_strerror_r \
char errno_buf[MAXPATHLEN / 2] = {"Failed to get errno string"}; \
char errno_buf[PATH_MAX / 2] = {"Failed to get errno string"}; \
char *ptr = NULL; \
{ \
int saved_errno = errno; \
Expand All @@ -350,7 +350,7 @@ ATTR_UNUSED static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
}
#else
#define lxc_log_strerror_r \
char errno_buf[MAXPATHLEN / 2] = {"Failed to get errno string"}; \
char errno_buf[PATH_MAX / 2] = {"Failed to get errno string"}; \
char *ptr = errno_buf; \
{ \
int saved_errno = errno; \
Expand All @@ -361,10 +361,10 @@ ATTR_UNUSED static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
#elif ENFORCE_THREAD_SAFETY
#error ENFORCE_THREAD_SAFETY was set but cannot be guaranteed
#else
#define lxc_log_strerror_r \
char *ptr = NULL; \
{ \
ptr = strerror(errno); \
#define lxc_log_strerror_r \
char *ptr = NULL; \
{ \
ptr = strerror(errno); \
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/lxc/lsm/apparmor.c
Expand Up @@ -809,7 +809,7 @@ static int run_apparmor_parser(char command,
struct lxc_conf *conf,
const char *lxcpath)
{
char output[MAXPATHLEN];
char output[PATH_MAX];
int ret;
struct apparmor_parser_args args = {
.cmd = command,
Expand Down

0 comments on commit 969e23f

Please sign in to comment.