From: gilles Date: Tue, 6 Oct 2015 05:48:34 +0000 (+0000) Subject: fix reallocarray() constructs to always use temporary variable X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=483e84519ae6487e6ee51a55a2ed439624fb6bc0;p=openbsd fix reallocarray() constructs to always use temporary variable --- diff --git a/usr.sbin/smtpd/smtpctl.c b/usr.sbin/smtpd/smtpctl.c index c2b4ff0a0c1..2344a2d49fb 100644 --- a/usr.sbin/smtpd/smtpctl.c +++ b/usr.sbin/smtpd/smtpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpctl.c,v 1.125 2015/01/20 17:37:54 deraadt Exp $ */ +/* $OpenBSD: smtpctl.c,v 1.126 2015/10/06 05:48:34 gilles Exp $ */ /* * Copyright (c) 2013 Eric Faurot @@ -302,7 +302,7 @@ srv_iter_envelopes(uint32_t msgid, struct envelope *evp) static int srv_iter_evpids(uint32_t msgid, uint64_t *evpid, int *offset) { - static uint64_t *evpids = NULL; + static uint64_t *evpids = NULL, *tmp; static int n, alloc = 0; struct envelope evp; @@ -318,10 +318,11 @@ srv_iter_evpids(uint32_t msgid, uint64_t *evpid, int *offset) while (srv_iter_envelopes(msgid, &evp)) { if (n == alloc) { alloc += 256; - evpids = reallocarray(evpids, alloc, + tmp = reallocarray(evpids, alloc, sizeof(*evpids)); - if (evpids == NULL) + if (tmp == NULL) err(1, "reallocarray"); + evpids = tmp; } evpids[n++] = evp.id; } diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c index a7409bc6470..9d2bb34eff6 100644 --- a/usr.sbin/smtpd/util.c +++ b/usr.sbin/smtpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.116 2015/10/05 22:08:14 stsp Exp $ */ +/* $OpenBSD: util.c,v 1.117 2015/10/06 05:48:34 gilles Exp $ */ /* * Copyright (c) 2000,2001 Markus Friedl. All rights reserved. @@ -554,6 +554,7 @@ addargs(arglist *args, char *fmt, ...) char *cp; uint nalloc; int r; + char **tmp; va_start(ap, fmt); r = vasprintf(&cp, fmt, ap); @@ -568,9 +569,10 @@ addargs(arglist *args, char *fmt, ...) } else if (args->num+2 >= nalloc) nalloc *= 2; - args->list = reallocarray(args->list, nalloc, sizeof(char *)); - if (args->list == NULL) + tmp = reallocarray(args->list, nalloc, sizeof(char *)); + if (tmp == NULL) fatal("addargs: reallocarray"); + args->list = tmp; args->nalloc = nalloc; args->list[args->num++] = cp; args->list[args->num] = NULL;