The Wayback Machine - https://web.archive.org/web/20201109182225/https://github.com/ARMmbed/mbedtls/pull/3614
Skip to content
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

Fix printf escape errors in shell scripts #3614

Conversation

@gilles-peskine-arm
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm commented Aug 26, 2020

Fix a minor bug in ssl-opt.sh that caused spurious messages on standard error and missing information in log files, but no test failure and no missed detection of a test failure. The bug was triggered by GnuTLS ciphersuite priority specifications containing % and manifested in errors like

Renegotiation: gnutls server strict, client-initiated .................. ./tests/ssl-opt.sh: 741: printf: %S: invalid directive
PASS

The bug was calling printf "$foo" instead of printf %s "$foo". Fix other instances of this mistake elsewhere, even if it had no practical consequence with current data.

The commit 880f7f2 “ssl-opt.sh --help: don't show regexps for -f and -e” is shared with #3615 to avoid a conflict between the two PR.

Backports: #3828, #3829

Showing a regexp to say that by default all tests are executed is not
particularly helpful.

If we ever add a default exclusion list or a default filter, we can
edit the documentation again.

Signed-off-by: Gilles Peskine <[email protected]>
Fix `printf "$foo"` which treats the value of `foo` as a printf format
rather than a string.

I used the following command to find potentially problematic lines:
```
git ls-files '*.sh' | xargs egrep 'printf +("?[^"]*|[^ ]*)\$'
```
The remaining ones are false positives for this regexp.

The errors only had minor consequences: the output of `ssl-opt.sh`
contained lines like
```
Renegotiation: gnutls server strict, client-initiated .................. ./tests/ssl-opt.sh: 741: printf: %S: invalid directive
PASS
```
and in case of failure the GnuTLS command containing a substring like
`--priority=NORMAL:%SAFE_RENEGOTIATION` was not included in the log
file. With the current tests, there was no risk of a test failure
going undetected.

Signed-off-by: Gilles Peskine <[email protected]>
Copy link
Contributor

@ronald-cron-arm ronald-cron-arm left a comment

Just two minor questions.

@@ -433,10 +433,11 @@ run_test "Binary file instead of text file" \

# End of tests

echo

This comment has been minimized.

@ronald-cron-arm

ronald-cron-arm Sep 24, 2020
Contributor

Why moving to echo here ? Just wondering if there is some specific reason.

This comment has been minimized.

@gilles-peskine-arm

gilles-peskine-arm Sep 24, 2020
Author Contributor

I find echo clearer than printf since you don't have to worry about escape sequences. They each have their downside: echo only works portably on strings that don't contain backslashes and don't start with a dash, but it's straightforward for those strings. printf is well-defined but you need to remember about its escapes (and it's slower in some shells where it isn't built in, but since it's built into dash, bash and zsh, that's not much of a concern in the context of this script).

printf "script should also be adjusted.\n"
printf "\n"

cat <<EOF

This comment has been minimized.

@ronald-cron-arm

ronald-cron-arm Sep 24, 2020
Contributor

Is that a well-known shell construct? Why not just some echo's there?

This comment has been minimized.

@gilles-peskine-arm

gilles-peskine-arm Sep 24, 2020
Author Contributor

This is the idiomatic shell construct to print multiple lines. https://stackoverflow.com/questions/2953081/how-can-i-write-a-heredoc-to-a-file-in-bash-script

Copy link
Contributor

@ronald-cron-arm ronald-cron-arm left a comment

Thanks for the clarifications, LGTM.

@ronald-cron-arm ronald-cron-arm moved this from To do to 1 Approval in Mbed TLS PRs Sep 25, 2020
@bensze01 bensze01 added this to Has Approval in Mbed TLS Unified Board Oct 1, 2020
@gabor-mezei-arm gabor-mezei-arm self-requested a review Oct 1, 2020
Mbed TLS PRs automation moved this from 1 Approval to Approved Oct 1, 2020
@ronald-cron-arm
Copy link
Contributor

@ronald-cron-arm ronald-cron-arm commented Nov 4, 2020

The CI failure in head job is a CI infrastructure glitch and all merge job tests passed thus good to go.

@ronald-cron-arm ronald-cron-arm merged commit efcf52d into ARMmbed:development Nov 4, 2020
9 of 12 checks passed
9 of 12 checks passed
continuous-integration/jenkins/pr-head This commit cannot be built
Details
PR-3614-head TLS Testing Failures: all_sh-ubuntu-16.04-test_default_cmake_gcc_asan
Details
continuous-integration/jenkins/pr-merge This commit is being built
Details
DCO DCO
Details
PR-3614-head Mbed OS Testing Ignore: Mbed OS is no longer tested
PR-3614-head Pre Test Checks OK
Details
PR-3614-head Result analysis OK
Details
PR-3614-merge Mbed OS Testing Ignore: Mbed OS is no longer tested
PR-3614-merge Pre Test Checks OK
Details
PR-3614-merge Result analysis OK
Details
PR-3614-merge TLS Testing All tests passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Mbed TLS Unified Board automation moved this from Has Approval to Done Nov 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Mbed TLS PRs
  
Approved
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.