Skip to content

Commit

Permalink
fix(ota): Wrap espota --auth flag in quotes (#10126)
Browse files Browse the repository at this point in the history
When performing an "OTA" upload via a network port, the user may configure the sketch to require
an authentication password.

Arduino IDE presents a "Configure and Upload" dialog when the user triggers an upload to a network
port. The user can provide the authentication password via the field in that dialog. The
`upload.field.password` platform property is then set to the value provided by the user.

The platform uses the `tools.esp_ota.upload.pattern` command template to pass this value to the
espota upload tool via the tool's `--auth` flag.

Since the value of the `upload.field.password` platform property is set by the user via a free text
field, it might contain any characters. Since some characters (e.g., spaces) can be problematic in
a command line, it is essential to wrap it in quotes. This was done for the Arduino IDE 1.x variant
of the command template, but that was not ported when the pluggable discovery variant of the
command pattern was defined. This causes a spurious failure of the OTA upload process if the user
provides an authentication password that contains problematic characters.

For example:

```
"C:\Users\per\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.4\tools\espota.exe" \
-r -i 192.168.254.145 \
-p 3232 --auth=foo bar \
-f "C:\Users\per\AppData\Local\Temp\arduino\sketches\E2D807FABB134A2A60A1B9C7D14FE02B/11973.ino.bin"
usage: espota.exe [-h] [-i ESP_IP] [-I HOST_IP] [-p ESP_PORT] [-P HOST_PORT]
                  [-a AUTH] [-f FILE] [-s] [-d] [-r] [-t TIMEOUT]
espota.exe: error: unrecognized arguments: bar
Failed uploading: uploading error: exit status 2
```

This is prevented by wrapping the `--auth` flag in quotes:

```
"C:\Users\per\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.4\tools\espota.exe" \
a-r -i 192.168.254.145 \
-p 3232 "--auth=foo bar" \
-f "C:\Users\per\AppData\Local\Temp\arduino\sketches\E2D807FABB134A2A60A1B9C7D14FE02B/11973.ino.bin"
Sending invitation to 192.168.254.145
Authenticating...OK

Uploading: [                                                            ] 0%
```
  • Loading branch information
per1234 authored Aug 13, 2024
1 parent da13c03 commit d3f5b9b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ tools.esptool_py.upload.network_pattern={network_cmd} -i "{serial.port}" -p "{ne
tools.esp_ota.upload.protocol=network
tools.esp_ota.upload.field.password=Password
tools.esp_ota.upload.field.password.secret=true
tools.esp_ota.upload.pattern={cmd} -i {upload.port.address} -p {upload.port.properties.port} --auth={upload.field.password} -f "{build.path}/{build.project_name}.bin"
tools.esp_ota.upload.pattern={cmd} -i {upload.port.address} -p {upload.port.properties.port} "--auth={upload.field.password}" -f "{build.path}/{build.project_name}.bin"

## Upload Sketch Through DFU OTA
## -------------------------------------------
Expand Down

0 comments on commit d3f5b9b

Please sign in to comment.