Subject: bug#13472: Execution mode can hang pc when parameter refers to big file

From: Petr Hracek <[email-masked]>
Date: Tue, 22 Jan 2013 16:03:02 +0100

Hello Bob,

I have created simple helper binary which can be replaced with sed
in case that dd is not available.
Patch is in attachment including new c source file.

best regards
Petr
--
Greetings,
Petr Hracek

BaseOS Core Services Brno

diff --git a/Makefile.am b/Makefile.am
index a3e3c7d..c29373b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -464,6 +464,7 @@ pkgltdl_files	= COPYING.LIB \
 		  loaders/loadlibrary.c \
 		  loaders/preopen.c \
 		  loaders/shl_load.c \
+		  loaders/load_head.c \
 		  lt__alloc.c \
 		  lt__dirent.c \
 		  lt__strl.c \
diff --git a/bootstrap b/bootstrap
index 9c7c01f..44681b3 100755
--- a/bootstrap
+++ b/bootstrap
@@ -154,6 +154,7 @@ fi
 : ${MKDIR="mkdir"}
 : ${MV="mv -f"}
 : ${RM="rm -f"}
+: ${DD="/bin/dd"}
 : ${SED="sed"}
 : ${SHELL="${CONFIG_SHELL-/bin/sh}"}
 
diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in
index c8cdb9c..750f34e 100644
--- a/build-aux/ltmain.in
+++ b/build-aux/ltmain.in
@@ -575,7 +575,7 @@ _LTECHO_EOF'
 func_lalib_p ()
 {
     test -f "$1" &&
-      $SED -e 4q "$1" 2>/dev/null \
+      if [ -x "$DD" ]; then $DD if=$1 bs=16K count=1 2>/dev/null; else load_head $1 2>/dev/null; fi \
         | $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
 }
 
diff --git a/libltdl/loaders/load_head.c b/libltdl/loaders/load_head.c
new file mode 100644
index 0000000..f0835d4
--- /dev/null
+++ b/libltdl/loaders/load_head.c
@@ -0,0 +1,68 @@
+/* loader-loadlibrary.c --  dynamic linking for Win32
+
+   Copyright (C) 1998-2000, 2004-2008, 2010-2013 Free Software
+   Foundation, Inc.
+   Written by Thomas Tanner, 1998
+
+   NOTE: The canonical source of this file is maintained with the
+   GNU Libtool package.  Report bugs to [email-masked].
+
+GNU Libltdl is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+As a special exception to the GNU Lesser General Public License,
+if you distribute this file as part of a program or library that
+is built using GNU Libtool, you may include this file under the
+same distribution terms that you use for the rest of that program.
+
+GNU Libltdl is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with GNU Libltdl; see the file COPYING.LIB.  If not, a
+copy can be downloaded from  http://www.gnu.org/licenses/lgpl.html,
+or obtained by writing to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define MAX_SIZE 16384
+int main(int argc, char * argv[])
+{
+	unsigned char buffer[MAX_SIZE];
+	FILE * pFile;
+	int n=0;
+
+	if(argc < 2)
+	{
+		printf("Filename as argument is missing\n");
+		exit(1);
+	}
+	if(argc > 2)
+	{
+		printf("There is a lot of arguments. Only filename is allowed\n");
+		exit(1);
+	}
+	pFile = fopen(argv[1],"r");
+	if(pFile == NULL)
+	{
+		printf("Problem with openning file %s\n",argv[1]);
+		exit(1);
+	}
+	n = fread(buffer,1,MAX_SIZE,pFile);
+	if(n==0)
+	{
+		printf("Problem with reading file\n");
+		exit(1);
+	}
+	printf("%s",buffer);
+	fclose(pFile);
+	exit (0);
+	
+}