From 3d0e8811640553198560792213a100a065680aca Mon Sep 17 00:00:00 2001
From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
Date: Tue, 28 Aug 2018 16:15:03 -0400
Subject: [PATCH] avoid weird interactions with the GNU version of strerror_r

---
 hddemux.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/hddemux.c b/hddemux.c
index e2a3ed4..f616cef 100644
--- a/hddemux.c
+++ b/hddemux.c
@@ -167,7 +167,11 @@ static void dump_addrinfo(FILE *f, const char *label, const struct addrinfo *a,
   if (ia) {
     if (inet_ntop(a->ai_family, ia, paddr, sizeof(paddr)) == NULL) {
       int e = errno;
-      strerror_r(e, paddr+6, sizeof(paddr)-(6+1));
+      /* these shenanigans are all for the GNU variant of
+         strerror_r(3), not the XSI variant: */
+      const char * e2 = strerror_r(e, paddr+6, sizeof(paddr)-(6+1));
+      if (e2 != paddr+6)
+        strncpy(paddr+6, e2, sizeof(paddr)-(6+1));
       memcpy(paddr, "<err> ", 6);
       paddr[sizeof(paddr)-1] = '\0';
     }
-- 
GitLab