From b818a7086b921ea66d2e31dd11add1c34bb5dddf Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <mail@bernhard-voelker.de>
Date: Fri, 16 Oct 2020 16:25:13 +0200
Subject: [PATCH] find: add error handling for strdup in the '-print %h' case

* find/print.c (do_fprintf): Change strdup call to xstrdup to ensure
proper error handling.  Reported by Infer.

Fixes https://sv.gnu.org/bugs/?59133
---
 find/print.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/find/print.c b/find/print.c
index 8b555343..88635b54 100644
--- a/find/print.c
+++ b/find/print.c
@@ -958,7 +958,7 @@ do_fprintf (struct format_val *dest,
         case 'h':               /* leading directories part of path */
           /* sanitised */
           {
-            char *pname = strdup (pathname);
+            char *pname = xstrdup (pathname);
 
             /* Remove trailing slashes - unless it's the root '/' directory.  */
             char *s = pname + strlen (pname) -1;
-- 
2.28.0

