php / pecl-networking-ssh2

Bindings for the libssh2 library
http://pecl.php.net/package/ssh2
Other
51 stars 61 forks source link

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

Open mrngm opened 1 year ago

mrngm commented 1 year ago

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)