mbedtls icon indicating copy to clipboard operation
mbedtls copied to clipboard

ssl_mail_client: Fix unbounded write of sprintf()

Open szsam opened this issue 11 months ago • 7 comments

Description

These calls to sprintf may overflow buf because opt.mail_from and opt.mail_to are controlled by users. Fix by replacing sprintf with snprintf.

PR checklist

Please tick as appropriate and edit the reasons (e.g.: "backport: not needed because this is a new feature")

  • [x] changelog not required
  • [ ] backport Need to cherry-pick to mbedtls-2.28: #8907; 3.6: TODO
  • [x] tests not required

Notes for the submitter

Please refer to the contributing guidelines, especially the checklist for PR contributors.

Help make review efficient:

  • Multiple simple commits
    • please structure your PR into a series of small commits, each of which does one thing
  • Avoid force-push
    • please do not force-push to update your PR - just add new commit(s)
  • See our Guidelines for Contributors for more details about the review process.

szsam avatar Mar 05 '24 23:03 szsam

Windows builds are failing.

gilles-peskine-arm avatar Mar 12 '24 10:03 gilles-peskine-arm

From the CI:

281>C:\Windows\workspace\mbed-tls-pr-head_PR-8897-head\worktrees\tmpsowuty4p\programs\ssl\ssl_mail_client.c(730): warning C4013: 'snprintf' undefined; assuming extern returning int [c:\windows\workspace\mbed-tls-pr-head_PR-8897-head\worktrees\tmpsowuty4p\cmake_solution\programs\ssl\ssl_mail_client.vcxproj]

daverodgman avatar Mar 12 '24 11:03 daverodgman

I replaced snprintf with mbedtls_snprintf and checked the return values of mbedtls_snprintf. If that looks good and passes CI, I will update the backport PR.

szsam avatar Mar 12 '24 20:03 szsam

Hi, and thank you for your contribution. Could you please try to fix the code style?

It can be done automatically using the scripts/code_style.py -f

minosgalanakis avatar Mar 18 '24 15:03 minosgalanakis

Can we start CI?

szsam avatar Apr 01 '24 20:04 szsam

Can we start CI?

I've just done it.

ronald-cron-arm avatar Apr 02 '24 06:04 ronald-cron-arm

Ready for review.

szsam avatar Apr 03 '24 20:04 szsam

I'd say this needs a 3.6 backport too, now. Edit: ah, was already in the PR description, I had missed it as the end of the line after the 2.28 link.

mpg avatar Apr 30 '24 10:04 mpg