[vlc-devel] [PATCH] Fix Hurd build

Samuel Thibault samuel.thibault at ens-lyon.org
Wed Apr 27 13:47:13 CEST 2016


Denis Charmet, on Wed 27 Apr 2016 13:35:47 +0200, wrote:
> On 2016-04-27 13:21, Samuel Thibault wrote:
> >Denis Charmet, on Wed 27 Apr 2016 12:10:54 +0200, wrote:
> >>On 2016-04-26 21:14, Samuel Thibault wrote:
> >>>Rémi Denis-Courmont, on Tue 26 Apr 2016 22:12:04 +0300, wrote:
> >>>>I mean the following sprintf(). Maybe there was a nonobvious way to
> >>>>prevent
> >>>>overflow, but I don´t see it.
> >>>
> >>>Ok. The "idea" behind PATH_MAX is that it's supposed to be the maximum
> >>>size you'd want to pass with prefix and filename. But yes, that won't
> >>>prevent anybody from actually passing bigger filenames, and so the
> >>>second patch I sent, which uses malloc, just avoids the issue
> >>>altogether.
> >>
> >>I think the point of Rémi was: use snprintf and not sprintf regardless
> >>of
> >>your memory zone of allocation.
> >
> >Then this?
> 
> Nope let the stack buffer with snprintf

Ok, then back to this?

>From aac67ee41cd77b6fab6c914e272e1cb84c32c648 Mon Sep 17 00:00:00 2001
From: Samuel Thibault <samuel.thibault at ens-lyon.org>
Date: Tue, 26 Apr 2016 18:22:41 +0000
Subject: [PATCH] Fix hurd build

theme_loader.cpp contains an unconditional use of PATH_MAX,
which is not defined on GNU/Hurd to avoid imposing build-time
limits. This change replaces its use with dynamic allocation of the
required size.
---
 modules/gui/skins2/src/theme_loader.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/modules/gui/skins2/src/theme_loader.cpp b/modules/gui/skins2/src/theme_loader.cpp
index 1ec1dfc..b4cf7e8 100644
--- a/modules/gui/skins2/src/theme_loader.cpp
+++ b/modules/gui/skins2/src/theme_loader.cpp
@@ -549,7 +549,9 @@ int tar_extract_all( TAR *t, char *prefix )
     union tar_buffer buffer;
     int   len, err, getheader = 1, remaining = 0;
     FILE  *outfile = NULL;
-    char  fname[BLOCKSIZE + PATH_MAX];
+    long  path_max = pathconf (".", _PC_PATH_MAX);
+    size_t maxsize = (path_max == -1 || path_max > 4096) ? 4096 : path_max;
+    char  fname[BLOCKSIZE + maxsize];
 
     while( 1 )
     {
@@ -583,7 +585,7 @@ int tar_extract_all( TAR *t, char *prefix )
                 break;
             }
 
-            sprintf( fname, "%s/%s", prefix, buffer.header.name );
+            snprintf( fname, sizeof(fname), "%s/%s", prefix, buffer.header.name );
 
             /* Check magic value in header */
             if( strncmp( buffer.header.magic, "GNUtar", 6 ) &&
-- 
2.6.4



More information about the vlc-devel mailing list