|
From: <arn...@us...> - 2006-08-31 07:46:44
|
Revision: 643
http://svn.sourceforge.net/dcplusplus/?rev=643&view=rev
Author: arnetheduck
Date: 2006-08-31 00:46:12 -0700 (Thu, 31 Aug 2006)
Log Message:
-----------
Patches
Modified Paths:
--------------
dcplusplus/trunk/changelog.txt
dcplusplus/trunk/client/AdcCommand.h
dcplusplus/trunk/client/BufferedSocket.cpp
dcplusplus/trunk/client/Client.h
dcplusplus/trunk/client/ClientManager.cpp
dcplusplus/trunk/client/DCPlusPlus.h
dcplusplus/trunk/client/DirectoryListing.cpp
dcplusplus/trunk/client/DownloadManager.cpp
dcplusplus/trunk/client/FilteredFile.h
dcplusplus/trunk/client/NmdcHub.cpp
dcplusplus/trunk/client/QueueManager.cpp
dcplusplus/trunk/client/ShareManager.cpp
dcplusplus/trunk/client/Socket.cpp
dcplusplus/trunk/client/Socket.h
dcplusplus/trunk/client/Util.cpp
dcplusplus/trunk/client/Util.h
dcplusplus/trunk/client/stdinc.h
dcplusplus/trunk/windows/AboutDlg.h
dcplusplus/trunk/windows/FlatTabCtrl.h
Modified: dcplusplus/trunk/changelog.txt
===================================================================
--- dcplusplus/trunk/changelog.txt 2006-07-23 12:21:17 UTC (rev 642)
+++ dcplusplus/trunk/changelog.txt 2006-08-31 07:46:12 UTC (rev 643)
@@ -7,6 +7,14 @@
* [bug 395] Fixed password being blanked
* [bug 419] Allowed changing case only when moving file in queue
* [bug 736] Fixed escaping of menu items
+* [bug 1013] Fixed gcc warnings (thanks steven sheehy)
+* [bug 1023] Fixed some large stack allocations (thanks steven sheehy)
+* [bug 1026] Fixed some potential buffer overflows (thanks steven sheehy)
+* [bug 1027] Improved unix socket support (thanks steven sheehy)
+* [bug 1028] Improved big endian support (thanks steven sheehy)
+* [bug 1029] Fixed BSD compile issue (thanks steven sheehy)
+* [bug 1031] Fixed a crash after closing hub window (thanks bigmuscle/pothead)
+* [bug 1032] Fixed certificates help (thanks pothead)
-- 0.694 2006-07-10 --
* Fixed crash in certificates page
Modified: dcplusplus/trunk/client/AdcCommand.h
===================================================================
--- dcplusplus/trunk/client/AdcCommand.h 2006-07-23 12:21:17 UTC (rev 642)
+++ dcplusplus/trunk/client/AdcCommand.h 2006-08-31 07:46:12 UTC (rev 643)
@@ -79,7 +79,11 @@
static const char TYPE_HUB = 'H';
static const char TYPE_UDP = 'U';
+#if defined(_WIN32) || defined(__i386__) || defined(__x86_64__) || defined(__alpha)
#define C(n, a, b, c) static const u_int32_t CMD_##n = (((u_int32_t)a) | (((u_int32_t)b)<<8) | (((u_int32_t)c)<<16)); typedef Type<CMD_##n> n
+#else
+#define C(n, a, b, c) static const u_int32_t CMD_##n = ((((u_int32_t)a)<<24) | (((u_int32_t)b)<<16) | (((u_int32_t)c)<<8)); typedef Type<CMD_##n> n
+#endif
// Base commands
C(SUP, 'S','U','P');
C(STA, 'S','T','A');
Modified: dcplusplus/trunk/client/BufferedSocket.cpp
===================================================================
--- dcplusplus/trunk/client/BufferedSocket.cpp 2006-07-23 12:21:17 UTC (rev 642)
+++ dcplusplus/trunk/client/BufferedSocket.cpp 2006-08-31 07:46:12 UTC (rev 643)
@@ -33,8 +33,8 @@
#define POLL_TIMEOUT 250
BufferedSocket::BufferedSocket(char aSeparator) throw() :
-separator(aSeparator), mode(MODE_LINE),
-dataBytes(0), rollback(0), failed(false), sock(0), disconnecting(false), filterIn(NULL)
+separator(aSeparator), mode(MODE_LINE), filterIn(NULL),
+dataBytes(0), rollback(0), failed(false), sock(0), disconnecting(false)
{
Thread::safeInc(sockets);
}
@@ -69,6 +69,8 @@
case MODE_ZPIPE:
filterIn = new UnZFilter;
break;
+ case MODE_DATA:
+ break;
}
}
@@ -423,6 +425,8 @@
break;
case SHUTDOWN:
return false;
+ case ACCEPTED:
+ break;
}
delete p.second;
Modified: dcplusplus/trunk/client/Client.h
===================================================================
--- dcplusplus/trunk/client/Client.h 2006-07-23 12:21:17 UTC (rev 642)
+++ dcplusplus/trunk/client/Client.h 2006-08-31 07:46:12 UTC (rev 643)
@@ -34,6 +34,7 @@
class ClientListener
{
public:
+ virtual ~ClientListener() { }
template<int I> struct X { enum { TYPE = I }; };
typedef X<0> Connecting;
@@ -114,7 +115,7 @@
static string getCounts() {
char buf[128];
- return string(buf, sprintf(buf, "%ld/%ld/%ld", counts.normal, counts.registered, counts.op));
+ return string(buf, snprintf(buf, sizeof(buf), "%ld/%ld/%ld", counts.normal, counts.registered, counts.op));
}
StringMap& escapeParams(StringMap& sm) {
Modified: dcplusplus/trunk/client/ClientManager.cpp
===================================================================
--- dcplusplus/trunk/client/ClientManager.cpp 2006-07-23 12:21:17 UTC (rev 642)
+++ dcplusplus/trunk/client/ClientManager.cpp 2006-08-31 07:46:12 UTC (rev 643)
@@ -62,7 +62,7 @@
{
Lock l(cs);
- clients.erase(remove(clients.begin(), clients.end(), aClient), clients.end());
+ clients.remove(aClient);
}
delete aClient;
}
Modified: dcplusplus/trunk/client/DCPlusPlus.h
===================================================================
--- dcplusplus/trunk/client/DCPlusPlus.h 2006-07-23 12:21:17 UTC (rev 642)
+++ dcplusplus/trunk/client/DCPlusPlus.h 2006-08-31 07:46:12 UTC (rev 643)
@@ -41,6 +41,10 @@
va_end(args);
}
+#ifdef _WIN32
+#define snprintf _snprintf
+#endif
+
#define dcdebug debugTrace
#ifdef _WIN32
#define dcassert(exp) \
Modified: dcplusplus/trunk/client/DirectoryListing.cpp
===================================================================
--- dcplusplus/trunk/client/DirectoryListing.cpp 2006-07-23 12:21:17 UTC (rev 642)
+++ dcplusplus/trunk/client/DirectoryListing.cpp 2006-08-31 07:46:12 UTC (rev 643)
@@ -95,7 +95,7 @@
::File ff(name, ::File::READ, ::File::OPEN);
FilteredInputStream<UnBZFilter, false> f(&ff);
const size_t BUF_SIZE = 64*1024;
- char buf[BUF_SIZE];
+ AutoArray<char> buf(BUF_SIZE);
size_t len;
size_t bytesRead = 0;
for(;;) {
@@ -110,7 +110,7 @@
}
} else if(Util::stricmp(ext, ".xml") == 0) {
int64_t sz = ::File::getSize(name);
- if(sz == -1 || sz >= txt.max_size())
+ if(sz == -1 || sz >= static_cast<int64_t>(txt.max_size()))
throw(FileException(CSTRING(FILE_NOT_AVAILABLE)));
txt.resize((size_t) sz);
size_t n = txt.length();
Modified: dcplusplus/trunk/client/DownloadManager.cpp
===================================================================
--- dcplusplus/trunk/client/DownloadManager.cpp 2006-07-23 12:21:17 UTC (rev 642)
+++ dcplusplus/trunk/client/DownloadManager.cpp 2006-08-31 07:46:12 UTC (rev 643)
@@ -117,7 +117,7 @@
bytesDownloaded / timeElapsed * 1000 < (u_int32_t)SETTING(AUTODROP_SPEED) : false;
bool onlineSourcesOk = (*i)->isSet(Download::FLAG_USER_LIST) ?
true : QueueManager::getInstance()->countOnlineSources((*i)->getTarget()) >= SETTING(AUTODROP_MINSOURCES);
- bool filesizeOk = !((*i)->isSet(Download::FLAG_USER_LIST)) && (*i)->getSize() >= ((size_t)SETTING(AUTODROP_FILESIZE)) * 1024;
+ bool filesizeOk = !((*i)->isSet(Download::FLAG_USER_LIST)) && (*i)->getSize() >= ((int64_t)SETTING(AUTODROP_FILESIZE)) * 1024;
bool dropIt = ((*i)->isSet(Download::FLAG_USER_LIST) && BOOLSETTING(AUTODROP_FILELISTS)) ||
(filesizeOk && BOOLSETTING(AUTODROP_ALL));
if(speedTooLow && onlineSourcesOk && dropIt) {
Modified: dcplusplus/trunk/client/FilteredFile.h
===================================================================
--- dcplusplus/trunk/client/FilteredFile.h 2006-07-23 12:21:17 UTC (rev 642)
+++ dcplusplus/trunk/client/FilteredFile.h 2006-08-31 07:46:12 UTC (rev 643)
@@ -24,6 +24,7 @@
#endif // _MSC_VER > 1000
#include "Streams.h"
+#include "Util.h"
template<class Filter, bool managed>
class CalcOutputStream : public OutputStream {
@@ -72,7 +73,7 @@
public:
using OutputStream::write;
- FilteredOutputStream(OutputStream* aFile) : f(aFile), flushed(false) { }
+ FilteredOutputStream(OutputStream* aFile) : f(aFile), buf(BUF_SIZE), flushed(false) { }
~FilteredOutputStream() throw() { if(manage) delete f; }
size_t flush() throw(Exception) {
@@ -123,19 +124,19 @@
}
private:
- enum { BUF_SIZE = 64*1024 };
+ static const size_t BUF_SIZE = 64*1024;
OutputStream* f;
Filter filter;
- u_int8_t buf[BUF_SIZE];
+ AutoArray<u_int8_t> buf;
bool flushed;
};
template<class Filter, bool managed>
class FilteredInputStream : public InputStream {
public:
- FilteredInputStream(InputStream* aFile) : f(aFile), pos(0), valid(0), more(true) { }
+ FilteredInputStream(InputStream* aFile) : f(aFile), buf(BUF_SIZE), pos(0), valid(0), more(true) { }
virtual ~FilteredInputStream() throw() { if(managed) delete f; }
/**
@@ -173,11 +174,11 @@
}
private:
- enum { BUF_SIZE = 64*1024 };
+ static const size_t BUF_SIZE = 64*1024;
InputStream* f;
Filter filter;
- u_int8_t buf[BUF_SIZE];
+ AutoArray<u_int8_t> buf;
size_t pos;
size_t valid;
bool more;
Modified: dcplusplus/trunk/client/NmdcHub.cpp
===================================================================
--- dcplusplus/trunk/client/NmdcHub.cpp 2006-07-23 12:21:17 UTC (rev 642)
+++ dcplusplus/trunk/client/NmdcHub.cpp 2006-08-31 07:46:12 UTC (rev 643)
@@ -800,13 +800,16 @@
tmp[i] = '$';
}
int chars = 0;
+ size_t BUF_SIZE;
if(ClientManager::getInstance()->isActive()) {
string x = ClientManager::getInstance()->getCachedIp();
- buf = new char[x.length() + aString.length() + 64];
- chars = sprintf(buf, "$Search %s:%d %c?%c?%s?%d?%s|", x.c_str(), (int)SearchManager::getInstance()->getPort(), c1, c2, Util::toString(aSize).c_str(), aFileType+1, tmp.c_str());
+ BUF_SIZE = x.length() + aString.length() + 64;
+ buf = new char[BUF_SIZE];
+ chars = snprintf(buf, BUF_SIZE, "$Search %s:%d %c?%c?%s?%d?%s|", x.c_str(), (int)SearchManager::getInstance()->getPort(), c1, c2, Util::toString(aSize).c_str(), aFileType+1, tmp.c_str());
} else {
- buf = new char[getMyNick().length() + aString.length() + 64];
- chars = sprintf(buf, "$Search Hub:%s %c?%c?%s?%d?%s|", toAcp(getMyNick()).c_str(), c1, c2, Util::toString(aSize).c_str(), aFileType+1, tmp.c_str());
+ BUF_SIZE = getMyNick().length() + aString.length() + 64;
+ buf = new char[BUF_SIZE];
+ chars = snprintf(buf, BUF_SIZE, "$Search Hub:%s %c?%c?%s?%d?%s|", toAcp(getMyNick()).c_str(), c1, c2, Util::toString(aSize).c_str(), aFileType+1, tmp.c_str());
}
send(buf, chars);
}
Modified: dcplusplus/trunk/client/QueueManager.cpp
===================================================================
--- dcplusplus/trunk/client/QueueManager.cpp 2006-07-23 12:21:17 UTC (rev 642)
+++ dcplusplus/trunk/client/QueueManager.cpp 2006-08-31 07:46:12 UTC (rev 643)
@@ -939,8 +939,9 @@
}
}
if(flags & QueueItem::FLAG_MATCH_QUEUE) {
- AutoArray<char> tmp(STRING(MATCHED_FILES).size() + 16);
- sprintf(tmp, CSTRING(MATCHED_FILES), matchListing(dirList));
+ const size_t BUF_SIZE = STRING(MATCHED_FILES).size() + 16;
+ AutoArray<char> tmp(BUF_SIZE);
+ snprintf(tmp, BUF_SIZE, CSTRING(MATCHED_FILES), matchListing(dirList));
LogManager::getInstance()->message(Util::toString(ClientManager::getInstance()->getNicks(user->getCID())) + ": " + string(tmp));
}
}
Modified: dcplusplus/trunk/client/ShareManager.cpp
===================================================================
--- dcplusplus/trunk/client/ShareManager.cpp 2006-07-23 12:21:17 UTC (rev 642)
+++ dcplusplus/trunk/client/ShareManager.cpp 2006-08-31 07:46:12 UTC (rev 643)
@@ -339,7 +339,7 @@
::File ff(Util::getConfigPath() + "files.xml.bz2", ::File::READ, ::File::OPEN);
FilteredInputStream<UnBZFilter, false> f(&ff);
const size_t BUF_SIZE = 64*1024;
- char buf[BUF_SIZE];
+ AutoArray<char> buf(BUF_SIZE);
size_t len;
for(;;) {
size_t n = BUF_SIZE;
Modified: dcplusplus/trunk/client/Socket.cpp
===================================================================
--- dcplusplus/trunk/client/Socket.cpp 2006-07-23 12:21:17 UTC (rev 642)
+++ dcplusplus/trunk/client/Socket.cpp 2006-08-31 07:46:12 UTC (rev 643)
@@ -52,7 +52,7 @@
if(msg.empty())
{
char tmp[64];
- sprintf(tmp, CSTRING(UNKNOWN_ERROR), aError);
+ snprintf(tmp, sizeof(tmp), CSTRING(UNKNOWN_ERROR), aError);
msg = tmp;
}
return msg;
Modified: dcplusplus/trunk/client/Socket.h
===================================================================
--- dcplusplus/trunk/client/Socket.h 2006-07-23 12:21:17 UTC (rev 642)
+++ dcplusplus/trunk/client/Socket.h 2006-08-31 07:46:12 UTC (rev 643)
@@ -236,7 +236,7 @@
static int check(int ret, bool blockOk = false) {
if(ret == -1) {
int error = getLastError();
- if(blockOk && (error == EWOULDBLOCK || error == ENOBUFS || error == EINPROGRESS) ) {
+ if(blockOk && (error == EWOULDBLOCK || error == ENOBUFS || error == EINPROGRESS || error == EAGAIN) ) {
return -1;
} else {
throw SocketException(error);
Modified: dcplusplus/trunk/client/Util.cpp
===================================================================
--- dcplusplus/trunk/client/Util.cpp 2006-07-23 12:21:17 UTC (rev 642)
+++ dcplusplus/trunk/client/Util.cpp 2006-08-31 07:46:12 UTC (rev 643)
@@ -338,17 +338,17 @@
string Util::formatBytes(int64_t aBytes) {
char buf[64];
if(aBytes < 1024) {
- sprintf(buf, "%d %s", (int)(aBytes&0xffffffff), CSTRING(B));
+ snprintf(buf, sizeof(buf), "%d %s", (int)(aBytes&0xffffffff), CSTRING(B));
} else if(aBytes < 1024*1024) {
- sprintf(buf, "%.02f %s", (double)aBytes/(1024.0), CSTRING(KiB));
+ snprintf(buf, sizeof(buf), "%.02f %s", (double)aBytes/(1024.0), CSTRING(KiB));
} else if(aBytes < 1024*1024*1024) {
- sprintf(buf, "%.02f %s", (double)aBytes/(1024.0*1024.0), CSTRING(MiB));
+ snprintf(buf, sizeof(buf), "%.02f %s", (double)aBytes/(1024.0*1024.0), CSTRING(MiB));
} else if(aBytes < (int64_t)1024*1024*1024*1024) {
- sprintf(buf, "%.02f %s", (double)aBytes/(1024.0*1024.0*1024.0), CSTRING(GiB));
+ snprintf(buf, sizeof(buf), "%.02f %s", (double)aBytes/(1024.0*1024.0*1024.0), CSTRING(GiB));
} else if(aBytes < (int64_t)1024*1024*1024*1024*1024) {
- sprintf(buf, "%.02f %s", (double)aBytes/(1024.0*1024.0*1024.0*1024.0), CSTRING(TiB));
+ snprintf(buf, sizeof(buf), "%.02f %s", (double)aBytes/(1024.0*1024.0*1024.0*1024.0), CSTRING(TiB));
} else {
- sprintf(buf, "%.02f %s", (double)aBytes/(1024.0*1024.0*1024.0*1024.0*1024.0), CSTRING(PIB));
+ snprintf(buf, sizeof(buf), "%.02f %s", (double)aBytes/(1024.0*1024.0*1024.0*1024.0*1024.0), CSTRING(PIB));
}
return buf;
@@ -380,9 +380,8 @@
return Text::fromT(buf);
#else
char buf[64];
- sprintf(buf, "%'lld", aBytes);
- sprintf(buf, "%s %s", buf, CSTRING(B));
- return buf;
+ snprintf(buf, sizeof(buf), "%'lld", aBytes);
+ return string(buf) + STRING(B);
#endif
}
Modified: dcplusplus/trunk/client/Util.h
===================================================================
--- dcplusplus/trunk/client/Util.h 2006-07-23 12:21:17 UTC (rev 642)
+++ dcplusplus/trunk/client/Util.h 2006-08-31 07:46:12 UTC (rev 643)
@@ -326,7 +326,7 @@
static string formatSeconds(int64_t aSec) {
char buf[64];
- sprintf(buf, "%01lu:%02d:%02d", (unsigned long)(aSec / (60*60)), (int)((aSec / 60) % 60), (int)(aSec % 60));
+ snprintf(buf, sizeof(buf), "%01lu:%02d:%02d", (unsigned long)(aSec / (60*60)), (int)((aSec / 60) % 60), (int)(aSec % 60));
return buf;
}
@@ -369,55 +369,55 @@
static string toString(short val) {
char buf[8];
- sprintf(buf, "%d", (int)val);
+ snprintf(buf, sizeof(buf), "%d", (int)val);
return buf;
}
static string toString(unsigned short val) {
char buf[8];
- sprintf(buf, "%u", (unsigned int)val);
+ snprintf(buf, sizeof(buf), "%u", (unsigned int)val);
return buf;
}
static string toString(int val) {
char buf[16];
- sprintf(buf, "%d", val);
+ snprintf(buf, sizeof(buf), "%d", val);
return buf;
}
static string toString(unsigned int val) {
char buf[16];
- sprintf(buf, "%u", val);
+ snprintf(buf, sizeof(buf), "%u", val);
return buf;
}
static string toString(long val) {
char buf[32];
- sprintf(buf, "%ld", val);
+ snprintf(buf, sizeof(buf), "%ld", val);
return buf;
}
static string toString(unsigned long val) {
char buf[32];
- sprintf(buf, "%lu", val);
+ snprintf(buf, sizeof(buf), "%lu", val);
return buf;
}
static string toString(long long val) {
char buf[32];
#ifdef _MSC_VER
- sprintf(buf, "%I64d", val);
+ snprintf(buf, sizeof(buf), "%I64d", val);
#else
- sprintf(buf, "%lld", val);
+ snprintf(buf, sizeof(buf), "%lld", val);
#endif
return buf;
}
static string toString(unsigned long long val) {
char buf[32];
#ifdef _MSC_VER
- sprintf(buf, "%I64u", val);
+ snprintf(buf, sizeof(buf), "%I64u", val);
#else
- sprintf(buf, "%llu", val);
+ snprintf(buf, sizeof(buf), "%llu", val);
#endif
return buf;
}
static string toString(double val) {
char buf[16];
- sprintf(buf, "%0.2f", val);
+ snprintf(buf, sizeof(buf), "%0.2f", val);
return buf;
}
@@ -437,7 +437,7 @@
static string toHexEscape(char val) {
char buf[sizeof(int)*2+1+1];
- sprintf(buf, "%%%X", val&0x0FF);
+ snprintf(buf, sizeof(buf), "%%%X", val&0x0FF);
return buf;
}
static char fromHexEscape(const string aString) {
Modified: dcplusplus/trunk/client/stdinc.h
===================================================================
--- dcplusplus/trunk/client/stdinc.h 2006-07-23 12:21:17 UTC (rev 642)
+++ dcplusplus/trunk/client/stdinc.h 2006-08-31 07:46:12 UTC (rev 643)
@@ -47,6 +47,7 @@
#else
#include <unistd.h>
+#include <stdint.h>
#endif
#include <stdio.h>
Modified: dcplusplus/trunk/windows/AboutDlg.h
===================================================================
--- dcplusplus/trunk/windows/AboutDlg.h 2006-07-23 12:21:17 UTC (rev 642)
+++ dcplusplus/trunk/windows/AboutDlg.h 2006-08-31 07:46:12 UTC (rev 643)
@@ -41,7 +41,7 @@
_T("theparanoidone, gadget, naga, tremor, joakim tosteberg, pofis, psf8500, lauris ievins, ")
_T("defr, ullner, fleetcommand, liny, xan, olle svensson, mark gillespie, jeremy huddleston, ")
_T("bsod, sulan, jonathan stone, tim burton, izzzo, guitarm, paka, nils maier, jens oknelid, yoji, ")
-_T("krzysztof tyszecki, poison, pothead, pur, bigmuscle, martin, jove, bart vullings, steven, ")
+_T("krzysztof tyszecki, poison, pothead, pur, bigmuscle, martin, jove, bart vullings, ")
_T("steven sheehy, tobias nygren. ")
_T("Keep it coming!");
Modified: dcplusplus/trunk/windows/FlatTabCtrl.h
===================================================================
--- dcplusplus/trunk/windows/FlatTabCtrl.h 2006-07-23 12:21:17 UTC (rev 642)
+++ dcplusplus/trunk/windows/FlatTabCtrl.h 2006-08-31 07:46:12 UTC (rev 643)
@@ -82,8 +82,7 @@
active = NULL;
delete ti;
tabs.erase(i);
- dcassert(find(viewOrder.begin(), viewOrder.end(), aWnd) != viewOrder.end());
- viewOrder.erase(remove(viewOrder.begin(), viewOrder.end(), aWnd), viewOrder.end());
+ viewOrder.remove(aWnd);
nextTab = viewOrder.end();
if(!viewOrder.empty())
--nextTab;
@@ -136,8 +135,7 @@
}
void setTop(HWND aWnd) {
- dcassert(find(viewOrder.begin(), viewOrder.end(), aWnd) != viewOrder.end());
- viewOrder.erase(remove(viewOrder.begin(), viewOrder.end(), aWnd), viewOrder.end());
+ viewOrder.remove(aWnd);
viewOrder.push_back(aWnd);
nextTab = --viewOrder.end();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|