From f1b02bed97401a1573efc2b7c894a6e5c64f5e7a Mon Sep 17 00:00:00 2001 From: wbaumann Date: Sat, 28 Jan 2012 22:38:15 +0000 Subject: [PATCH] Add Gnulib modules xstrndup and xvasprintf --- ChangeLog | 1 + config/gnulib-cache.m4 | 4 +- src/cache.c | 42 ++++++++------- src/kernel_interface.c | 29 ++++------ src/mount_davfs.c | 118 ++++++++++++++++++----------------------- src/umount_davfs.c | 11 ++-- src/webdav.c | 16 +++--- 7 files changed, 105 insertions(+), 116 deletions(-) diff --git a/ChangeLog b/ChangeLog index fcf16be..f2ad0a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,7 @@ ChangeLog for davfs2 Check secrets file in check_dirs. * all: Add Gnulib module xalloc. + Add Gnulib modules xstrndup and xvasprintf. 2012-01-25 Werner Baumann (werner.baumann@onlinehome.de) * mount_davfs.c, mount_davfs.h: diff --git a/config/gnulib-cache.m4 b/config/gnulib-cache.m4 index 4253caf..94fbecf 100644 --- a/config/gnulib-cache.m4 +++ b/config/gnulib-cache.m4 @@ -15,7 +15,7 @@ # Specification in the form of a command-line invocation: -# gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=config --po-base=glpo --doc-base=doc --tests-base=tests --aux-dir=config --no-libtool --macro-prefix=gl --po-domain=davfs2 canonicalize iconv_open rpmatch xalloc +# gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=config --po-base=glpo --doc-base=doc --tests-base=tests --aux-dir=config --no-libtool --macro-prefix=gl --po-domain=davfs2 canonicalize iconv_open rpmatch xalloc xstrndup xvasprintf # Specification in the form of a few gnulib-tool.m4 macro invocations: gl_LOCAL_DIR([]) @@ -24,6 +24,8 @@ gl_MODULES([ iconv_open rpmatch xalloc + xstrndup + xvasprintf ]) gl_AVOID([]) gl_SOURCE_BASE([gl]) diff --git a/src/cache.c b/src/cache.c index 2c1ff98..6b1d011 100644 --- a/src/cache.c +++ b/src/cache.c @@ -60,6 +60,8 @@ #include #include "xalloc.h" +#include "xstrndup.h" +#include "xvasprintf.h" #include #include @@ -688,7 +690,7 @@ dav_close_cache(int got_sigterm) clean_tree(root, !got_sigterm); - char *new_index = ne_concat(cache_dir, "/", DAV_INDEX, ".new", NULL); + char *new_index = xasprintf("%s/%s.new",cache_dir, DAV_INDEX); if (debug) syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG), "Creating index %s.", new_index); @@ -706,7 +708,7 @@ dav_close_cache(int got_sigterm) if (debug) syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG), "Replacing old index"); - char *old_index = ne_concat(cache_dir, "/", DAV_INDEX, NULL); + char *old_index = xasprintf("%s/%s", cache_dir, DAV_INDEX); if (rename(new_index, old_index) != 0) syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_ERR), _("can't replace %s with %s"), old_index, new_index); @@ -925,7 +927,7 @@ dav_create(dav_node **nodep, dav_node *parent, const char *name, uid_t uid, return EINVAL; char *name_conv = dav_conv_to_server_enc(name); - char *path = ne_concat(parent->path, name_conv, NULL); + char *path = xasprintf("%s%s", parent->path, name_conv); free(name_conv); *nodep = new_node(parent, mode | S_IFREG); @@ -1102,7 +1104,7 @@ dav_mkdir(dav_node **nodep, dav_node *parent, const char *name, uid_t uid, return EINVAL; char *name_conv = dav_conv_to_server_enc(name); - char *path = ne_concat(parent->path, name_conv, "/", NULL); + char *path = xasprintf("%s%s/", parent->path, name_conv); free(name_conv); int ret = dav_make_collection(path); @@ -1859,7 +1861,7 @@ move_dir(dav_node *src, dav_node *dst, dav_node *dst_parent, char *dst_path; if (!dst) { char *dst_conv = dav_conv_to_server_enc(dst_name); - dst_path = ne_concat(dst_parent->path, dst_conv, "/", NULL); + dst_path = xasprintf("%s%s/", dst_parent->path, dst_conv); free(dst_conv); } else { dst_path = xstrdup(dst->path); @@ -1898,7 +1900,7 @@ move_no_remote(dav_node *src, dav_node *dst, dav_node *dst_parent, char *dst_path; if (!dst) { char *dst_conv = dav_conv_to_server_enc(dst_name); - dst_path = ne_concat(dst_parent->path, dst_conv, NULL); + dst_path = xasprintf("%s%s", dst_parent->path, dst_conv); free(dst_conv); } else { dst_path = xstrdup(dst->path); @@ -1968,7 +1970,7 @@ move_reg(dav_node *src, dav_node *dst, dav_node *dst_parent, char *dst_path; if (!dst) { char *dst_conv = dav_conv_to_server_enc(dst_name); - dst_path = ne_concat(dst_parent->path, dst_conv, NULL); + dst_path = xasprintf("%s%s", dst_parent->path, dst_conv); free(dst_conv); } else { dst_path = xstrdup(dst->path); @@ -2399,7 +2401,7 @@ update_path(dav_node *node, const char *src_path, const char *dst_path) return; } - char *path = ne_concat(dst_path, node->path + strlen(src_path), NULL); + char *path = xasprintf("%s%s", dst_path, node->path + strlen(src_path)); free(node->path); node->path = path; } @@ -2556,7 +2558,7 @@ create_cache_file(dav_node *node) } } - node->cache_path = ne_concat(cache_dir, "/", node->name, "-XXXXXX", NULL); + node->cache_path = xasprintf("%s/%s-XXXXXX", cache_dir, node->name); int fd = mkstemp(node->cache_path); if (fd <= 0) { @@ -2590,8 +2592,7 @@ create_dir_cache_file(dav_node *dir) } } - dir->cache_path = ne_concat(cache_dir, "/dir-", dir->name, "-XXXXXX", - NULL); + dir->cache_path = xasprintf("%s/dir-%s-XXXXXX", cache_dir, dir->name); int fd = mkstemp(dir->cache_path); if (fd <= 0) { syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_ERR), @@ -2779,7 +2780,8 @@ check_cache_dir(const char *dir, const char *host, const char *path, struct passwd *pw = getpwuid(default_uid); if (!pw || !pw->pw_name) error(EXIT_FAILURE, 0, _("can't read user data base")); - char *dir_name = ne_concat(host, path, mpoint + 1, "+", pw->pw_name, NULL); + char *dir_name = xasprintf("%s%s%s+%s", host, path, mpoint + 1, + pw->pw_name); *(dir_name + strlen(host) + strlen(path) - 1) = '+'; char *pos = strchr(dir_name, '/'); while (pos) { @@ -2794,7 +2796,7 @@ check_cache_dir(const char *dir, const char *host, const char *path, struct dirent *de = readdir(tl_dir); while (de && !cache_dir) { if (strcmp(de->d_name, dir_name) == 0) { - cache_dir = ne_concat(dir, "/", de->d_name, NULL); + cache_dir = xasprintf("%s/%s", dir, de->d_name); } de = readdir(tl_dir); } @@ -2802,7 +2804,7 @@ check_cache_dir(const char *dir, const char *host, const char *path, closedir(tl_dir); if (!cache_dir) { - cache_dir = ne_concat(dir, "/", dir_name, NULL); + cache_dir = xasprintf("%s/%s", dir, dir_name); if (mkdir(cache_dir, S_IRWXU) != 0) error(EXIT_FAILURE, 0, _("can't create cache directory %s"), cache_dir); @@ -2835,7 +2837,7 @@ clean_cache(void) if (strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0 && strcmp(de->d_name, DAV_INDEX) != 0) { - char *path = ne_concat(cache_dir, "/", de->d_name, NULL); + char *path = xasprintf("%s/%s", cache_dir, de->d_name); int i = 0; dav_node *node = NULL; while (!node && i < table_size) { @@ -2876,7 +2878,7 @@ clean_cache(void) static void parse_index(void) { - char *index = ne_concat(cache_dir, "/", DAV_INDEX, NULL); + char *index = xasprintf("%s/%s", cache_dir, DAV_INDEX); FILE *idx = fopen(index, "r"); if (!idx) { free(index); @@ -3019,7 +3021,7 @@ write_node(dav_node *node, FILE *file, const char *indent) return -1; } - char *ind = ne_concat(indent, " ", NULL); + char *ind = xasprintf("%s ", indent); if (node != root && !is_backup(node)) { if (fprintf(file, "%s\n", ind, type[PATH], node->path, @@ -3156,10 +3158,10 @@ static int xml_cdata(void *userdata, int state, const char *cdata, size_t len) { if (!xml_data) { - xml_data = ne_strndup(cdata, len); + xml_data = xstrndup(cdata, len); } else { - char *add = ne_strndup(cdata, len); - char *new = ne_concat(xml_data, add, NULL); + char *add = xstrndup(cdata, len); + char *new = xasprintf("%s%s", xml_data, add); free(add); free(xml_data); xml_data = new; diff --git a/src/kernel_interface.c b/src/kernel_interface.c index 192614c..6700acc 100644 --- a/src/kernel_interface.c +++ b/src/kernel_interface.c @@ -55,6 +55,7 @@ #endif #include "xalloc.h" +#include "xvasprintf.h" #include "defaults.h" #include "mount_davfs.h" @@ -155,9 +156,7 @@ init_coda(int *dev, dav_run_msgloop_fn *msg_loop, void **mdata) *dev = 0; int minor = 0; while (*dev <= 0 && minor < MAX_CODADEVS) { - char *path; - if (asprintf(&path, "%s/%s%i", DAV_DEV_DIR, CODA_DEV_NAME, minor) < 0) - abort(); + char *path = xasprintf("%s/%s%i", DAV_DEV_DIR, CODA_DEV_NAME, minor); *dev = open(path, O_RDWR | O_NONBLOCK); free(path); ++minor; @@ -166,10 +165,8 @@ init_coda(int *dev, dav_run_msgloop_fn *msg_loop, void **mdata) if (*dev <= 0 && system("/sbin/modprobe coda &>/dev/null") == 0) { minor = 0; while (*dev <= 0 && minor < MAX_CODADEVS) { - char *path; - if (asprintf(&path, "%s/%s%i", - DAV_DEV_DIR, CODA_DEV_NAME, minor) < 0) - abort(); + char *path = xasprintf("%s/%s%i", DAV_DEV_DIR, CODA_DEV_NAME, + minor); *dev = open(path, O_RDWR | O_NONBLOCK); if (*dev <= 0) { if (mknod(path, S_IFCHR, makedev(CODA_MAJOR, minor)) == 0) { @@ -215,9 +212,7 @@ init_fuse(int *dev, dav_run_msgloop_fn *msg_loop, void **mdata, size_t *buf_size, const char *url, const char *mpoint, unsigned long int mopts, uid_t owner, gid_t group, mode_t mode) { - char *path; - if (asprintf(&path, "%s/%s", DAV_DEV_DIR, FUSE_DEV_NAME) < 0) - abort(); + char *path = xasprintf("%s/%s", DAV_DEV_DIR, FUSE_DEV_NAME); *dev = open(path, O_RDWR | O_NONBLOCK); if (*dev <= 0 && system("/sbin/modprobe fuse &>/dev/null") == 0) { @@ -244,15 +239,13 @@ init_fuse(int *dev, dav_run_msgloop_fn *msg_loop, void **mdata, } #if SIZEOF_VOID_P == 8 - if (asprintf((char **) mdata, "fd=%i,rootmode=%o,user_id=%i,group_id=%i," - "allow_other,max_read=%lu", *dev, mode, owner, group, - *buf_size - 4096) < 0) - abort(); + *mdata = xasprintf("fd=%i,rootmode=%o,user_id=%i,group_id=%i," + "allow_other,max_read=%lu", *dev, mode, owner, group, + *buf_size - 4096); #else - if (asprintf((char **) mdata, "fd=%i,rootmode=%o,user_id=%i,group_id=%i," - "allow_other,max_read=%u", *dev, mode, owner, group, - *buf_size - 4096) < 0) - abort(); + *mdata = xasprintf("fd=%i,rootmode=%o,user_id=%i,group_id=%i," + "allow_other,max_read=%u", *dev, mode, owner, group, + *buf_size - 4096); #endif if (mount(url, mpoint, "fuse", mopts, *mdata) == 0) { *msg_loop = dav_fuse_loop; diff --git a/src/mount_davfs.c b/src/mount_davfs.c index 851c675..a558462 100644 --- a/src/mount_davfs.c +++ b/src/mount_davfs.c @@ -71,6 +71,8 @@ #include "canonicalize.h" #include "xalloc.h" +#include "xvasprintf.h" +#include "xstrndup.h" #include #include @@ -382,7 +384,7 @@ main(int argc, char *argv[]) dav_close_cache(got_sigterm); dav_close_webdav(); if (is_mounted()) { - char *prog = ne_concat("/bin/umount -il ", mpoint, NULL); + char *prog = xasprintf("/bin/umount -il %s", mpoint); syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_ERR), _("unmounting %s"), mpoint); if (system(prog) != 0) syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_ERR), _("unmounting failed")); @@ -497,7 +499,7 @@ check_dirs(dav_args *args) } release_privileges(args); - fname = ne_concat(DAV_SYS_CONF_DIR "/" DAV_SECRETS, NULL); + fname = xasprintf("%s/%s", DAV_SYS_CONF_DIR, DAV_SECRETS); if (stat(fname, &st) == 0) { if (st.st_uid != 0) error(EXIT_FAILURE, 0, _("file %s has wrong owner"), fname); @@ -510,46 +512,41 @@ check_dirs(dav_args *args) if (!args->privileged) { - char *path = ne_concat(args->home, "/.", PACKAGE, NULL); + char *path = xasprintf("%s/.%s", args->home, PACKAGE); if (stat(path, &st) != 0) mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); if (stat(path, &st) == 0) { - fname = ne_concat(args->home, "/.", PACKAGE, "/", DAV_CACHE, NULL); + fname = xasprintf("%s/.%s/%s", args->home, PACKAGE, DAV_CACHE); if (stat(fname, &st) != 0) mkdir(fname, S_IRWXU); free(fname); - fname = ne_concat(args->home, "/.", PACKAGE, "/", DAV_CERTS_DIR, - NULL); + fname = xasprintf("%s/.%s/%s", args->home, PACKAGE, DAV_CERTS_DIR); if (stat(fname, &st) != 0) mkdir(fname, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); free(fname); - fname = ne_concat(args->home, "/.", PACKAGE, "/", DAV_CERTS_DIR, - "/", DAV_CLICERTS_DIR, NULL); + fname = xasprintf("%s/.%s/%s/%s", args->home, PACKAGE, + DAV_CERTS_DIR, DAV_CLICERTS_DIR); if (stat(fname, &st) != 0) mkdir(fname, S_IRWXU); free(fname); - fname = ne_concat(args->home, "/.", PACKAGE, "/", DAV_CONFIG, NULL); + fname = xasprintf("%s/.%s/%s", args->home, PACKAGE, DAV_CONFIG); if (stat(fname, &st) != 0) { - char *template = ne_concat(DAV_DATA_DIR, "/", DAV_CONFIG, NULL); - char *command = ne_concat("cp ", template, " ", fname, - NULL); + char *template = xasprintf("%s/%s", DAV_DATA_DIR, DAV_CONFIG); + char *command = xasprintf("cp %s %s", template, fname); if (system(command) != 0); free(command); free(template); } free(fname); - fname = ne_concat(args->home, "/.", PACKAGE, "/", DAV_SECRETS, - NULL); + fname = xasprintf("%s/.%s/%s", args->home, PACKAGE, DAV_SECRETS); if (stat(fname, &st) != 0) { - char *template = ne_concat(DAV_DATA_DIR, "/", DAV_SECRETS, - NULL); - char *command = ne_concat("cp ", template, " ", fname, - NULL); + char *template = xasprintf("%s/%s", DAV_DATA_DIR, DAV_SECRETS); + char *command = xasprintf("cp %s %s", template, fname); if (system(command) == 0) chmod(fname, S_IRUSR | S_IWUSR); free(command); @@ -658,8 +655,7 @@ check_double_mounts(dav_args *args) *m = '-'; m = strchr(mp, '/'); } - char *pidf = NULL; - if (asprintf(&pidf, "%s/%s.pid", DAV_SYS_RUN, mp) < 0) abort(); + char *pidf = xasprintf("%s/%s.pid", DAV_SYS_RUN, mp); free(mp); if (args->debug & DAV_DBG_CONFIG) syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG), "PID file: %s", pidf); @@ -938,7 +934,7 @@ parse_commandline(dav_args *args, int argc, char *argv[]) exit(EXIT_FAILURE); case 2: if (*argv[i] == '\"' || *argv[i] == '\'') { - url = ne_strndup(argv[i] + 1, strlen(argv[i]) -2); + url = xstrndup(argv[i] + 1, strlen(argv[i]) - 2); } else { url = xstrdup(argv[i]); } @@ -971,8 +967,7 @@ parse_commandline(dav_args *args, int argc, char *argv[]) if (args->conf) { expand_home(&args->conf, args); } else if (!args->privileged) { - if (asprintf(&args->conf, "%s/.%s/%s", args->home, PACKAGE, - DAV_CONFIG) < 0) abort(); + args->conf = xasprintf("%s/.%s/%s", args->home, PACKAGE, DAV_CONFIG); } return args; @@ -1023,8 +1018,8 @@ parse_config(dav_args *args) if (args->servercert) expand_home(&args->servercert, args); if (args->servercert && *args->servercert != '/' && !args->privileged) { - char *f = ne_concat(args->home, "/.", PACKAGE, "/", DAV_CERTS_DIR, - "/", args->servercert, NULL); + char *f = xasprintf("%s/.%s/%s/%s", args->home, PACKAGE, DAV_CERTS_DIR, + args->servercert); if (access(f, F_OK) == 0) { free(args->servercert); args->servercert = f; @@ -1033,8 +1028,8 @@ parse_config(dav_args *args) } } if (args->servercert && *args->servercert != '/') { - char *f = ne_concat(DAV_SYS_CONF_DIR, "/", DAV_CERTS_DIR, "/", - args->servercert, NULL); + char *f = xasprintf("%s/%s/%s", DAV_SYS_CONF_DIR, DAV_CERTS_DIR, + args->servercert); free(args->servercert); args->servercert = f; } @@ -1042,23 +1037,22 @@ parse_config(dav_args *args) if (args->secrets) expand_home(&args->secrets, args); if (!args->privileged && !args->secrets) - args->secrets = ne_concat(args->home, "/.", PACKAGE, "/", DAV_SECRETS, - NULL); - + args->secrets = xasprintf("%s/.%s/%s", args->home, PACKAGE, + DAV_SECRETS); if (args->clicert) expand_home(&args->clicert, args); if (args->clicert && *args->clicert != '/' && !args->privileged) { - char *f = ne_concat(args->home, "/.", PACKAGE, "/", DAV_CERTS_DIR, "/", - DAV_CLICERTS_DIR, "/", args->clicert, NULL); + char *f = xasprintf("%s/.%s/%s/%s/%s", args->home, PACKAGE, + DAV_CERTS_DIR, DAV_CLICERTS_DIR, args->clicert); if (access(f, F_OK) == 0) { free(args->clicert); args->clicert = f; } } if (args->clicert && *args->clicert != '/' && args->privileged) { - char *f = ne_concat(DAV_SYS_CONF_DIR, "/", DAV_CERTS_DIR, "/", - DAV_CLICERTS_DIR, "/", args->clicert, NULL); + char *f = xasprintf("%s/%s/%s/%s", DAV_SYS_CONF_DIR, DAV_CERTS_DIR, + DAV_CLICERTS_DIR, args->clicert); free(args->clicert); args->clicert = f; } @@ -1097,8 +1091,8 @@ parse_config(dav_args *args) if (args->cache_dir) { expand_home(&args->cache_dir, args); } else { - args->cache_dir = ne_concat(args->home, "/.", PACKAGE, "/", - DAV_CACHE, NULL); + args->cache_dir = xasprintf("%s/.%s/%s", args->home, PACKAGE, + DAV_CACHE); } } @@ -1287,21 +1281,19 @@ write_mtab_entry(const dav_args *args) mntent.mnt_fsname = url; mntent.mnt_dir = mpoint; mntent.mnt_type = DAV_FS_TYPE; - mntent.mnt_opts = NULL; - if (asprintf(&mntent.mnt_opts, "%s%s%s%s%s%s", - (args->mopts & MS_RDONLY) ? "ro" : "rw", - (args->mopts & MS_NOSUID) ? ",nosuid" : "", - (args->mopts & MS_NOEXEC) ? ",noexec" : "", - (args->mopts & MS_NODEV) ? ",nodev" : "", - (args->netdev) ? ",_netdev" : "", - (args->add_mopts != NULL) ? args->add_mopts : "") < 0) - abort(); + mntent.mnt_opts = xasprintf("%s%s%s%s%s%s", + (args->mopts & MS_RDONLY) ? "ro" : "rw", + (args->mopts & MS_NOSUID) ? ",nosuid" : "", + (args->mopts & MS_NOEXEC) ? ",noexec" : "", + (args->mopts & MS_NODEV) ? ",nodev" : "", + (args->netdev) ? ",_netdev" : "", + (args->add_mopts != NULL) ? args->add_mopts : ""); mntent. mnt_freq = 0; mntent. mnt_passno = 0; if (!args->privileged) { char *opts = mntent.mnt_opts; - mntent.mnt_opts = ne_concat(opts, ",user=", args->uid_name, NULL); + mntent.mnt_opts = xasprintf("%s,user=%s", opts, args->uid_name); free(opts); } @@ -1529,9 +1521,7 @@ expand_home(char **dir, const dav_args *args) if (*p != '/') return; - char *new_dir = NULL; - if (asprintf(&new_dir, "%s%s", args->home, p) < 0) - abort(); + char *new_dir = xasprintf("%s%s", args->home, p); free(*dir); *dir = new_dir; } @@ -1638,10 +1628,8 @@ get_options(dav_args *args, char *option) } else { args->fsuid = pwd->pw_uid; } - if (asprintf(&add_mopts, "%s,uid=%i", - (args->add_mopts) ? args->add_mopts : "", - args->fsuid) < 0) - abort(); + add_mopts = xasprintf("%s,uid=%i", + (args->add_mopts) ? args->add_mopts : "", args->fsuid); if (args->add_mopts) free(args->add_mopts); args->add_mopts = add_mopts; @@ -1654,10 +1642,8 @@ get_options(dav_args *args, char *option) } else { args->fsgid = grp->gr_gid; } - if (asprintf(&add_mopts, "%s,gid=%i", - (args->add_mopts) ? args->add_mopts : "", - args->fsgid) < 0) - abort(); + add_mopts = xasprintf("%s,gid=%i", + (args->add_mopts) ? args->add_mopts : "", args->fsgid); if (args->add_mopts) free(args->add_mopts); args->add_mopts = add_mopts; @@ -2208,11 +2194,14 @@ read_config(dav_args *args, const char * filename, int system) } else if (applies && count == 3) { if (strcmp(parmv[0], "add_header") == 0) { - char *tmp = args->header; - args->header = ne_concat(parmv[1], ": ", parmv[2], "\r\n", tmp, - NULL); - if (tmp) - free(tmp); + if (args->header) { + char *tmp = args->header; + args->header = xasprintf("%s: %s\r\n%s", parmv[1], + parmv[2], tmp); + if (tmp) free(tmp); + } else { + args->header = xasprintf("%s: %s\r\n", parmv[1], parmv[2]); + } } else { error_at_line(EXIT_FAILURE, 0, filename, lineno, _("unknown option")); @@ -2258,8 +2247,7 @@ read_no_proxy_list(dav_args *args) char *host = NULL; if (strchr(np, ':')) { - if (asprintf(&host, "%s:%d", args->host, args->port) < 0) - abort(); + host = xasprintf("%s:%d", args->host, args->port); } else { host = xstrdup(args->host); } @@ -2497,7 +2485,7 @@ split_uri(char **scheme, char **host, int *port,char **path, const char *uri) } else if (*(pa + strlen(pa) - 1) == '/') { *path = xstrdup(pa); } else { - if (asprintf(path, "%s/", pa) < 1) abort(); + *path = xasprintf("%s/", pa); } } diff --git a/src/umount_davfs.c b/src/umount_davfs.c index 6573cfd..bdf7e29 100644 --- a/src/umount_davfs.c +++ b/src/umount_davfs.c @@ -41,6 +41,7 @@ #endif #include "xalloc.h" +#include "xvasprintf.h" #include @@ -140,14 +141,14 @@ main(int argc, char *argv[]) *m = '-'; m = strchr(mp, '/'); } - char *pidfile = ne_concat(DAV_SYS_RUN, "/", mp, ".pid", NULL); + char *pidfile = xasprintf("%s/%s.pid", DAV_SYS_RUN, mp); free(mp); - char *umount_command = ne_concat("umount -i '", mpoint, "'", NULL); + char *umount_command = xasprintf("umount -i '%s'", mpoint); - char *pid = NULL; + char pid[32]; FILE *file = fopen(pidfile, "r"); - if (!file || fscanf(file, "%a[0-9]", &pid) != 1 || !pid) { + if (!file || fscanf(file, "%30[0-9]", pid) != 1 || !pid) { error(0, 0, _("\n" " can't read PID from file %s;\n" @@ -157,7 +158,7 @@ main(int argc, char *argv[]) } fclose(file); - char *ps_command = ne_concat("ps -p ", pid, NULL); + char *ps_command = xasprintf("ps -p %s", pid); FILE *ps_in = popen(ps_command, "r"); if (!ps_in) { error(0, 0, diff --git a/src/webdav.c b/src/webdav.c index cbc3586..e475b54 100644 --- a/src/webdav.c +++ b/src/webdav.c @@ -57,6 +57,8 @@ #endif #include "xalloc.h" +#include "xstrndup.h" +#include "xvasprintf.h" #include #include @@ -377,7 +379,7 @@ dav_init_webdav(const dav_args *args) ne_set_connect_timeout(session, args->connect_timeout); #endif /* NE_VERSION_MINOR > 26 */ - char *useragent = ne_concat(PACKAGE_TARNAME, "/", PACKAGE_VERSION, NULL); + char *useragent = xasprintf("%s/%s", PACKAGE_TARNAME, PACKAGE_VERSION); ne_set_useragent(session, useragent); free(useragent); @@ -1278,7 +1280,7 @@ convert(char **s, iconv_t conv) && insize == 0 && outsize >= MB_LEN_MAX) { memset(out, 0, MB_LEN_MAX); free(*s); - *s = ne_strndup(buf, out - buf + MB_LEN_MAX); + *s = xstrndup(buf, out - buf + MB_LEN_MAX); } free(buf); @@ -1551,11 +1553,11 @@ replace_slashes(char **name) char *nn; *slash = '\0'; if (slash == *name) { - nn = ne_concat("slash-", slash + 1, NULL); + nn = xasprintf("slash-%s", slash + 1); } else if (slash == end) { - nn = ne_concat(*name, "-slash", NULL); + nn = xasprintf("%s-slash", *name); } else { - nn = ne_concat(*name, "-slash-", slash + 1, NULL); + nn = xasprintf("%s-slash-%s", *name, slash + 1); } free(*name); *name = nn; @@ -1776,7 +1778,7 @@ prop_result(void *userdata, const ne_uri *uri, const ne_prop_result_set *set) *(result->path + strlen(result->path) - 1) = '\0'; } else { if (result->is_dir) { - char *tmp = ne_concat(result->path, "/", NULL); + char *tmp = xasprintf("%s/", result->path); free(result->path); result->path = tmp; } @@ -2056,7 +2058,7 @@ update_cookie(ne_request *req, void *userdata, const ne_status *status) } char *value = ne_strndup(cookie_hdr, sep - cookie_hdr + 1); - cookie = ne_concat("Cookie: $Version=1;", value, "\r\n", NULL); + cookie = xasprintf("Cookie: $Version=1;%s\r\n", value); free(value); ne_hook_pre_send(session, add_header, cookie);