Package: src:libs3
Version: 2.0-4
Severity: important
Tags: ftbfs patch

On Linux _UTSNAME_SYSNAME_LENGTH and _UTSNAME_MACHINE_LENGTH are 65,
and the platform string, which is defined as

char platform[_UTSNAME_SYSNAME_LENGTH + 1 + _UTSNAME_MACHINE_LENGTH];

fits into the subsequent snprintf command:

snprintf(userAgentG, sizeof(userAgentG),
         "Mozilla/4.0 (Compatible; %s; libs3 %s.%s; %s)",
         userAgentInfo, LIBS3_VER_MAJOR, LIBS3_VER_MINOR, platform);

where the target string is defined as:

#define USER_AGENT_SIZE 256
static char userAgentG[USER_AGENT_SIZE];

However, on Hurd _UTSNAME_SYSNAME_LENGTH and _UTSNAME_MACHINE_LENGTH
are 1024, and the compilation fails:

src/request.c:1105:57: error: ‘%s’ directive output may be truncated writing up 
to 2048 bytes into a region of size between 211 and 218 
[-Werror=format-truncation=]
 1105 |              "Mozilla/4.0 (Compatible; %s; libs3 %s.%s; %s)",
      |                                                         ^~
 1106 |              userAgentInfo, LIBS3_VER_MAJOR, LIBS3_VER_MINOR, platform);
      |                                                               ~~~~~~~~
src/request.c:1104:5: note: ‘snprintf’ output 40 or more bytes (assuming 2095) 
into a destination of size 256
 1104 |     snprintf(userAgentG, sizeof(userAgentG),
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1105 |              "Mozilla/4.0 (Compatible; %s; libs3 %s.%s; %s)",
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1106 |              userAgentInfo, LIBS3_VER_MAJOR, LIBS3_VER_MINOR, platform);
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

The attached updated patch (intended to replace the current
debian/patches/utsn.patch has the following change:

-#define USER_AGENT_SIZE 256
+#define USER_AGENT_SIZE 126 + _UTSNAME_SYSNAME_LENGTH + _UTSNAME_MACHINE_LENGTH

This implies no change for Linux (126 + 65 + 65 = 256), but increases
the size to the appropriate size on Hurd.

diff -ur libs3-2.0.orig/src/request.c libs3-2.0/src/request.c
--- libs3-2.0.orig/src/request.c	2011-09-28 10:16:09.000000000 +0200
+++ libs3-2.0/src/request.c	2025-04-27 13:12:52.000000000 +0200
@@ -35,7 +35,7 @@
 #include "util.h"
 
 
-#define USER_AGENT_SIZE 256
+#define USER_AGENT_SIZE 126 + _UTSNAME_SYSNAME_LENGTH + _UTSNAME_MACHINE_LENGTH
 #define REQUEST_STACK_SIZE 32
 
 static char userAgentG[USER_AGENT_SIZE];
@@ -1089,7 +1089,7 @@
         userAgentInfo = "Unknown";
     }
 
-    char platform[96];
+    char platform[_UTSNAME_SYSNAME_LENGTH + 1 + _UTSNAME_MACHINE_LENGTH];
     struct utsname utsn;
     if (uname(&utsn)) {
         strncpy(platform, "Unknown", sizeof(platform));

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to