Ignore:
Timestamp:
Sep 12, 2017, 11:26:33 AM (7 years ago)
Author:
Sanahuja Guillaume
Message:

avoid buffer overrun

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairSensorActuator/src/Mb800.cpp

    r194 r196  
    4343
    4444void Mb800::Run(void) {
    45   char response[200] = {0};
    46   int size,written;
     45  int written;
    4746
    4847  /** Debut config **/
     
    103102  /** Debut running loop **/
    104103  WarnUponSwitches(true);
    105 
     104 
    106105  while (!ToBeStopped()) {
    107     //SleepMS(10);??
    108     size = 0;
     106    char response[1024] = {0};
     107    int size = 0;
    109108    while (!ToBeStopped()) {
    110109      ssize_t read = serialport->Read(&response[size], 1);
     
    113112      }
    114113
    115       if (response[size] == 0x0a)
    116         break;
     114      if (response[size] == 0x0a ) break;
    117115      size++;
     116      if (size==sizeof(response)) break;
    118117    }
    119     size++;
    120     parseFrame(response, size);
     118    if (size!=sizeof(response)) {
     119      size++;
     120      parseFrame(response, size);
     121    } else {
     122      Thread::Warn("frame too long for buffer\n");
     123    }
    121124  }
     125 
    122126  /** fin running loop **/
    123127  WarnUponSwitches(false);
Note: See TracChangeset for help on using the changeset viewer.