From fd6a1eb9f8e10949e0a928d576a489679760b00f Mon Sep 17 00:00:00 2001 From: otto Date: Thu, 21 Dec 2023 08:01:21 +0000 Subject: [PATCH] Fix a few unchecked allocations; ok millert@ miod@ --- sbin/dump/dumprmt.c | 4 ++-- sbin/dump/itime.c | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/sbin/dump/dumprmt.c b/sbin/dump/dumprmt.c index 28bd7115d10..4bd2171de09 100644 --- a/sbin/dump/dumprmt.c +++ b/sbin/dump/dumprmt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dumprmt.c,v 1.32 2023/03/08 04:43:06 guenther Exp $ */ +/* $OpenBSD: dumprmt.c,v 1.33 2023/12/21 08:01:21 otto Exp $ */ /* $NetBSD: dumprmt.c,v 1.17 1997/06/05 16:10:47 mrg Exp $ */ /*- @@ -90,7 +90,7 @@ rmthost(char *host) if (rmtpeer) strlcpy(rmtpeer, host, len); else - rmtpeer = host; + return (0); signal(SIGPIPE, rmtconnaborted); rmtgetconn(); if (rmtape < 0) diff --git a/sbin/dump/itime.c b/sbin/dump/itime.c index 0cd11f18150..4498d91b19c 100644 --- a/sbin/dump/itime.c +++ b/sbin/dump/itime.c @@ -1,4 +1,4 @@ -/* $OpenBSD: itime.c,v 1.25 2021/01/21 00:16:36 mortimer Exp $ */ +/* $OpenBSD: itime.c,v 1.26 2023/12/21 08:01:21 otto Exp $ */ /* $NetBSD: itime.c,v 1.4 1997/04/15 01:09:50 lukem Exp $ */ /*- @@ -99,6 +99,8 @@ readdumptimes(FILE *df) for (;;) { dtwalk = calloc(1, sizeof(struct dumptime)); + if (dtwalk == NULL) + quit("allocation failed"); if (getrecord(df, &(dtwalk->dt_value)) < 0) { free(dtwalk); break; @@ -114,6 +116,8 @@ readdumptimes(FILE *df) * record that we may have to add to the ddate structure */ ddatev = calloc((unsigned) (nddates + 1), sizeof(struct dumpdates *)); + if (ddatev == NULL) + quit("allocation failed"); dtwalk = dthead; for (i = nddates - 1; i >= 0; i--, dtwalk = dtwalk->dt_next) ddatev[i] = &dtwalk->dt_value; @@ -192,6 +196,8 @@ putdumptime(void) * Enough room has been allocated. */ dtwalk = ddatev[nddates] = calloc(1, sizeof(struct dumpdates)); + if (dtwalk == NULL) + quit("allocation failed"); nddates += 1; found: (void) strlcpy(dtwalk->dd_name, fname, sizeof(dtwalk->dd_name)); -- 2.20.1