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

Bug#89172: marked as done (apt: [PATCH] use library instead of char[])



Your message dated Sun, 11 Mar 2001 15:11:42 -0700 (MST)
with message-id <[🔎] Pine.LNX.3.96.1010311151014.6894d-100000@wakko.deltatee.com>
and subject line Bug#89172: apt: [PATCH] use library instead of char[]
has caused the attached Bug report to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what I am
talking about this indicates a serious mail system misconfiguration
somewhere.  Please contact me immediately.)

Darren Benham
(administrator, Debian Bugs database)

--------------------------------------
Received: (at submit) by bugs.debian.org; 10 Mar 2001 17:20:48 +0000
>From gohmandj@mrs.umn.edu Sat Mar 10 11:20:48 2001
Return-path: <gohmandj@mrs.umn.edu>
Received: from rn082040.mrs.umn.edu [::ffff:146.57.82.40] 
	by master.debian.org with esmtp (Exim 3.12 1 (Debian))
	id 14bn2t-0002fG-00; Sat, 10 Mar 2001 11:20:47 -0600
Received: from normal by rn082040.mrs.umn.edu with local (Exim 3.22 #1 (Debian))
	id 14bn2s-0001rN-00; Sat, 10 Mar 2001 11:20:46 -0600
From: Normal User <gohmandj@mrs.umn.edu>
Subject: apt: [PATCH] use library instead of char[]
To: submit@bugs.debian.org
X-Mailer: bug 3.3.9
Message-Id: <[🔎] E14bn2s-0001rN-00@rn082040.mrs.umn.edu>
Sender: Normal User <normal@rn082040>
Date: Sat, 10 Mar 2001 11:20:46 -0600
Delivered-To: submit@bugs.debian.org

Package: apt
Version: 0.5.3
Severity: wishlist

The following is a patch (against the current CVS) that replaces a few
uses of sprintf and strcat with the C++ string and ostringstream classes
(safer, more flexible, type-safe, blah blah...). If you're interested in
accepting this type of patch, let me know, and I'll continue to make them.

diff -ur apt.orig/cmdline/indexcopy.cc apt/cmdline/indexcopy.cc
--- apt.orig/cmdline/indexcopy.cc	Tue Feb 20 01:03:17 2001
+++ apt/cmdline/indexcopy.cc	Sat Mar 10 11:00:23 2001
@@ -112,9 +112,11 @@
 	 return false;
       
       // Open the output file
-      char S[400];
-      sprintf(S,"cdrom:[%s]/%s%s",Name.c_str(),(*I).c_str() + CDROM.length(),
-	      GetFileName());
+      string S = "cdrom:[";
+      S += Name;
+      S += "]/";
+      S += I->substr(CDROM.length());
+      S += GetFileName();
       string TargetF = _config->FindDir("Dir::State::lists") + "partial/";
       TargetF += URItoFileName(S);
       if (_config->FindB("APT::CDROM::NoAct",false) == true)
@@ -229,7 +231,11 @@
 	    return _error->Errno("rename","Failed to rename");
 
 	 // Copy the release file
-	 sprintf(S,"cdrom:[%s]/%sRelease",Name.c_str(),(*I).c_str() + CDROM.length());
+	 S = "cdrom:[";
+	 S += Name;
+	 S += "]/";
+	 S += I->substr(CDROM.length());
+	 S += "Release";
 	 string TargetF = _config->FindDir("Dir::State::lists") + "partial/";
 	 TargetF += URItoFileName(S);
 	 if (FileExists(*I + "Release") == true)
@@ -380,8 +386,8 @@
  */
 void IndexCopy::ConvertToSourceList(string CD,string &Path)
 {
-   char S[300];
-   sprintf(S,"binary-%s",_config->Find("Apt::Architecture").c_str());
+   string S = "binary-";
+   S += _config->Find("Apt::Architecture");
    
    // Strip the cdrom base path
    Path = string(Path,CD.length());
diff -ur apt.orig/methods/http.cc apt/methods/http.cc
--- apt.orig/methods/http.cc	Tue Mar  6 01:15:29 2001
+++ apt/methods/http.cc	Sat Mar 10 11:11:00 2001
@@ -30,6 +30,8 @@
 #include <apt-pkg/error.h>
 #include <apt-pkg/hashes.h>
 
+#include <sstream>
+
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <utime.h>
@@ -47,6 +49,8 @@
 
 									/*}}}*/
 
+using namespace std;
+
 string HttpMethod::FailFile;
 int HttpMethod::FailFd = -1;
 time_t HttpMethod::FailTime = 0;
@@ -599,18 +603,14 @@
    URI Uri = Itm->Uri;
 
    // The HTTP server expects a hostname with a trailing :port
-   char Buf[1000];
-   string ProperHost = Uri.Host;
+   ostringstream ProperHost(Uri.Host);
    if (Uri.Port != 0)
    {
-      sprintf(Buf,":%u",Uri.Port);
-      ProperHost += Buf;
+      ProperHost << ":" << Uri.Port;
    }   
       
-   // Just in case.
-   if (Itm->Uri.length() >= sizeof(Buf))
-       abort();
-       
+   ostringstream Req;
+
    /* Build the request. We include a keep-alive header only for non-proxy
       requests. This is to tweak old http/1.0 servers that do support keep-alive
       but not HTTP/1.1 automatic keep-alive. Doing this with a proxy server 
@@ -618,64 +618,68 @@
       pass it on, HTTP/1.1 says the connection should default to keep alive
       and we expect the proxy to do this */
    if (Proxy.empty() == true)
-      sprintf(Buf,"GET %s HTTP/1.1\r\nHost: %s\r\nConnection: keep-alive\r\n",
-	      QuoteString(Uri.Path,"~").c_str(),ProperHost.c_str());
+      Req << "GET " << QuoteString(Uri.Path,"~") << " HTTP/1.1\r\nHost: "
+          << ProperHost.str() << "\r\nConnection: keep-alive\r\n";
    else
    {
       /* Generate a cache control header if necessary. We place a max
        	 cache age on index files, optionally set a no-cache directive
        	 and a no-store directive for archives. */
-      sprintf(Buf,"GET %s HTTP/1.1\r\nHost: %s\r\n",
-	      Itm->Uri.c_str(),ProperHost.c_str());
+      Req << "GET " << Itm->Uri << " HTTP/1.1\r\nHost: "
+          << ProperHost.str() << "\r\n";
       if (_config->FindB("Acquire::http::No-Cache",false) == true)
-	 strcat(Buf,"Cache-Control: no-cache\r\nPragma: no-cache\r\n");
+        Req << "Cache-Control: no-cache\r\nPragma: no-cache\r\n";
       else
       {
 	 if (Itm->IndexFile == true)
-	    sprintf(Buf+strlen(Buf),"Cache-Control: max-age=%u\r\n",
-		    _config->FindI("Acquire::http::Max-Age",60*60*24));
+           Req << "Cache-Control: max-age="
+               << _config->FindI("Acquire::http::Max-Age",60*60*24)
+               << "\r\n";
 	 else
 	 {
 	    if (_config->FindB("Acquire::http::No-Store",false) == true)
-	       strcat(Buf,"Cache-Control: no-store\r\n");
+              Req << "Cache-Control: no-store\r\n";
 	 }	 
       }
    }
    
-   string Req = Buf;
-
    // Check for a partial file
    struct stat SBuf;
    if (stat(Itm->DestFile.c_str(),&SBuf) >= 0 && SBuf.st_size > 0)
    {
       // In this case we send an if-range query with a range header
-      sprintf(Buf,"Range: bytes=%li-\r\nIf-Range: %s\r\n",(long)SBuf.st_size - 1,
-	      TimeRFC1123(SBuf.st_mtime).c_str());
-      Req += Buf;
+      Req << "Range: bytes="
+          << SBuf.st_size - 1
+          << "-\r\nIf-Range: "
+          << TimeRFC1123(SBuf.st_mtime)
+          << "\r\n";
    }
    else
    {
       if (Itm->LastModified != 0)
       {
-	 sprintf(Buf,"If-Modified-Since: %s\r\n",TimeRFC1123(Itm->LastModified).c_str());
-	 Req += Buf;
+        Req << "If-Modified-Since: "
+            << TimeRFC1123(Itm->LastModified)
+            << "\r\n";
       }
    }
 
    if (Proxy.User.empty() == false || Proxy.Password.empty() == false)
-      Req += string("Proxy-Authorization: Basic ") + 
-          Base64Encode(Proxy.User + ":" + Proxy.Password) + "\r\n";
+      Req << "Proxy-Authorization: Basic " 
+          << Base64Encode(Proxy.User + ":" + Proxy.Password)
+          << "\r\n";
 
    if (Uri.User.empty() == false || Uri.Password.empty() == false)
-      Req += string("Authorization: Basic ") + 
-          Base64Encode(Uri.User + ":" + Uri.Password) + "\r\n";
+      Req << "Authorization: Basic " 
+          << Base64Encode(Uri.User + ":" + Uri.Password)
+          << "\r\n";
    
-   Req += "User-Agent: Debian APT-HTTP/1.3\r\n\r\n";
+   Req << "User-Agent: Debian APT-HTTP/1.3\r\n\r\n";
    
    if (Debug == true)
-      cerr << Req << endl;
+      cerr << Req.str() << endl;
 
-   Out.Read(Req);
+   Out.Read(Req.str());
 }
 									/*}}}*/
 // HttpMethod::Go - Run a single loop					/*{{{*/

-- System Information
Debian Release: testing/unstable

Versions of the packages apt depends on:
ii  libc6          2.2.2-1        GNU C Library: Shared libraries and Timezone
ii  libstdc++2.10- 2.95.3-6       The GNU stdc++ library

---------------------------------------
Received: (at 89172-done) by bugs.debian.org; 11 Mar 2001 22:11:45 +0000
>From jgg@debian.org Sun Mar 11 16:11:45 2001
Return-path: <jgg@debian.org>
Received: from crack-ext.ab.videon.ca [206.75.216.33] 
	by master.debian.org with smtp (Exim 3.12 1 (Debian))
	id 14cE41-0007DN-00; Sun, 11 Mar 2001 16:11:45 -0600
Received: (qmail 11706 invoked from network); 11 Mar 2001 22:11:43 -0000
Received: from unknown (HELO wakko.deltatee.com) ([24.108.173.63]) (envelope-sender <jgg@debian.org>)
          by crack-ext.ab.videon.ca (qmail-ldap-1.03) with SMTP
          for <gohmandj@mrs.umn.edu>; 11 Mar 2001 22:11:43 -0000
Received: from localhost
	([127.0.0.1] helo=wakko.deltatee.com ident=jgg)
	by wakko.deltatee.com with smtp (Exim 3.16 #1 (Debian))
	id 14cE3y-0006jP-00; Sun, 11 Mar 2001 15:11:43 -0700
Date: Sun, 11 Mar 2001 15:11:42 -0700 (MST)
From: Jason Gunthorpe <jgg@debian.org>
X-Sender: jgg@wakko.deltatee.com
To: Normal User <gohmandj@mrs.umn.edu>, 89172-done@bugs.debian.org
cc: APT Development Team <deity@lists.debian.org>
Subject: Re: Bug#89172: apt: [PATCH] use library instead of char[]
In-Reply-To: <[🔎] E14bn2s-0001rN-00@rn082040.mrs.umn.edu>
Message-ID: <[🔎] Pine.LNX.3.96.1010311151014.6894d-100000@wakko.deltatee.com>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Delivered-To: 89172-done@bugs.debian.org


On Sat, 10 Mar 2001, Normal User wrote:

> The following is a patch (against the current CVS) that replaces a few
> uses of sprintf and strcat with the C++ string and ostringstream classes
> (safer, more flexible, type-safe, blah blah...). If you're interested in
> accepting this type of patch, let me know, and I'll continue to make them.

Now I remember why I never did this in the first place:

wakko{jgg}/usr/include#find -type f | xargs grep -i ostringstream
./g++-3/stl_rope.h:// behave a little like basic_ostringstream<sequence::value_type> and a

There are no stringstreams in potato and before's g++ :<

So, despite how nice this is, no can do.

Sorry,
Jason



Reply to: