     serial_buffer[num_read] = 0;// terminate the string
     if (serial_buffer[0] || current_buffer[0]) {
       if (serial_buffer[0])
-        strcat(current_buffer, serial_buffer);
+		  if (strlen(serial_buffer) + strlen(current_buffer) < MAX_BUFFER_LENGTH) // concat only if it fits
+			strcat(current_buffer, serial_buffer);
 
 #ifdef DEBUG
       Serial.write("initial buffer is=");

void setup()
{
  first_start = 0;
  strcpy(firmware_version, "2017.03.16.0");

  current_buffer[0] = 0;


//Main loop
void loop()
{
  char serial_out[MAX_BUFFER_LENGTH];

  // check to see if there are new results from ultrasonic sensor
  ultrasonic_sensors_controller.update_results(serial_out);
