diff options
Diffstat (limited to 'methods')
-rw-r--r-- | methods/ftp.cc | 9 | ||||
-rw-r--r-- | methods/http.cc | 20 | ||||
-rw-r--r-- | methods/http.h | 11 | ||||
-rw-r--r-- | methods/https.h | 6 | ||||
-rw-r--r-- | methods/mirror.cc | 2 | ||||
-rw-r--r-- | methods/rsh.cc | 4 |
6 files changed, 24 insertions, 28 deletions
diff --git a/methods/ftp.cc b/methods/ftp.cc index ad8a7b828..d55ac1224 100644 --- a/methods/ftp.cc +++ b/methods/ftp.cc @@ -77,6 +77,7 @@ FTPConn::FTPConn(URI Srv) : Len(0), ServerFd(-1), DataFd(-1), { Debug = _config->FindB("Debug::Acquire::Ftp",false); PasvAddr = 0; + Buffer[0] = '\0'; } /*}}}*/ // FTPConn::~FTPConn - Destructor /*{{{*/ @@ -621,8 +622,7 @@ bool FTPConn::ExtGoPasv() } // Get a new passive address. - int Res; - if ((Res = getaddrinfo(IP.c_str(),PStr,&Hints,&PasvAddr)) != 0) + if (getaddrinfo(IP.c_str(),PStr,&Hints,&PasvAddr) != 0) return true; return true; @@ -720,14 +720,13 @@ bool FTPConn::CreateDataFd() DataListenFd = -1; // Get the information for a listening socket. - struct addrinfo *BindAddr = 0; + struct addrinfo *BindAddr = NULL; struct addrinfo Hints; memset(&Hints,0,sizeof(Hints)); Hints.ai_socktype = SOCK_STREAM; Hints.ai_flags |= AI_PASSIVE; Hints.ai_family = ((struct sockaddr *)&ServerAddr)->sa_family; - int Res; - if ((Res = getaddrinfo(0,"0",&Hints,&BindAddr)) != 0) + if (getaddrinfo(0,"0",&Hints,&BindAddr) != 0 || BindAddr == NULL) return _error->Error(_("getaddrinfo was unable to get a listening socket")); // Construct the socket diff --git a/methods/http.cc b/methods/http.cc index 2721b1224..d2e03cfbc 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -42,6 +42,7 @@ #include <stdio.h> #include <errno.h> #include <string.h> +#include <climits> #include <iostream> #include <map> @@ -534,10 +535,6 @@ bool ServerState::HeaderLine(string Line) if (Line.empty() == true) return true; - // The http server might be trying to do something evil. - if (Line.length() >= MAXLEN) - return _error->Error(_("Got a single header line over %u chars"),MAXLEN); - string::size_type Pos = Line.find(' '); if (Pos == string::npos || Pos+1 > Line.length()) { @@ -561,7 +558,7 @@ bool ServerState::HeaderLine(string Line) // Evil servers return no version if (Line[4] == '/') { - int const elements = sscanf(Line.c_str(),"HTTP/%u.%u %u%[^\n]",&Major,&Minor,&Result,Code); + int const elements = sscanf(Line.c_str(),"HTTP/%3u.%3u %3u%359[^\n]",&Major,&Minor,&Result,Code); if (elements == 3) { Code[0] = '\0'; @@ -575,7 +572,7 @@ bool ServerState::HeaderLine(string Line) { Major = 0; Minor = 9; - if (sscanf(Line.c_str(),"HTTP %u%[^\n]",&Result,Code) != 2) + if (sscanf(Line.c_str(),"HTTP %3u%359[^\n]",&Result,Code) != 2) return _error->Error(_("The HTTP server sent an invalid reply header")); } @@ -585,7 +582,7 @@ bool ServerState::HeaderLine(string Line) Persistent = false; else { - if (Major == 1 && Minor <= 0) + if (Major == 1 && Minor == 0) Persistent = false; else Persistent = true; @@ -603,9 +600,10 @@ bool ServerState::HeaderLine(string Line) // The length is already set from the Content-Range header if (StartPos != 0) return true; - - if (sscanf(Val.c_str(),"%llu",&Size) != 1) - return _error->Error(_("The HTTP server sent an invalid Content-Length header")); + + Size = strtoull(Val.c_str(), NULL, 10); + if (Size == ULLONG_MAX) + return _error->Errno("HeaderLine", _("The HTTP server sent an invalid Content-Length header")); return true; } @@ -1329,7 +1327,7 @@ int HttpMethod::Loop() after the same URI is seen twice in a queue item. */ StringVector &R = Redirected[Queue->DestFile]; bool StopRedirects = false; - if (R.size() == 0) + if (R.empty() == true) R.push_back(Queue->Uri); else if (R[0] == "STOP" || R.size() > 10) StopRedirects = true; diff --git a/methods/http.h b/methods/http.h index c73d4df5c..7a3ccda54 100644 --- a/methods/http.h +++ b/methods/http.h @@ -11,8 +11,6 @@ #ifndef APT_HTTP_H #define APT_HTTP_H -#define MAXLEN 360 - #include <apt-pkg/strutl.h> #include <string> @@ -92,7 +90,7 @@ struct ServerState unsigned int Major; unsigned int Minor; unsigned int Result; - char Code[MAXLEN]; + char Code[360]; // These are some statistics from the last parsed header lines unsigned long long Size; @@ -117,9 +115,10 @@ struct ServerState bool HeaderLine(std::string Line); bool Comp(URI Other) const {return Other.Host == ServerName.Host && Other.Port == ServerName.Port;}; - void Reset() {Major = 0; Minor = 0; Result = 0; Size = 0; StartPos = 0; - Encoding = Closes; time(&Date); ServerFd = -1; - Pipeline = true;}; + void Reset() {Major = 0; Minor = 0; Result = 0; Code[0] = '\0'; Size = 0; + StartPos = 0; Encoding = Closes; time(&Date); HaveContent = false; + State = Header; Persistent = false; ServerFd = -1; + Pipeline = true;}; /** \brief Result of the header acquire */ enum RunHeadersResult { diff --git a/methods/https.h b/methods/https.h index b7adeb880..b1961a870 100644 --- a/methods/https.h +++ b/methods/https.h @@ -8,10 +8,8 @@ ##################################################################### */ /*}}}*/ -#ifndef APT_HTTP_H -#define APT_HTTP_H - -#define MAXLEN 360 +#ifndef APT_HTTPS_H +#define APT_HTTPS_H #include <iostream> #include <curl/curl.h> diff --git a/methods/mirror.cc b/methods/mirror.cc index 3d5983efa..3b2ab8ede 100644 --- a/methods/mirror.cc +++ b/methods/mirror.cc @@ -147,7 +147,7 @@ bool MirrorMethod::DownloadMirrorFile(string mirror_uri_str) // append all architectures std::vector<std::string> vec = APT::Configuration::getArchitectures(); for (std::vector<std::string>::const_iterator I = vec.begin(); - I != vec.end(); I++) + I != vec.end(); ++I) if (I == vec.begin()) fetch += "?arch" + (*I); else diff --git a/methods/rsh.cc b/methods/rsh.cc index d249ae961..fb3782314 100644 --- a/methods/rsh.cc +++ b/methods/rsh.cc @@ -42,7 +42,9 @@ int RSHMethod::FailFd = -1; // --------------------------------------------------------------------- /* */ RSHConn::RSHConn(URI Srv) : Len(0), WriteFd(-1), ReadFd(-1), - ServerName(Srv), Process(-1) {} + ServerName(Srv), Process(-1) { + Buffer[0] = '\0'; +} /*}}}*/ // RSHConn::RSHConn - Destructor /*{{{*/ // --------------------------------------------------------------------- |