char *currentBuf=receiveBuffer;
int bytesLeft=receivedBytes;
- int tmpIP;
//this should be large enough for a name
- char tmpName[1024];
+ char tmpName[4*1024];
//this should be large enough for the hostname
- char tmpHostname[512];
+ char tmpHostname[4*1024];
while (bytesLeft>0)
{
+ int tmpIP=2;
+ tmpName[0]='\0';
if ((memchr(currentBuf,0,bytesLeft)==0) || (memchr(currentBuf,int('\n'),bytesLeft)==0))
{
delete [] receiveBuffer;
@@ -190,17 +191,19 @@
return 0;
};
kdDebug(7101)<<"LANProtocol::lanReadDataFromServer: processing "<<currentBuf;
- sscanf(currentBuf,"%u %s\n",&tmpIP,tmpName);
//since we check for 0 and \n with memchr() we can be sure
//at this point that tmpBuf is correctly terminated
int length=strlen(currentBuf)+1;
+ if (length<(4*1024))
+ sscanf(currentBuf,"%u %s\n",&tmpIP,tmpName);
+
bytesLeft-=length;
currentBuf+=length;
- if ((bytesLeft==0) && (strstr(tmpName,"succeeded")!=0) && ((tmpIP==0) ||(tmpIP==1)))
+ if ((bytesLeft==0) && ((tmpIP==0) ||(tmpIP==1)) && (strstr(tmpName,"succeeded")!=0))
{
kdDebug(7101)<<"LANProtocol::lanReadDataFromServer: succeeded"<<endl;
}
- else
+ else if (tmpIP!=2)
{
kdDebug(7101)<<"LANProtocol::lanReadDataFromServer: listing host: "<<tmpName<<" with ip: "<<tmpIP<<endl;
UDSAtom atom;
@@ -344,13 +347,14 @@
char *currentBuf=receiveBuffer;
int bytesLeft=receivedBytes;
- int tmpIP;
//this should be large enough for a name
- char tmpName[1024];
+ char tmpName[4*1024];
//this should be large enough for the hostname
- char tmpHostname[512];
+ char tmpHostname[4*1024];
while (bytesLeft>0)
{
+ int tmpIP=2;
+ tmpName[0]='\0';
if ((memchr(currentBuf,0,bytesLeft)==0) || (memchr(currentBuf,int('\n'),bytesLeft)==0))
{
delete [] receiveBuffer;
@@ -358,17 +362,19 @@
return 0;
};
kdDebug(7101)<<"RLANProtocol::readDataFromServer: processing "<<currentBuf;
- sscanf(currentBuf,"%u %s\n",&tmpIP,tmpName);
//since we check for 0 and \n with memchr() we can be sure
//at this point that tmpBuf is correctly terminated
int length=strlen(currentBuf)+1;
+ if (length<(4*1024))
+ sscanf(currentBuf,"%u %s\n",&tmpIP,tmpName);
+
bytesLeft-=length;
currentBuf+=length;
- if ((bytesLeft==0) && (strstr(tmpName,"succeeded")!=0) && ((tmpIP==0) ||(tmpIP==1)))
+ if ((bytesLeft==0) && ((tmpIP==0) ||(tmpIP==1)) && (strstr(tmpName,"succeeded")!=0) )
{
kdDebug(7101)<<"RLANProtocol::readDataFromServer: succeeded"<<endl;
}
- else
+ else if (tmpIP!=2)
{
kdDebug(7101)<<"RLANProtocol::readDataFromServer: listing host: "<<tmpName<<" with ip: "<<tmpIP<<endl;
UDSAtom atom;
@@ -436,7 +442,7 @@
delete hostInfo;
return 0;
}
- memcpy(&ip, hp->h_addr, hp->h_length);
+ memcpy(&ip, hp->h_addr, sizeof(ip));
sockaddr_in serverAddress;
// bzero((char*)&serverAddress, sizeof(serverAddress));
@@ -654,6 +669,10 @@
m_receivedBytes+=result;
if (m_receiveBuffer!=0) delete [] m_receiveBuffer;
m_receiveBuffer=newBuf;
+ // too much data - abort at 2MB to avoid memory exhaustion
+ if (m_receivedBytes>2*1024*1024)
+ return 0;
+
return 1;
};
@@ -665,14 +684,15 @@
char *tmpBuf=m_receiveBuffer;
int bytesLeft=m_receivedBytes;
- int tmpIP;
mgetDebug()<<"m_receivedBytes: "<<m_receivedBytes<<" bytesLeft: "<<bytesLeft<<std::endl;
//this should be large enough for a name
//and the stuff which is inserted into the buffer
- //comes only from ourselves
+ //comes only from ourselves ... or attackers :-(
char tmpName[1024*4];
while (bytesLeft>0)
{
+ int tmpIP=2; // well, some impossible IP address, 0 and 1 are already used for the last line of output
+ tmpName[0]='\0';
if ((memchr(tmpBuf,0,bytesLeft)==0) || (memchr(tmpBuf,int('\n'),bytesLeft)==0))
{
delete newNodes;
@@ -687,14 +707,16 @@
return 0;
};
//mgetDebug()<<"NetManager::processScanResults: processing -"<<tmpBuf;
- sscanf(tmpBuf,"%u %s\n",&tmpIP,tmpName);
//since we check for 0 and \n with memchr() we can be sure
//at this point that tmpBuf is correctly terminated
int length=strlen(tmpBuf)+1;
+ if (length<(4*1024))
+ sscanf(tmpBuf,"%u %s\n",&tmpIP,tmpName);
+
bytesLeft-=length;
tmpBuf+=length;
mgetDebug()<<"length: "<<length<<" bytesLeft: "<<bytesLeft<<std::endl;
- if ((bytesLeft==0) && (strstr(tmpName,"succeeded")!=0) && ((tmpIP==0) ||(tmpIP==1)))
+ if ((bytesLeft==0) && ((tmpIP==0) ||(tmpIP==1)) && (strstr(tmpName,"succeeded")!=0))
{
mgetDebug()<<"NetManager::processScanResults: succeeded :-)"<<std::endl;
delete hostList;
@@ -712,7 +734,7 @@
struct ICMPEchoRequest
@@ -133,7 +137,7 @@
{
if ((m_strictMode) && (hostsAdded>=STRICTMODEMAXHOSTS))
break;
- memcpy(&server_addr, hp->h_addr, hp->h_length);
+ memcpy(&server_addr, hp->h_addr, sizeof(server_addr));
char *ip=inet_ntoa(server_addr);
mgetDebug()<<"NetScanner::configure(): looking up "<<nextName<<" gives -"<<ip<<"-"<<std::endl;
ipRangeStr=ipRangeStr+ip+';';
@@ -377,6 +381,9 @@
};
};
} while (!done);
+
+ // Warning: The return value of plcose may be incorrect due to the
+ // SIGCHLD handler that is installed. Ignore it!
pclose(nmblookupFile);