[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#566664: apt-ftparchive segfaults on hurd-i386



Package: apt
Version: 0.7.25
Severity: important
Tags: patch

Hello,

apt-ftparchive currently crashes because the case when
pathconf(".",_PC_PATH_MAX); returns -1 (no limit) is not properly
handled. The attached patch replaces it with just using glibc's
realpath(path, NULL) feature (which got into POSIX 2008 btw).

Samuel

-- Package-specific info:

-- (no /etc/apt/preferences present) --


-- (/etc/apt/sources.list present, but not submitted) --


-- System Information:
Debian Release: squeeze/sid
  APT prefers testing
  APT policy: (990, 'testing'), (500, 'unstable'), (500, 'stable'), (1, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.32 (SMP w/2 CPU cores)
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages apt depends on:
ii  debian-archive-keyring  2009.01.31       GnuPG archive keys of the Debian a
ii  libc6                   2.10.2-2         GNU C Library: Shared libraries
ii  libgcc1                 1:4.5-20091226-1 GCC support library
ii  libstdc++6              4.4.2-9          The GNU Standard C++ Library v3

apt recommends no packages.

Versions of packages apt suggests:
pn  apt-doc                   <none>         (no description available)
ii  aptitude                  0.4.11.11-1+b2 terminal-based package manager
ii  bzip2                     1.0.5-3        high-quality block-sorting file co
ii  dpkg-dev                  1.15.5.6       Debian package development tools
ii  lzma                      4.43-14        Compression method of 7z format in
ii  python-apt                0.7.13.3       Python interface to libapt-pkg
ii  synaptic                  0.63           Graphical package manager

-- no debconf information

-- 
Samuel Thibault <samuel.thibault@fnac.net>
R: Parce que a renverse btement l'ordre naturel de lecture!
Q: Mais pourquoi citer en fin d'article est-il si effroyable?
R: Citer en fin d'article
Q: Quelle est la chose la plus dsagrable sur les groupes de news?
diff -ur tmp/apt-0.7.25.1/ftparchive/writer.cc apt-0.7.25.1/ftparchive/writer.cc
--- tmp/apt-0.7.25.1/ftparchive/writer.cc	2010-01-09 20:56:01.000000000 +0000
+++ apt-0.7.25.1/ftparchive/writer.cc	2010-01-24 12:27:55.000000000 +0000
@@ -58,10 +58,6 @@
 {
    ErrorPrinted = false;
    NoLinkAct = !_config->FindB("APT::FTPArchive::DeLinkAct",true);
-   RealPath = 0;
-   long PMax = pathconf(".",_PC_PATH_MAX);
-   if (PMax > 0)
-      RealPath = new char[PMax];
 }
 									/*}}}*/
 // FTWScanner::Scanner - FTW Scanner					/*{{{*/
@@ -92,6 +88,8 @@
 int FTWScanner::ScannerFile(const char *File, bool ReadLink)
 {
    const char *LastComponent = strrchr(File, '/');
+   char *RealPath;
+
    if (LastComponent == NULL)
       LastComponent = File;
    else
@@ -111,10 +109,13 @@
       given are not links themselves. */
    char Jnk[2];
    Owner->OriginalPath = File;
-   if (ReadLink && Owner->RealPath != 0 &&
+   if (ReadLink &&
        readlink(File,Jnk,sizeof(Jnk)) != -1 &&
-       realpath(File,Owner->RealPath) != 0)
-      Owner->DoPackage(Owner->RealPath);
+       (RealPath = realpath(File,NULL)) != 0)
+   {
+      Owner->DoPackage(RealPath);
+      free(RealPath);
+   }
    else
       Owner->DoPackage(File);
    
@@ -150,13 +151,15 @@
 /* */
 bool FTWScanner::RecursiveScan(string Dir)
 {
+   char *RealPath;
    /* If noprefix is set then jam the scan root in, so we don't generate
       link followed paths out of control */
    if (InternalPrefix.empty() == true)
    {
-      if (realpath(Dir.c_str(),RealPath) == 0)
+      if ((RealPath = realpath(Dir.c_str(),NULL)) == 0)
 	 return _error->Errno("realpath",_("Failed to resolve %s"),Dir.c_str());
-      InternalPrefix = RealPath;      
+      InternalPrefix = RealPath;
+      free(RealPath);
    }
    
    // Do recursive directory searching
@@ -180,13 +183,15 @@
    of files from another file. */
 bool FTWScanner::LoadFileList(string Dir,string File)
 {
+   char *RealPath;
    /* If noprefix is set then jam the scan root in, so we don't generate
       link followed paths out of control */
    if (InternalPrefix.empty() == true)
    {
-      if (realpath(Dir.c_str(),RealPath) == 0)
+      if ((RealPath = realpath(Dir.c_str(),NULL)) == 0)
 	 return _error->Errno("realpath",_("Failed to resolve %s"),Dir.c_str());
       InternalPrefix = RealPath;      
+      free(RealPath);
    }
    
    Owner = this;
@@ -668,6 +673,7 @@
    // Perform the delinking operation over all of the files
    string ParseJnk;
    const char *C = Files;
+   char *RealPath;
    for (;isspace(*C); C++);
    while (*C != 0)
    {   
@@ -679,10 +685,11 @@
       
       char Jnk[2];
       string OriginalPath = Directory + ParseJnk;
-      if (RealPath != 0 && readlink(OriginalPath.c_str(),Jnk,sizeof(Jnk)) != -1 &&
-	  realpath(OriginalPath.c_str(),RealPath) != 0)
+      if (readlink(OriginalPath.c_str(),Jnk,sizeof(Jnk)) != -1 &&
+	  (RealPath = realpath(OriginalPath.c_str(),NULL)) != 0)
       {
 	 string RP = RealPath;
+	 free(RealPath);
 	 if (Delink(RP,OriginalPath.c_str(),Stats.DeLinkBytes,St.st_size) == false)
 	    return false;
       }
diff -ur tmp/apt-0.7.25.1/ftparchive/writer.h apt-0.7.25.1/ftparchive/writer.h
--- tmp/apt-0.7.25.1/ftparchive/writer.h	2010-01-09 20:56:01.000000000 +0000
+++ apt-0.7.25.1/ftparchive/writer.h	2010-01-24 12:15:13.000000000 +0000
@@ -35,7 +35,6 @@
    protected:
    vector<string> Patterns;
    const char *OriginalPath;
-   char *RealPath;
    bool ErrorPrinted;
    
    // Stuff for the delinker
@@ -70,7 +69,6 @@
    bool SetExts(string Vals);
       
    FTWScanner();
-   virtual ~FTWScanner() {delete [] RealPath;};
 };
 
 class PackagesWriter : public FTWScanner

Reply to: