Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Nov 2006 18:07:09 +0100 (CET)
From:      "Frank W. Josellis" <frank@dynamical-systems.org>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   ports/105214: patch: archivers/unmakeself - extraction fails under certain conditions
Message-ID:  <200611061707.kA6H79oB001976@pollux.senax.net>
Resent-Message-ID: <200611061720.kA6HKKBR054117@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         105214
>Category:       ports
>Synopsis:       patch: archivers/unmakeself - extraction fails under certain conditions
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Nov 06 17:20:19 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     Frank W. Josellis
>Release:        FreeBSD 5.5-STABLE i386
>Organization:
>Environment:
System: FreeBSD pollux.senax.net 5.5-STABLE FreeBSD 5.5-STABLE #11: Fri Oct 27 20:51:49 CEST 2006 root@pollux.senax.net:/usr/obj/usr/src/sys/POLLUX i386


	
>Description:
It appears that the offset calculation is not always correct. The approach
fails in an obvious way if the first line of an archive consists entirely of
printable characters. Unfortunately, this can indeed happen, an example
is the latest GoogleEarthLinux.bin (version 4.0.2414). Please consider the
patch below for a different method to determine the offset.  

>How-To-Repeat:
fetch http://dl.google.com/earth/GE4/GoogleEarthLinux.bin

unmakeself GoogleEarthLinux.bin

>Fix:

	

--- unmakeself.patch begins here ---
diff -Nur unmakeself.orig/files/unmakeself.c unmakeself/files/unmakeself.c
--- unmakeself.orig/files/unmakeself.c	Sun Jun 12 20:17:05 2005
+++ unmakeself/files/unmakeself.c	Mon Nov  6 14:36:53 2006
@@ -43,6 +43,8 @@
 #include <getopt.h>
 #include <archive.h>
 
+#define BUFSIZE 4096
+
 static char *self = NULL;				/* program name */
 static int extract_flags = ARCHIVE_EXTRACT_TIME;	/* bsdtar default */
 
@@ -70,6 +72,36 @@
   printf("Copyright (C) 2005 Jean-Yves Lefort\n");
 }
 
+static int
+unmakeself_get_offset (const char *filename)
+{
+  int offset = -1;
+  int skip = 0;
+  char buf[BUFSIZE];
+  FILE *stream;
+
+  /* Let the script tell us the number of header lines. */
+  snprintf(buf, BUFSIZE,
+	   "sh %s --dumpconf | grep OLDSKIP | cut -f2 -d=", filename);
+  stream = popen(buf, "r");
+  skip = atoi(fgets(buf, BUFSIZE, stream));
+  pclose(stream);
+
+  /* Scan the header lines to calculate the offset. */
+  if (skip) {
+    int i;
+    
+    stream = fopen(filename, "r");
+    for (i = 0; i < skip - 1; i++) {
+      fgets(buf, BUFSIZE, stream);
+      offset += strlen(buf);
+    }
+    fclose(stream);
+    offset++;
+  }
+  return(offset);
+}
+
 static void
 unmakeself_extract (const char *filename, int print_offset)
 {
@@ -93,6 +125,7 @@
    * by locating the first non-printable character following a
    * newline. The archive starts immediately after that newline.
    */
+  /*
   while (! done && (len = read(fd, buf, sizeof(buf))) > 0)
     {
       int i;
@@ -109,7 +142,9 @@
 	    break;
 	  }
     }
+  */
 
+  offset = unmakeself_get_offset(filename);
   if (offset != -1)		/* offset found */
     {
       if (print_offset)		/* only print the offset */
--- unmakeself.patch ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200611061707.kA6H79oB001976>