]> git.saurik.com Git - apt.git/commitdiff
avoid 416 response teardown binding to null pointer
authorDavid Kalnischkies <david@kalnischkies.de>
Tue, 5 Jul 2016 11:07:29 +0000 (13:07 +0200)
committerJulian Andres Klode <jak@debian.org>
Wed, 31 Aug 2016 11:49:37 +0000 (13:49 +0200)
methods/http.cc:640:13: runtime error: reference binding to null pointer
of type 'struct FileFd'

This reference is never used in the cases it has a nullptr, so the
practical difference is non-existent, but its a bug still.

Reported-By: gcc -fsanitize=undefined
(cherry picked from commit 4460551841d909d3ee9c1de00156ed3cdf8b1665)

methods/http.cc
methods/http.h
methods/https.h
methods/server.h

index 0c3803fbb3979d1635bc9478f2343d7e19fdfb59..46d90e2566608d3f71b59fec61a15d85b47d65df 100644 (file)
@@ -498,20 +498,22 @@ APT_PURE Hashes * HttpServerState::GetHashes()                            /*{{{*/
 }
                                                                        /*}}}*/
 // HttpServerState::Die - The server has closed the connection.                /*{{{*/
-bool HttpServerState::Die(FileFd &File)
+bool HttpServerState::Die(FileFd * const File)
 {
    unsigned int LErrno = errno;
 
    // Dump the buffer to the file
    if (State == ServerState::Data)
    {
+      if (File == nullptr)
+        return true;
       // on GNU/kFreeBSD, apt dies on /dev/null because non-blocking
       // can't be set
-      if (File.Name() != "/dev/null")
-        SetNonBlock(File.Fd(),false);
+      if (File->Name() != "/dev/null")
+        SetNonBlock(File->Fd(),false);
       while (In.WriteSpace() == true)
       {
-        if (In.Write(File.Fd()) == false)
+        if (In.Write(File->Fd()) == false)
            return _error->Errno("write",_("Error writing to the file"));
 
         // Done
@@ -630,7 +632,7 @@ bool HttpServerState::Go(bool ToFile, FileFd * const File)
    if (Res == 0)
    {
       _error->Error(_("Connection timed out"));
-      return Die(*File);
+      return Die(File);
    }
    
    // Handle server IO
@@ -638,14 +640,14 @@ bool HttpServerState::Go(bool ToFile, FileFd * const File)
    {
       errno = 0;
       if (In.Read(ServerFd) == false)
-        return Die(*File);
+        return Die(File);
    }
         
    if (ServerFd != -1 && FD_ISSET(ServerFd,&wfds))
    {
       errno = 0;
       if (Out.Write(ServerFd) == false)
-        return Die(*File);
+        return Die(File);
    }
 
    // Send data to the file
index 9e2b1da5caf3de0e56c0a7f6fa2c421b1421ab6c..e3d2a77ff1e59fb55e0eedc381f694272d684430 100644 (file)
@@ -113,7 +113,7 @@ struct HttpServerState: public ServerState
    virtual bool Close() APT_OVERRIDE;
    virtual bool InitHashes(HashStringList const &ExpectedHashes) APT_OVERRIDE;
    virtual Hashes * GetHashes() APT_OVERRIDE;
-   virtual bool Die(FileFd &File) APT_OVERRIDE;
+   virtual bool Die(FileFd * const File) APT_OVERRIDE;
    virtual bool Flush(FileFd * const File) APT_OVERRIDE;
    virtual bool Go(bool ToFile, FileFd * const File) APT_OVERRIDE;
 
index 4d50c5a040cdd1f62508c781876333f71f009446..7d49d9882de8e155f3545e4d53c4bcf8e0d9bc01 100644 (file)
@@ -47,7 +47,7 @@ class HttpsServerState : public ServerState
    virtual bool Close() APT_OVERRIDE { return false; }
    virtual bool InitHashes(HashStringList const &ExpectedHashes) APT_OVERRIDE;
    virtual Hashes * GetHashes() APT_OVERRIDE;
-   virtual bool Die(FileFd &/*File*/) APT_OVERRIDE { return false; }
+   virtual bool Die(FileFd * const /*File*/) APT_OVERRIDE { return false; }
    virtual bool Flush(FileFd * const /*File*/) APT_OVERRIDE { return false; }
    virtual bool Go(bool /*ToFile*/, FileFd * const /*File*/) APT_OVERRIDE { return false; }
 
index 3f6502432e5b11789913948cd37d93d8a3ccc32c..28c6851f1c07b6e62d792260e9a7ddad19723ae1 100644 (file)
@@ -98,7 +98,7 @@ struct ServerState
    virtual bool Close() = 0;
    virtual bool InitHashes(HashStringList const &ExpectedHashes) = 0;
    virtual Hashes * GetHashes() = 0;
-   virtual bool Die(FileFd &File) = 0;
+   virtual bool Die(FileFd * const File) = 0;
    virtual bool Flush(FileFd * const File) = 0;
    virtual bool Go(bool ToFile, FileFd * const File) = 0;