Skip to content

Remove broken frivolous function from install script #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2022
Merged

Remove broken frivolous function from install script #222

merged 1 commit into from
Apr 20, 2022

Conversation

per1234
Copy link
Contributor

@per1234 per1234 commented Apr 20, 2022

The "template" installation script contained a get() function used to make an HTTP request.

The response body is required by the caller, but shell functions do not support returning content as you might do when using a more capable programming language.

As a workaround, the script author set up a system where the caller passed an arbitrary variable name to the function, which the function then assigns with the response body string.

This was done using the eval builtin. The eval command was quoted in a naive manner, not considering that the body content could contain any arbitrary characters. This made it possible that contents of the response body could be unintentionally executed on the user's machine.

In the context of the installation script, this happened under the following conditions:

The most minimal fix would likely have been to change the eval command so that the variable containing the response body text was not expanded in the command:

eval "$1=\$GET_BODY"

However, this problem has provided clear evidence that best practices are to avoid eval altogether unless absolutely necessary. Since it is only called once, the entire function is not necessary (and in fact it is questionable whether there is any real value in the entire GitHub releases fallback system). So I decided the best fix was to do away with the function altogether, replacing its single call with the contents of the former function. This removed unnecessary complexity from the script without any decrease in efficiency or increase in maintenance burden.


Originally reported at arduino/arduino-cli#1714

The "template" installation script contained a `get()` function used to make an HTTP request.

The response body is required by the caller, but shell functions do not support returning content as you might do when
using a more capable programming language.

As a workaround, the script author set up a system where the caller passed an arbitrary variable name to the function,
which the function then assigns with the response body string.

This was done using the `eval` builtin. The `eval` command was quoted in a naive manner, not considering that the body
content could contain any arbitrary characters. This made it possible that contents of the response body could be
unintentionally executed on the user's machine.

In the context of the installation script, this happened under the following conditions:

- The release download was not available from Arduino's downloads server
- The response body from the Releases GitHub API request contained single quotes

The most minimal fix would likely have been to change the `eval` command so that the variable containing the response
body text was not expanded in the command:

eval "$1=\$GET_BODY"

However, this problem has provided clear evidence that best practices are to avoid `eval` altogether unless absolutely
necessary. Since it is only called once, the entire function is not necessary (and in fact it is questionable whether
there is any real value in the entire GitHub releases fallback system). So I decided the best fix was to do away with
the function altogether, replacing its single call with the contents of the former function. This removed unnecessary
complexity from the script without any decrease in efficiency or increase in maintenance burden.
@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Apr 20, 2022
@per1234 per1234 requested review from cmaglie and umbynos April 20, 2022 13:30
@per1234 per1234 self-assigned this Apr 20, 2022
@cmaglie
Copy link
Member

cmaglie commented Apr 20, 2022

I like a lot this change 👍🏼
I see that there are other eval with the same purpose, maybe it's worth removing all of them since we are here?

@per1234 per1234 merged commit 6d108f7 into arduino:main Apr 20, 2022
@per1234 per1234 deleted the fix-install-fallback branch April 20, 2022 15:44
Copy link

@ubidefeo ubidefeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

install svcript tested and working correctly on M1 Monterey 12.3

Installing in /Users/ubidefeo/Downloads/bin
ARCH=ARM64
OS=macOS
Using curl as download tool
Downloading https://downloads.arduino.cc/arduino-cli/arduino-cli_0.21.1_macOS_ARM64.tar.gz
macOS ARM64 release not currently available. Checking for alternative macOS 64bit release for your system.
Downloading https://downloads.arduino.cc/arduino-cli/arduino-cli_0.21.1_macOS_64bit.tar.gz
An existing arduino-cli was found at /opt/homebrew/bin/arduino-cli. Please prepend "/Users/ubidefeo/Downloads/bin" to your $PATH or remove the existing one.
arduino-cli  Version: 0.21.1 Commit: 9fcbb392 Date: 2022-02-24T15:41:45Z installed successfully in /Users/ubidefeo/Downloads/bin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants