Repository navigation
tests: avoid using MAXPATHLEN, for portability - #1415
babelouest wants to merge 15 commits into
Conversation
…some systems Closes: libssh2#1414
|
valgrind tests would be a nice addition, but I personally have not As for freeing pointers: What do you think of an approach of freeing If we move to freeing right after use, there are two more cases |
|
Thanks for your feedback! I've updated the PR to cleanup Concerning valgrind, I use it by executing the test program via valgrind and checking the result, example: I don't know exactly where the test programs are executed in libssh2, I guess tests/test_sshd.test is one of the starting point. Although, the docker tests should be updated too, but I don't know how yet. |
|
Thanks for you updates! checksrc has these complaints: Tests are launched via the |
MAXPATHLEN, for portability
|
Looking good. Based on https://learn.microsoft.com/en-us/cpp/c-runtime-library/path-field-limits https://www.man7.org/linux/man-pages/man3/realpath.3.html and 10a5cbf we might be able to drop If CI remains green, we could drop Would you like to do these? Or let me know if I should do it. |
|
Removing If successful, I'd like you to remove |
|
Agreed! |
|
It seems that removing |
|
I think the AppVeyor job failed for unrelated reasons. It sometimes does that while trying to interact with a GHA server process and failing ("Waiting for SSH connection from GitHub Actions..[...] failed.", then timing out. If you push (or force-push) the branch it will make it re-run. |
After a small change/push, still no luck with AppVeyor tests. |
```
../../tests/session_fixture.c:266:49: warning: conversion to 'size_t' {aka 'long long unsigned int'} from 'int' may change the sign of the result [-Wsign-conversion]
266 | snprintf(filepath[curpath], len + 1, "%s/%s", p, file);
| ~~~~^~~
../../tests/session_fixture.c:276:49: warning: conversion to 'size_t' {aka 'long long unsigned int'} from 'int' may change the sign of the result [-Wsign-conversion]
276 | snprintf(filepath[curpath], len + 1, "%s", file);
| ~~~~^~~
../../tests/session_fixture.c:276:57: error: 'snprintf' output may be truncated before the last format character [-Werror=format-truncation=]
276 | snprintf(filepath[curpath], len + 1, "%s", file);
| ^
../../tests/session_fixture.c:276:17: note: 'snprintf' output 1 or more bytes (assuming 2) into a destination of size 1
276 | snprintf(filepath[curpath], len + 1, "%s", file);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../tests/session_fixture.c:266:57: error: '/' directive output may be truncated writing 1 byte into a region of size between 0 and 1 [-Werror=format-truncation=]
266 | snprintf(filepath[curpath], len + 1, "%s/%s", p, file);
| ^
../../tests/session_fixture.c:266:54: note: assuming directive output of 1 byte
266 | snprintf(filepath[curpath], len + 1, "%s/%s", p, file);
| ^~~~~~~
../../tests/session_fixture.c:266:17: note: 'snprintf' output 2 or more bytes (assuming 4) into a destination of size 1
266 | snprintf(filepath[curpath], len + 1, "%s/%s", p, file);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
|
Thank you Nicolas, merged! |
|
Thanks for your help! |
`MAXPATHLEN` is not present in some systems, e.g. GNU Hurd. Co-authored-by: Viktor Szakats Ref: 54bef4c libssh2#198 Fixes libssh2#1414 Closes libssh2#1415
This header is no longer used. Follow-up to 12427f4 libssh2#1415 Closes libssh2#1418
Causing memleak, OOB read and freeing an invalid pointer.
Also:
- fix potentially freeing the whole list when receiving `NULL` input
path. (reported by clang-tidy, could not happen with existing tests.)
- make use of `SSH2_ARRAYSIZE()`, bump index type to `size_t`.
- avoid calling `getenv()` when unnecessary.
- clear freed slot pointers.
- avoid crash on OOM by checking `calloc()` results.
- return `NULL` if no more empty slots.
- drop single-instruction `{}` blocks.
Root issue spotted by GitHub Code Quality
Note: this is still problematic after this many changes since the many
failure mores all return `NULL` which then crash/break the actual test,
in obscure ways.
Follow-up to 12427f4 #1415
Closes #2089
- if `srcdir` is unset or empty return the received filename as-is. - replace `assert()` with an always-enabled check, error messages and `abort()` on fail. To make it work in debug build and not return `NULL` to the caller. - determine buffer length manuall, to not rely on `snprintf()`. - limit input sizes. - switch from `calloc()` to `malloc()` to avoid GCC false positive `-Wformat-truncation`. Ref: https://github.com/libssh2/libssh2/actions/runs/27912044754/job/82590731447#step:24:45 - restore lost `const` to return value. - constify `getenv()` result pointer. - rename `p` to `srcdir`. - flatten. If this still falls short in some ways, it's still an option to revert to static buffers. Follow-up to aae3776 #2089 Follow-up to 12427f4 #1415 Closes #2102
This time without using `MAXPATHLEN`, which is missing from GNU Hurd. Nor using other constants, and 256 bytes on all platforms. Dynamic allocations almost looked good after good summer day of hair pulling, until I ran gcc-16, gcc-15, gcc-14 locally, in unity mode, where all 3 fell over with various bogus `-Wformat-truncate` false positives. This isn't worth all this effort. Ref: https://darnassus.sceen.net/~hurd-web/faq/foo_max/ Follow-up to 3f6481b1a870636d9bb19988ed61fff1f6877547 libssh2#2102 Follow-up to aae3776 libssh2#2089 Follow-up to 12427f4 libssh2#1415 Fixing: gcc-14, gcc-15: ``` tests/session_fixture.c: In function 'srcdir_path': tests/session_fixture.c:276:46: error: '%s' directive output may be truncated writing likely 1 or more bytes into a region of size between 0 and 1 [-Werror=format-truncation=] 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~ tests/session_fixture.c:276:5: note: in expansion of macro 'ssh2_snprintf' 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~~~~~~~ In file included from bld/tests/CMakeFiles/runner.dir/Unity/unity_0_c.c:7: tests/session_fixture.c:276:50: note: format string is defined here 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~ tests/session_fixture.c:276:46: note: assuming directive output of 1 byte 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~ tests/session_fixture.c:276:5: note: in expansion of macro 'ssh2_snprintf' 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~~~~~~~ src/libssh2_priv.h:151:23: note: '__builtin_snprintf' output 2 or more bytes (assuming 4) into a destination of size 2 151 | #define ssh2_snprintf snprintf | ^~~~~~~~ tests/session_fixture.c:276:5: note: in expansion of macro 'ssh2_snprintf' 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~~~~~~~ ``` gcc-16: ``` tests/session_fixture.c: In function 'srcdir_path': tests/session_fixture.c:276:46: error: '%s' directive output may be truncated writing up to 8192 bytes into a region of size 2 [-Werror=format-truncation=] 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~ tests/session_fixture.c:276:5: note: in expansion of macro 'ssh2_snprintf' 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~~~~~~~ In file included from bld/tests/CMakeFiles/runner.dir/Unity/unity_0_c.c:7: tests/session_fixture.c:276:47: note: format string is defined here 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~ src/libssh2_priv.h:151:23: note: '__builtin_snprintf' output between 2 and 16386 bytes into a destination of size 2 151 | #define ssh2_snprintf snprintf | ^~~~~~~~ tests/session_fixture.c:276:5: note: in expansion of macro 'ssh2_snprintf' 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~~~~~~~ ```
This time without using `MAXPATHLEN`, which is missing from GNU Hurd. Nor using other constants, but fixed 256 bytes on all platforms. Dynamic allocations almost looked good after good summer day of hair pulling, until I ran gcc-16, gcc-15, gcc-14 locally, in unity mode, where all 3 fell over with `-Wformat-truncate` false positives. This isn't worth all this amount of hassle. (It also fails in CI. What confused me is the last push only triggered AppVeyor CI and it went green. What a mess.) Ref: https://darnassus.sceen.net/~hurd-web/faq/foo_max/ Follow-up to 4cecccd #2102 Follow-up to aae3776 #2089 Follow-up to 12427f4 #1415 Fixing: gcc-13 (in CI): https://github.com/libssh2/libssh2/actions/runs/27913275531/job/82594004458 ``` tests/session_fixture.c: In function ‘srcdir_path’: tests/session_fixture.c:276:50: error: ‘%s’ directive output may be truncated writing likely 1 or more bytes into a region of size between 0 and 1 [-Werror=format-truncation=] 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~ tests/session_fixture.c:276:46: note: assuming directive output of 1 byte 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~ In file included from tests/session_fixture.h:45, from tests/runner.h:44, from tests/runner.c:40, from bld/tests/CMakeFiles/runner.dir/Unity/unity_0_c.c:4: src/libssh2_priv.h:151:23: note: ‘snprintf’ output 2 or more bytes (assuming 4) into a destination of size 2 151 | #define ssh2_snprintf snprintf tests/session_fixture.c:276:5: note: in expansion of macro ‘ssh2_snprintf’ 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~~~~~~~ ``` gcc-14, gcc-15: ``` tests/session_fixture.c: In function 'srcdir_path': tests/session_fixture.c:276:46: error: '%s' directive output may be truncated writing likely 1 or more bytes into a region of size between 0 and 1 [-Werror=format-truncation=] 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~ tests/session_fixture.c:276:5: note: in expansion of macro 'ssh2_snprintf' 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~~~~~~~ In file included from bld/tests/CMakeFiles/runner.dir/Unity/unity_0_c.c:7: tests/session_fixture.c:276:50: note: format string is defined here 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~ tests/session_fixture.c:276:46: note: assuming directive output of 1 byte 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~ tests/session_fixture.c:276:5: note: in expansion of macro 'ssh2_snprintf' 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~~~~~~~ src/libssh2_priv.h:151:23: note: '__builtin_snprintf' output 2 or more bytes (assuming 4) into a destination of size 2 151 | #define ssh2_snprintf snprintf | ^~~~~~~~ tests/session_fixture.c:276:5: note: in expansion of macro 'ssh2_snprintf' 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~~~~~~~ ``` gcc-16: ``` tests/session_fixture.c: In function 'srcdir_path': tests/session_fixture.c:276:46: error: '%s' directive output may be truncated writing up to 8192 bytes into a region of size 2 [-Werror=format-truncation=] 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~ tests/session_fixture.c:276:5: note: in expansion of macro 'ssh2_snprintf' 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~~~~~~~ In file included from bld/tests/CMakeFiles/runner.dir/Unity/unity_0_c.c:7: tests/session_fixture.c:276:47: note: format string is defined here 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~ src/libssh2_priv.h:151:23: note: '__builtin_snprintf' output between 2 and 16386 bytes into a destination of size 2 151 | #define ssh2_snprintf snprintf | ^~~~~~~~ tests/session_fixture.c:276:5: note: in expansion of macro 'ssh2_snprintf' 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~~~~~~~ ``` Closes #2106
MAXPATHLENis not present in some systems, e.g. GNU Hurd.Fixes #1414
Closes #1415