Skip to content

tests: tidy up srcdir_path() more - #2102

Closed
vszakats wants to merge 3 commits into
libssh2:masterfrom
vszakats:t-fix-path-buff
Closed

vszakats wants to merge 3 commits into
libssh2:masterfrom
vszakats:t-fix-path-buff

Conversation

@vszakats

@vszakats vszakats commented Jun 21, 2026 •

Copy link
Copy Markdown
Member

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


https://github.com/libssh2/libssh2/pull/2102/files?w=1

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR refines the tests’ srcdir_path() helper to make its contract clearer (returning a const char *) and to fail fast via assertions when invariants are violated, as a follow-up to prior fixes around slot handling and cleanup.

Changes:

  • Update srcdir_path() API to return const char * (header + implementation).
  • Replace several error-return paths with assert() checks and simplify/flatten the control flow.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
tests/session_fixture.h Changes srcdir_path() declaration to return const char *.
tests/session_fixture.c Updates srcdir_path() definition; switches to assert-based invariants and flattens logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/session_fixture.c Resolved
Comment thread tests/session_fixture.c Resolved
Comment thread tests/session_fixture.c Resolved
@vszakats vszakats changed the title tests: more srcdir_path() fixes tests: revert to fixed-length path in srcdir_path() Jun 21, 2026
@vszakats vszakats changed the title tests: revert to fixed-length path in srcdir_path() tests: revert to fixed-length paths in srcdir_path() Jun 21, 2026
@vszakats vszakats changed the title tests: revert to fixed-length paths in srcdir_path() tests: revert to fixed-length path buffers in srcdir_path() Jun 21, 2026
@vszakats
vszakats requested a review from Copilot June 21, 2026 14:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread tests/session_fixture.c Resolved
Comment thread tests/session_fixture.c Resolved
@vszakats
vszakats force-pushed the t-fix-path-buff branch 3 times, most recently from 14a65f3 to 31bf2bb Compare June 21, 2026 16:15
@vszakats
vszakats marked this pull request as draft June 21, 2026 16:15
@vszakats
vszakats requested a review from Copilot June 21, 2026 16:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread tests/session_fixture.c Resolved
Comment thread tests/session_fixture.c Resolved
session_fixture.c de-xmas-tree srcdir_path
session_fixture.c constify srcdir_path return value again
session_fixture.c constify more
@vszakats vszakats changed the title tests: revert to fixed-length path buffers in srcdir_path() tests: tidy up srcdir_path() more Jun 21, 2026
@vszakats
vszakats requested a review from Copilot June 21, 2026 17:03
@vszakats
vszakats marked this pull request as ready for review June 21, 2026 17:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread tests/session_fixture.c Resolved
Comment thread tests/session_fixture.c Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread tests/session_fixture.c Resolved
@vszakats vszakats closed this in 4cecccd Jun 21, 2026
@vszakats
vszakats deleted the t-fix-path-buff branch June 21, 2026 18:18
vszakats added a commit to vszakats/libssh2 that referenced this pull request Jun 21, 2026
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);
      |     ^~~~~~~~~~~~~
```
vszakats added a commit that referenced this pull request Jun 21, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants