buffer overflow problem

This is a discussion on buffer overflow problem within the C++ Programming forums, part of the General Programming Boards category; Im having problems with a server im writting, its possible to cause a buffer overflow. thanks you for any help ...

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    3

    buffer overflow problem

    Im having problems with a server im writting, its possible to cause a buffer overflow.

    thanks you for any help you can give.

    buff is a std string

    Code:
    connection::ReadData() {
      FD_ZERO(&mask);
      FD_SET(s, &mask);
    
      select(s+1,&mask,NULL,NULL,&tv);
    
      char cstr[200]; int mark = 0;
    
      if(FD_ISSET(s, &mask)) {
        int num = recv (s, cstr, 200, 0);
    
        for(int i = 0; i < num; i++) {
          buff = buff + cstr[i];
          }
    
        for(int i = 0; i < strlen(buff.c_str()); i++) {
          if( buff[i] == '\n' ) {
            buff[i] = '\0';
            messageLog.Add(buff, p);
            mark = i;
            buff = "";
            }
          }
    
        }
    }

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    3
    Code:
        int num = recv (s, cstr, 200, 0);
        
        for(int i = 0; i < num; i++) {
          buff = buff + cstr[i];
          }
    if num was 0 or 1, the next for statement wouldnt run. + the overflow only happens when someone piles in too much data.

    - Renski -

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    3
    Where is the ``buffer overflow''? You don't read too much data using recv( ), buff will dynamically be extended, and the last loop doesn't break anything either (at least not the code that can be seen, I don't know what messageLog::add( ) does...) How does the ``buffer overflow'' behave?

    Thats what I thought, however I showed that code to someone else and they said that recv was the problem. It looks like they where wrong.

    I must be doing something wrong further on...

    thanks

    - Renski -

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can't Produce a buffer overflow
    By someprogr in forum C Programming
    Replies: 8
    Last Post: 09-15-2008, 08:59 AM
  2. writing a pack-style function, any advices?
    By isaac_s in forum C Programming
    Replies: 10
    Last Post: 07-08-2006, 08:09 PM
  3. Buffer problem
    By Narcose in forum Game Programming
    Replies: 3
    Last Post: 03-24-2006, 08:29 AM
  4. Popen problem with stdout buffer
    By gandalf_bar in forum Linux Programming
    Replies: 2
    Last Post: 05-26-2004, 03:00 AM
  5. Input Buffer problem.
    By Krupux in forum C Programming
    Replies: 2
    Last Post: 08-06-2002, 09:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21