From: claudio Date: Mon, 17 May 2021 12:02:58 +0000 (+0000) Subject: Error out on memory failures in fargs_cmdline() and addargs() in both X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=dd3c9d240a3d0c8e4718db3935768d953e47b2d9;p=openbsd Error out on memory failures in fargs_cmdline() and addargs() in both cases it was impossible to start the remote rsync anyway. Also now fargs_cmdline() can no longer fail. Add missing err(ERR_IPC, "pldege") for the cases in socket.c OK benno@ --- diff --git a/usr.bin/rsync/fargs.c b/usr.bin/rsync/fargs.c index bb7123717d1..10eea6fa572 100644 --- a/usr.bin/rsync/fargs.c +++ b/usr.bin/rsync/fargs.c @@ -1,4 +1,4 @@ -/* $Id: fargs.c,v 1.17 2019/05/08 20:00:25 benno Exp $ */ +/* $Id: fargs.c,v 1.18 2021/05/17 12:02:58 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -51,7 +52,7 @@ fargs_cmdline(struct sess *sess, const struct fargs *f, size_t *skip) if (sess->opts->ssh_prog) { ap = strdup(sess->opts->ssh_prog); if (ap == NULL) - goto out; + err(ERR_NOMEM, NULL); while ((arg = strsep(&ap, " \t")) != NULL) { if (arg[0] == '\0') { @@ -127,8 +128,4 @@ fargs_cmdline(struct sess *sess, const struct fargs *f, size_t *skip) addargs(&args, "%s", f->sink); return args.list; -out: - freeargs(&args); - ERR("calloc"); - return NULL; } diff --git a/usr.bin/rsync/misc.c b/usr.bin/rsync/misc.c index 95cba8b5aec..5abc7e039cf 100644 --- a/usr.bin/rsync/misc.c +++ b/usr.bin/rsync/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.2 2021/03/22 11:14:42 claudio Exp $ */ +/* $OpenBSD: misc.c,v 1.3 2021/05/17 12:02:58 claudio Exp $ */ /* * Copyright (c) 2000 Markus Friedl. All rights reserved. * Copyright (c) 2005,2006 Damien Miller. All rights reserved. @@ -45,7 +45,7 @@ addargs(arglist *args, const char *fmt, ...) r = vasprintf(&cp, fmt, ap); va_end(ap); if (r == -1) - err(1, "addargs: argument too long"); + err(ERR_NOMEM, "addargs: argument too long"); nalloc = args->nalloc; if (args->list == NULL) { @@ -54,9 +54,10 @@ addargs(arglist *args, const char *fmt, ...) } else if (args->num+2 >= nalloc) nalloc *= 2; - args->list = recallocarray(args->list, args->nalloc, nalloc, sizeof(char *)); + args->list = recallocarray(args->list, args->nalloc, nalloc, + sizeof(char *)); if (!args->list) - err(1, "malloc"); + err(ERR_NOMEM, NULL); args->nalloc = nalloc; args->list[args->num++] = cp; args->list[args->num] = NULL; diff --git a/usr.bin/rsync/socket.c b/usr.bin/rsync/socket.c index f740c2dff2a..da58f5f2334 100644 --- a/usr.bin/rsync/socket.c +++ b/usr.bin/rsync/socket.c @@ -1,4 +1,4 @@ -/* $Id: socket.c,v 1.29 2021/03/31 19:45:16 job Exp $ */ +/* $Id: socket.c,v 1.30 2021/05/17 12:02:58 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -281,7 +281,7 @@ rsync_connect(const struct opts *opts, int *sd, const struct fargs *f) if (pledge("stdio unix rpath wpath cpath dpath inet fattr chown dns getpw unveil", NULL) == -1) - err(1, "pledge"); + err(ERR_IPC, "pledge"); memset(&sess, 0, sizeof(struct sess)); sess.opts = opts; @@ -365,7 +365,7 @@ rsync_socket(const struct opts *opts, int sd, const struct fargs *f) if (pledge("stdio unix rpath wpath cpath dpath fattr chown getpw unveil", NULL) == -1) - err(1, "pledge"); + err(ERR_IPC, "pledge"); memset(&sess, 0, sizeof(struct sess)); sess.lver = RSYNC_PROTOCOL; @@ -374,10 +374,7 @@ rsync_socket(const struct opts *opts, int sd, const struct fargs *f) assert(f->host != NULL); assert(f->module != NULL); - if ((args = fargs_cmdline(&sess, f, &skip)) == NULL) { - ERRX1("fargs_cmdline"); - exit(1); - } + args = fargs_cmdline(&sess, f, &skip); /* Initiate with the rsyncd version and module request. */