From 6d207a7535cfcf8b29344bced795c7af2d3cbcb3 Mon Sep 17 00:00:00 2001 From: jca Date: Wed, 5 Apr 2017 13:38:18 +0000 Subject: [PATCH] Don't rely on asprintf setting pointer to NULL on failure. ok millert@ deraadt@ tom@ --- usr.sbin/rtadvd/dump.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/usr.sbin/rtadvd/dump.c b/usr.sbin/rtadvd/dump.c index cafccadb973..bccfad7a3fb 100644 --- a/usr.sbin/rtadvd/dump.c +++ b/usr.sbin/rtadvd/dump.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dump.c,v 1.22 2017/04/02 22:57:20 deraadt Exp $ */ +/* $OpenBSD: dump.c,v 1.23 2017/04/05 13:38:18 jca Exp $ */ /* $KAME: dump.c,v 1.27 2002/05/29 14:23:55 itojun Exp $ */ /* @@ -113,7 +113,7 @@ rtadvd_dump(void) int first; struct timeval now, next; char *origin, *vltime, *pltime, *flags; - char *vltimexpire=NULL, *pltimexpire=NULL; + char *vltimexpire, *pltimexpire; char ctimebuf[26]; gettimeofday(&now, NULL); @@ -186,16 +186,23 @@ rtadvd_dump(void) default: origin = ""; } - if (pfx->vltimeexpire != 0) + if (pfx->vltimeexpire != 0) { /* truncate to onwire value */ - asprintf(&vltimexpire, "(decr,expire %u)", + if (asprintf(&vltimexpire, "(decr,expire %u)", (u_int32_t)(pfx->vltimeexpire > now.tv_sec ? - pfx->vltimeexpire - now.tv_sec : 0)); - if (pfx->pltimeexpire != 0) + pfx->vltimeexpire - now.tv_sec : 0)) == -1) + vltimexpire = NULL; + } else + vltimexpire = NULL; + + if (pfx->pltimeexpire != 0) { /* truncate to onwire value */ - asprintf(&pltimexpire, "(decr,expire %u)", + if (asprintf(&pltimexpire, "(decr,expire %u)", (u_int32_t)(pfx->pltimeexpire > now.tv_sec ? - pfx->pltimeexpire - now.tv_sec : 0)); + pfx->pltimeexpire - now.tv_sec : 0)) == -1) + pltimexpire = NULL; + } else + pltimexpire = NULL; vltime = lifetime(pfx->validlifetime); pltime = lifetime(pfx->preflifetime); -- 2.20.1