Skip to content

Fix [s]size_t types in ssh2_scp_send, also check written bytes in ssh2_scp_recv #72

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mrngm
Copy link
Contributor

@mrngm mrngm commented Aug 18, 2023

Although the streams documentation indicates a return type of size_t (and a warning that the prototypes are out of date), the current implementation is ssize_t.

When using size_t, we get a build warning on this line (ignoring the small mismatch in line numbers):

/builds/xxxxx/php/ext/ssh2/ssh2_fopen_wrappers.c:1254:91: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
 1254 |    if ((justsent = libssh2_channel_write(remote_file, (buffer + sent), bytesread - sent)) < 0) {
      |                                                                                           ^

This PR ensures we use the correct types, both for the libssh2 library call libssh2_channel_write, as well as the internal PHP functions.

Moreover, I've added a check on the number of written bytes in the PHP function for ssh2_scp_recv. (If it's better to add this in another PR, let me know)

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.

1 participant