Skip to content

Rebased/Squashed mbedTLS branch - #132

Closed
Keno wants to merge 5 commits into
libssh2:masterfrom
Keno:mbedtls
Closed

Keno wants to merge 5 commits into
libssh2:masterfrom
Keno:mbedtls

Conversation

@Keno

@Keno Keno commented Sep 26, 2016

Copy link
Copy Markdown
Contributor

This rebases and squashes #106. I've also added support for mbedtls to the autotools build system and added some documentation on the new build system options.

@bagder

bagder commented Sep 26, 2016

Copy link
Copy Markdown
Member

automake: error: cannot open < src/../Makefile.mbedTLS.inc: No such file or directory

Forgot to add that file I guess?

@Keno

Keno commented Sep 26, 2016

Copy link
Copy Markdown
Contributor Author

yes, sorry!

@Keno

Keno commented Sep 26, 2016

Copy link
Copy Markdown
Contributor Author

should be fixed.

@bagder

bagder commented Sep 26, 2016

Copy link
Copy Markdown
Member

Yes, works now. Now I just ran into problems with the configure script. Not really your fault as you just used the same style already used, its just that it isn't very good...

@Keno

Keno commented Sep 26, 2016

Copy link
Copy Markdown
Contributor Author

I suppose I'm gonna have to build mbedtls from source on travis. I had hoped that wasn't necessary anymore since we don't need to patch it now, but it looks like Travis' ubuntu is too old to have the package and I couldn't find a good ppa.

@bagder

bagder commented Sep 27, 2016

Copy link
Copy Markdown
Member

Thanks for all the work. I merged what we have now. For follow up fixes and more, just create new issues or PRs, thanks!

@tkelman

tkelman commented Sep 27, 2016

Copy link
Copy Markdown
Contributor

Fantastic, thank you so much @bagder!

@bagder

bagder commented Sep 27, 2016

Copy link
Copy Markdown
Member

Ah right, we need to fix the travis build. Do we revert the commit 3e6de50 to start with or do you have a fix pending?

@tkelman

tkelman commented Sep 27, 2016

Copy link
Copy Markdown
Contributor

I'll try a PR

kbulgrien pushed a commit to kbulgrien/libssh2-1.2.4-sco3.2v5.0.7 that referenced this pull request Dec 14, 2018
alex-weaver pushed a commit to alex-weaver/libssh2 that referenced this pull request Mar 23, 2023
vszakats added a commit to vszakats/libssh2 that referenced this pull request Oct 18, 2025
linux (clang-tidy, amd64, mbedTLS-prev, cmake, ON):
```
/home/runner/work/libssh2/libssh2/src/mbedtls.c:744:8: error: Branch condition evaluates to a garbage value [clang-analyzer-core.uninitialized.Branch,-warnings-as-errors]
  744 |     if(ret) {
      |        ^
/home/runner/work/libssh2/libssh2/src/mbedtls.c:777:8: note: Assuming 'ret' is 0
  777 |     if(ret) {
      |        ^~~
/home/runner/work/libssh2/libssh2/src/mbedtls.c:777:5: note: Taking false branch
  777 |     if(ret) {
      |     ^
/home/runner/work/libssh2/libssh2/src/mbedtls.c:783:11: note: Calling '_libssh2_mbedtls_pub_priv_key'
  783 |     ret = _libssh2_mbedtls_pub_priv_key(session, method, method_len,
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  784 |                                         pubkeydata, pubkeydata_len, &pkey);
      |                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/libssh2/libssh2/src/mbedtls.c:718:5: note: 'ret' declared without an initial value
  718 |     int ret;
      |     ^~~~~~~
/home/runner/work/libssh2/libssh2/src/mbedtls.c:721:8: note: Assuming the condition is false
  721 |     if(mbedtls_pk_get_type(pkey) != MBEDTLS_PK_RSA) {
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/libssh2/libssh2/src/mbedtls.c:721:5: note: Taking false branch
  721 |     if(mbedtls_pk_get_type(pkey) != MBEDTLS_PK_RSA) {
      |     ^
/home/runner/work/libssh2/libssh2/src/mbedtls.c:730:8: note: Assuming 'mth' is non-null
  730 |     if(mth) {
      |        ^~~
/home/runner/work/libssh2/libssh2/src/mbedtls.c:730:5: note: Taking true branch
  730 |     if(mth) {
      |     ^
/home/runner/work/libssh2/libssh2/src/mbedtls.c:739:9: note: 'key' is non-null
  739 |     if(!key) {
      |         ^~~
/home/runner/work/libssh2/libssh2/src/mbedtls.c:739:5: note: Taking false branch
  739 |     if(!key) {
      |     ^
/home/runner/work/libssh2/libssh2/src/mbedtls.c:744:8: note: Branch condition evaluates to a garbage value
  744 |     if(ret) {
      |        ^~~
4 warnings generated.
```
https://github.com/libssh2/libssh2/actions/runs/18620615649/job/53091295760#step:22:44

Follow-up to 186f1a2 libssh2#132
vszakats added a commit to vszakats/libssh2 that referenced this pull request Oct 18, 2025
In `_libssh2_mbedtls_pub_priv_key()` on a NON-error code path, a stack
variable was checked without initializing it first.

I found it interesting that clang-tidy did not find this when building
against the system mbedtls (2.x) with 2.x compatibility code still it.
Then it did find it when using a manual build of mbedtls 3.1.0 with
2.x compatibility code deleted from libssh2. Being such a trivial error
I wonder why no compiler ever detected it as a regular warning.

linux (clang-tidy, amd64, mbedTLS-prev [3.1.0], cmake, ON):
```
/home/runner/work/libssh2/libssh2/src/mbedtls.c:744:8: error: Branch condition evaluates to a garbage value [clang-analyzer-core.uninitialized.Branch,-warnings-as-errors]
  744 |     if(ret) {
      |        ^
```
Ref: https://github.com/libssh2/libssh2/actions/runs/18620615649/job/53091295760#step:22:44

Follow-up to 186f1a2 libssh2#132
Cherry-picked from libssh2#1727
vszakats added a commit that referenced this pull request Oct 18, 2025
In `_libssh2_mbedtls_pub_priv_key()` on a NON-error code path, a stack
variable was checked without initializing it first.

I found it interesting that clang-tidy did not find this when building
against the system mbedtls (2.x) with 2.x compatibility code still in.
Then it did find it when using a manual build of mbedtls 3.1.0 with
2.x compatibility code deleted from libssh2. Being such a trivial error
I wonder why no compiler ever detected it as a regular warning.

linux (clang-tidy, amd64, mbedTLS-prev [3.1.0], cmake, ON):
```
src/mbedtls.c:744:8: error: Branch condition evaluates to a garbage value [clang-analyzer-core.uninitialized.Branch,-warnings-as-errors]
  744 |     if(ret) {
      |        ^
```
Ref: https://github.com/libssh2/libssh2/actions/runs/18620615649/job/53091295760#step:22:44

Follow-up to 186f1a2 #132
Cherry-picked from #1727
Closes #1729
vszakats added a commit that referenced this pull request Aug 3, 2026
"`mbed_pub_priv_key()` frees `pkey` on the unsupported-key path, but the
caller (`ssh2_pub_privkey()`) unconditionally calls
`mbedtls_pk_free(&pkey)` after this helper returns. That makes this a
double-free on the error path (memory corruption). The helper should not
free `pkey`; leave ownership/cleanup to the caller."

Reported by Copilot
Bug: #2501 (comment)
Bug: #2501 (comment)
Follow-up to 186f1a2 #132

Closes #2502
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants