From f799c09038ac05030a43bf5c22a77847c12cef65 Mon Sep 17 00:00:00 2001
From: Sven Geuer <sge@debian.org>
Date: Mon, 3 Mar 2025 22:41:14 +0100
Subject: [PATCH] Consider only regular files when trying potential info files

Unpatched, pinfo tries to open all kinds of files, including
directories, sockets, devices, etc. This change makes sure only regular files
are taken into account when picking an info file.

See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1021533 for
further details.

From: https://github.com/baszoetekouw/pinfo/pull/40
---
 src/filehandling_functions.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/filehandling_functions.c b/src/filehandling_functions.c
index b05596c..49f1eb7 100644
--- a/src/filehandling_functions.c
+++ b/src/filehandling_functions.c
@@ -759,6 +759,7 @@ openinfo(char *filename, int number)
 #define BUF_LEN 1024
 	char *buf = xmalloc(BUF_LEN);	/* holds local copy of filename */
 	char *bufend;			/* points at the trailing 0 of initial name */
+	struct stat sbuf;
 	char command[1128];		/* holds command to evaluate for decompression of file */
 	int i, j;
 	char *tmpfilename;
@@ -822,7 +823,9 @@ openinfo(char *filename, int number)
 		for (j = 0; j < SuffixesNumber; j++)	/* go through all suffixes */
 		{
 			strcat(buf, suffixes[j].suffix);
-			if ((id = fopen(buf, "r")) != NULL)
+			if (stat(buf, &sbuf) != 0)
+				sbuf.st_mode = S_IFMT;
+			if (S_ISREG(sbuf.st_mode) && (id = fopen(buf, "r")) != NULL)
 			{
 				fclose(id);
 				clearfilenameprefix();
