From c46ae39631773a7fdae7d171cc4ef0bf2123efff Mon Sep 17 00:00:00 2001
From: Eric Blake <ebb9@byu.net>
Date: Fri, 4 Sep 2009 21:22:21 -0600
Subject: [PATCH] openat: fail with ENOENT on empty name

* lib/openat-proc.c (openat_proc_name): Special-case the empty
buffer.

Signed-off-by: Eric Blake <ebb9@byu.net>
---
 ChangeLog         | 4 ++++
 lib/openat-proc.c | 7 +++++++
 2 files changed, 11 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 193ec7f196..ecbf16e27f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2009-09-04  Eric Blake  <ebb9@byu.net>
 
+	openat: fail with ENOENT on empty name
+	* lib/openat-proc.c (openat_proc_name): Special-case the empty
+	buffer.
+
 	link-follow: fix logic bug in prior patch
 	* m4/link-follow.m4 (gl_FUNC_LINK_FOLLOWS_SYMLINK): Fix bug that
 	reversed sense of yes and no in prior patch.  Avoid confusing
diff --git a/lib/openat-proc.c b/lib/openat-proc.c
index 8057033e86..76e1c6dd51 100644
--- a/lib/openat-proc.c
+++ b/lib/openat-proc.c
@@ -57,6 +57,13 @@ openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file)
 {
   static int proc_status = 0;
 
+  /* Make sure the caller gets ENOENT when appropriate.  */
+  if (!*file)
+    {
+      buf[0] = '\0';
+      return buf;
+    }
+
   if (! proc_status)
     {
       /* Set PROC_STATUS to a positive value if /proc/self/fd is
-- 
2.30.2