Skip to content

Nano Every - fatal security bug in Wire.h #11221

Open
@mikrocoder

Description

@mikrocoder

Hallo,

wire.begin should disable 'output and 'pullup' of pin 18 and 19 before initializing TWI as a precaution. In case someone programs pin 18 and 19 digitally and then turns on TWI. Because pin 18/19 (PortF) TWI (PortA) are different ports, electrical short circuits could occur.
Another problem is that Wire.end does not turn off its own port pullups of PA2 and PA3. Pin 18 and 19 are inputs, Wire is terminated and still the pins output 4.7 volts.

Translated with www.DeepL.com/Translator (free version)

#include <Streaming.h>
#include <Wire.h>

const byte wait {1};  // for enventual electrical measurements

void setup(void) 
{
  Serial.begin(250000);
  Serial.println(F("\nStart #### #### #### ####"));
  showData();

  Serial.println("\nInput_Pullup.18");  pinMode(18, INPUT_PULLUP);  
  Serial.println("Input_Pullup.19");    pinMode(19, INPUT_PULLUP);
  showData();
  delay(wait);
  Serial.println("\nOutput.18");  pinMode(18, OUTPUT);        
  Serial.println("Output.19");    pinMode(19, OUTPUT);
  showData();
  delay(wait);
  Serial.println("\nWire.begin"); Wire.begin();
  showData();
  delay(wait);
  Serial.println("\nInput.18");   pinMode(18, INPUT);  
  Serial.println("Input.19");     pinMode(19, INPUT);
  showData();
  delay(wait);
  Serial.println("\nWire.end");   Wire.end();
  showData();
}

void loop(void) 
{ }

void showData(void)
{
  Serial << "TWI0_MCTRLA    " << _HEX((uint16_t)&TWI0_MCTRLA)    << '\t' << _BIN(TWI0_MCTRLA)    << endl;
  Serial << "TWI0_SCTRLA    " << _HEX((uint16_t)&TWI0_SCTRLA)    << '\t' << _BIN(TWI0_MCTRLA)    << endl;
  Serial << "PORTA_DIR      " << _HEX((uint16_t)&PORTA_DIR)      << '\t' << _BIN(PORTA_DIR)      << endl;
  Serial << "PORTA_PIN2CTRL " << _HEX((uint16_t)&PORTA_PIN2CTRL) << '\t' << _BIN(PORTA_PIN2CTRL) << endl;
  Serial << "PORTA_PIN3CTRL " << _HEX((uint16_t)&PORTA_PIN3CTRL) << '\t' << _BIN(PORTA_PIN3CTRL) << endl;
  Serial << "PORTF_DIR      " << _HEX((uint16_t)&PORTF_DIR)      << '\t' << _BIN(PORTF_DIR)      << endl;
  Serial << "PORTF_PIN2CTRL " << _HEX((uint16_t)&PORTF_PIN2CTRL) << '\t' << _BIN(PORTF_PIN2CTRL) << endl;
  Serial << "PORTF_PIN3CTRL " << _HEX((uint16_t)&PORTF_PIN3CTRL) << '\t' << _BIN(PORTF_PIN3CTRL) << endl;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions