ntruchsess / arduino_uip

UIPEthernet: A plugin-replacement of the stock Arduino Ethernet library for ENC28J60 shields and breakout boards. Full support for persistent (streaming) TCP-connections and UDP (Client and Server each), ARP, ICMP, DHCP and DNS. Build around Adam Dunkels uIP Stack. Further developed version can be found on https://github.com/UIPEthernet/UIPEthernet
489 stars 212 forks source link

Seg fault in another library when EthernetClient is initialised #151

Open jondea opened 8 years ago

jondea commented 8 years ago

I am getting a very mysterious error, while using a different library (AESlib.h), I was getting a seg fault when using one particular function (aes_cbc_enc). At first I thought it may be an error in that library, but I discovered that the error disappears when I comment out the line EthernetClient client, or even if I use the built in Arduino Ethernet.h.

Obviously I can't be sure which library is causing the error. In fact, I'm not even certain how to properly debug this library or further probe the cause of this error. Any help/advice would be appreciated.


#include <Arduino.h>
#include <AESLib.h>
#include <SPI.h>
#include <UIPEthernet.h>
//#include <Ethernet.h>

const uint8_t key[16] = {'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'};

// Comment this out and it works
EthernetClient client;

void setup() {

  Serial.begin(9600);

  cbcTest();
}

void loop() {}

void cbcTest() {

  Serial.println("Entered cbcTest()");

  uint16_t dataLength = 16;
  char data[] = "abcdefghijklmnop";

  uint8_t iv[16] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P'};

  Serial.print("Plaintext: "); Serial.write(data, dataLength); Serial.println("");
  Serial.print("key: ");  Serial.write(key, 16); Serial.println("");
  Serial.print("IV: "); Serial.write(iv, 16);  Serial.println("");
  Serial.println("If it stops here, it has frozen");
  delay(1000);

  aes128_cbc_enc(key, iv, data, dataLength);

  Serial.print("Ciphertext: ");  Serial.write(data, dataLength);  Serial.println("");
  delay(100);

  Serial.println("Finished cbcTest() without seg fault");
  delay(100);
}

Running on a mega and using the 1.09ext version of the library