Ignore:
Timestamp:
09/12/17 11:26:33 (4 years ago)
Author:
Sanahuja Guillaume
Message:

avoid buffer overrun

File:
1 edited

Legend:

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

    r170 r196  
    4242
    4343void Novatel::Run(void) {
    44   char response[200] = {0};
    45   int size;
    4644  ssize_t written;
    4745
     
    6260
    6361  while (!ToBeStopped()) {
    64     size = 0;
    65     while (1) {
    66       // ssize_t read = rt_dev_read(uart_fd, &response[size],1);
    67       ssize_t Read = serialport->Read(&response[size], 1);
    68       if (Read < 0) {
    69         Thread::Err("erreur Read (%s)\n", strerror(-Read));
     62    char response[1024] = {0};
     63    int size = 0;
     64    while (!ToBeStopped()) {
     65      ssize_t read = serialport->Read(&response[size], 1);
     66      if (read < 0) {
     67        Thread::Err("erreur Read (%s)\n", strerror(-read));
    7068      }
    71       if (response[size] == 0x0a)
    72         break;
     69
     70      if (response[size] == 0x0a ) break;
    7371      size++;
     72      if (size==sizeof(response)) break;
    7473    }
    75     size++;
    76     parseFrame(response, size);
     74    if (size!=sizeof(response)) {
     75      size++;
     76      parseFrame(response, size);
     77    } else {
     78      Thread::Warn("frame too long for buffer\n");
     79    }
    7780  }
    7881
Note: See TracChangeset for help on using the changeset viewer.