Changeset 915

Show
Ignore:
Timestamp:
11/07/06 09:39:47 (2 years ago)
Author:
ahu
Message:

fix possible TCP related crash on malformed packet

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/pdns/pdns/pdns_recursor.cc

    r903 r915  
    653653      conn->state=TCPConnection::BYTE1; 
    654654    if(bytes==2) {  
    655       conn->qlen=(conn->data[0]<<8)+conn->data[1]; 
     655      conn->qlen=(((unsigned char)conn->data[0]) << 8)+ (unsigned char)conn->data[1]; 
    656656      conn->bytesread=0; 
    657657      conn->state=TCPConnection::GETQUESTION; 
     
    665665  } 
    666666  else if(conn->state==TCPConnection::BYTE1) { 
    667     int bytes=recv(conn->fd,conn->data+1,1,0); 
     667    int bytes=recv(conn->fd, conn->data+1, 1, 0); 
    668668    if(bytes==1) { 
    669669      conn->state=TCPConnection::GETQUESTION; 
    670       conn->qlen=(conn->data[0]<<8)+conn->data[1]; 
     670      conn->qlen=(((unsigned char)conn->data[0]) << 8)+ (unsigned char)conn->data[1]; 
    671671      conn->bytesread=0; 
    672672    } 
     
    681681  } 
    682682  else if(conn->state==TCPConnection::GETQUESTION) { 
    683     int bytes=recv(conn->fd,conn->data + conn->bytesread,conn->qlen - conn->bytesread, 0); 
     683    int bytes=recv(conn->fd, conn->data + conn->bytesread, conn->qlen - conn->bytesread, 0); 
    684684    if(!bytes || bytes < 0) { 
    685685      L<<Logger::Error<<"TCP client "<< conn->remote.toString() <<" disconnected while reading question body"<<endl;