Index | Thread | Search

From:
"Omar Polo" <op@omarpolo.com>
Subject:
Re: patch: bail out in fetchname() if out_of_memory
To:
tech@openbsd.org
Date:
Thu, 05 Nov 2026 11:52:58 +0100

Download raw body.

Thread
"Omar Polo" <op@omarpolo.com> wrote:
> savestr() is basically xstrdup() with an optional path for "plan A"
> where it returns NULL instead of fatal().
> 
> afaik, this is the only place where we don't check out_of_mem after
> savestr().  bailing out seems nicer than crashing on the next line.
> 
> ok?

forgot the other hunk in fetchname(), sorry.

commit df9b60583bdd11046eda4aec845c0b6d98a36282 (master)
from: Omar Polo <op@omarpolo.com>
date: Thu Nov  5 10:50:57 2026 UTC
 
 bail out on fetchname on OOM
 
diff df4e48f5c58474cd91cf83065e253c9efdfe5d93 df9b60583bdd11046eda4aec845c0b6d98a36282
commit - df4e48f5c58474cd91cf83065e253c9efdfe5d93
commit + df9b60583bdd11046eda4aec845c0b6d98a36282
blob - c94a3f2beb10a18d9687941619e72776bf160a7f
blob + d7f39409e668dd259d144bf30536fb59278429a3
--- usr.bin/patch/util.c
+++ usr.bin/patch/util.c
@@ -356,6 +356,8 @@ fetchname(const char *at, bool *exists, int strip_lead
 	if (strnEQ(at, _PATH_DEVNULL, sizeof(_PATH_DEVNULL) - 1))
 		return NULL;
 	name = fullname = t = savestr(at);
+	if (out_of_mem)
+		return NULL;
 
 	tab = strchr(t, '\t') != NULL;
 	/* Strip off up to `strip_leading' path components and NUL terminate. */
@@ -380,6 +382,8 @@ fetchname(const char *at, bool *exists, int strip_lead
 		}
 	}
 	name = savestr(name);
+	if (out_of_mem)
+		return NULL;
 	free(fullname);
 
 	*exists = stat(name, &filestat) == 0;