diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6349ffe3..99467a1a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -847,17 +847,17 @@ jobs: else options='-DCMAKE_C_COMPILER=gcc' fi + cflags='' if [ "${MATRIX_TEST}" = 'uwp' ]; then options+=' -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0' pacman --noconfirm --ask 20 --noprogressbar --sync --needed "mingw-w64-${MATRIX_ENV}-winstorecompat-git" specs="$(realpath gcc-specs-uwp)" gcc -dumpspecs | sed -e 's/-lmingwex/-lwindowsapp -lmingwex -lwindowsapp -lwindowsappcompat/' -e 's/-lmsvcrt/-lmsvcr120_app/' > "${specs}" - cflags="-specs=$(cygpath -w "${specs}") -DWINSTORECOMPAT -DWINAPI_FAMILY=WINAPI_FAMILY_APP" + cflags+=" -specs=$(cygpath -w "${specs}") -DWINSTORECOMPAT -DWINAPI_FAMILY=WINAPI_FAMILY_APP" elif [ "${MATRIX_TEST}" = 'no-options' ]; then options+=' -DLIBSSH2_NO_DEPRECATED=ON' - cflags='-DLIBSSH2_NO_MD5 -DLIBSSH2_NO_MD5_PEM -DLIBSSH2_NO_HMAC_RIPEMD -DLIBSSH2_DSA_ENABLE -DLIBSSH2_NO_AES_CBC -DLIBSSH2_NO_AES_CTR -DLIBSSH2_NO_BLOWFISH -DLIBSSH2_NO_RC4 -DLIBSSH2_NO_CAST -DLIBSSH2_NO_3DES' - else - cflags='' + cflags+=' -DLIBSSH2_NO_MD5 -DLIBSSH2_NO_MD5_PEM -DLIBSSH2_NO_HMAC_RIPEMD -DLIBSSH2_DSA_ENABLE' + cflags+=' -DLIBSSH2_NO_AES_CBC -DLIBSSH2_NO_AES_CTR -DLIBSSH2_NO_BLOWFISH -DLIBSSH2_NO_RC4 -DLIBSSH2_NO_CAST -DLIBSSH2_NO_3DES' fi cmake -B bld -G Ninja ${options} \ -DCMAKE_C_FLAGS="${cflags}" \ diff --git a/LICENSES/BSD-2-Clause.txt b/LICENSES/BSD-2-Clause.txt index 516f77e2..87ea4c28 100644 --- a/LICENSES/BSD-2-Clause.txt +++ b/LICENSES/BSD-2-Clause.txt @@ -1,9 +1,22 @@ Copyright -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: -1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/LICENSES/BSD-3-Clause.txt b/LICENSES/BSD-3-Clause.txt index 086d3992..4a71c637 100644 --- a/LICENSES/BSD-3-Clause.txt +++ b/LICENSES/BSD-3-Clause.txt @@ -1,11 +1,26 @@ Copyright (c) . -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: -1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. -3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. +3. Neither the name of the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/LICENSES/SAX-PD-2.0.txt b/LICENSES/SAX-PD-2.0.txt index ff21f43c..ad101f71 100644 --- a/LICENSES/SAX-PD-2.0.txt +++ b/LICENSES/SAX-PD-2.0.txt @@ -1,6 +1,9 @@ SAX IS FREE ----------- -I hereby abandon any property rights to SAX 2.0 (the Simple API for XML), and release all of the SAX 2.0 source code, compiled code, and documentation contained in this distribution into the Public Domain. SAX comes with NO WARRANTY or guarantee of fitness for any purpose. +I hereby abandon any property rights to SAX 2.0 (the Simple API for XML), and +release all of the SAX 2.0 source code, compiled code, and documentation +contained in this distribution into the Public Domain. SAX comes with NO +WARRANTY or guarantee of fitness for any purpose. David Megginson, Megginson Technologies Ltd. diff --git a/ci/spacecheck.pl b/ci/spacecheck.pl index 81da6221..7b80c4a6 100755 --- a/ci/spacecheck.pl +++ b/ci/spacecheck.pl @@ -26,6 +26,8 @@ use strict; use warnings; +use File::Basename; + my @tabs = ( "Makefile\\.[a-z]+\$", "m4/lib-.+\\.m4\$", @@ -40,6 +42,14 @@ my @need_crlf = ( my @double_empty_lines = ( ); +my @longline = ( + "^libssh2-style\.el\$", + "tests/key_.+\.pub\$", + "tests/openssh_server/authorized_keys\$", + "tests/openssh_server/ca_.+\.pub\$", + "tests/openssh_server/sshd_config\$", +); + my @non_ascii = ( "AUTHORS", "RELEASE-NOTES", @@ -63,52 +73,70 @@ sub eol_detect { my $lf = () = $content =~ /\n/g; if($cr > 0 && $lf == 0) { - return "cr"; + return 'cr'; } elsif($cr == 0 && $lf > 0) { - return "lf"; + return 'lf'; } elsif($cr == 0 && $lf == 0) { - return "bin"; + return 'bin'; } elsif($cr == $lf) { - return "crlf"; + return 'crlf'; } - return ""; + return ''; } +my $max_repeat_space = 79; +my $max_line_len = 192; +my $max_path_len = 64; +my $max_filename_len = 48; + my $issues = 0; -open(my $git_ls_files, '-|', 'git ls-files') or die "Failed running git ls-files: $!"; +open(my $git_ls_files, '-|', 'git', 'ls-files') or die "Failed running git ls-files: $!"; while(my $filename = <$git_ls_files>) { chomp $filename; + my @err = (); + + if(length($filename) > $max_path_len) { + push @err, sprintf('long (%d > %d) path', length($filename), $max_path_len); + } + + my $bn = basename($filename); + if(length($bn) > $max_filename_len) { + push @err, sprintf('long (%d > %d) filename', length($bn), $max_filename_len); + } + + if($filename !~ /^[A-Za-z0-9\/._-]+$/) { + push @err, sprintf("filename contains character(s) outside [A-Za-z0-9/._-]"); + } + open(my $fh, '<', $filename) or die "Cannot open '$filename': $!"; my $content = do { local $/; <$fh> }; close $fh; - my @err = (); - if(!fn_match($filename, @tabs) && $content =~ /\t/) { - push @err, "content: has tab"; + push @err, 'content: has tab'; } my $eol = eol_detect($content); - if($eol eq "") { - push @err, "content: has mixed EOL types"; + if($eol eq '') { + push @err, 'content: has mixed EOL types'; } - if($eol ne "crlf" && + if($eol ne 'crlf' && fn_match($filename, @need_crlf)) { - push @err, "content: must use CRLF EOL for this file type"; + push @err, 'content: must use CRLF EOL for this file type'; } - if($eol ne "lf" && $content ne "" && + if($eol ne 'lf' && $content ne '' && !fn_match($filename, @need_crlf)) { - push @err, "content: must use LF EOL for this file type"; + push @err, 'content: must use LF EOL for this file type'; } if($content =~ /[ \t]\n/) { @@ -121,30 +149,108 @@ while(my $filename = <$git_ls_files>) { } } - if($content ne "" && + if($content ne '' && $content !~ /\n\z/) { - push @err, "content: has no EOL at EOF"; + push @err, 'content: has no EOL at EOF'; } if($content =~ /\n\n\z/ || $content =~ /\r\n\r\n\z/) { - push @err, "content: has multiple EOL at EOF"; + push @err, 'content: has multiple EOL at EOF'; + } + + if((!fn_match($filename, @double_empty_lines) && + ($content =~ /\n\n\n/ || + $content =~ /\r\n\r\n\r\n/)) || + $content =~ />\n\n\n+[<#]/) { + my $line = 0; + my $blank = 0; + for my $l (split(/\n/, $content)) { + chomp $l; + $line++; + if($l =~ /^$/) { + if($blank) { + my $lineno = sprintf('duplicate empty line @ line %d', $line); + push @err, $lineno; + } + $blank = 1; + } + else { + $blank = 0; + } + } } if($content =~ /\n\n\n\n/ || $content =~ /\r\n\r\n\r\n\r\n/) { - push @err, "content: has 3 or more consecutive empty lines"; - } - - if(!fn_match($filename, @double_empty_lines)) { - if($content =~ /\n\n\n/ || - $content =~ /\r\n\r\n\r\n/) { - push @err, "content: has 2 consecutive empty lines"; + my $line = 0; + my $blank = 0; + for my $l (split(/\n/, $content)) { + chomp $l; + $line++; + if($l =~ /^$/) { + if($blank > 1) { + my $lineno = sprintf('3 or more consecutive empty lines @ line %d', $line); + push @err, $lineno; + } + $blank++; + } + else { + $blank = 0; + } } } + if(!fn_match($filename, @longline)) { + my $line = 0; + for my $l (split(/\n/, $content)) { + $line++; + if(length($l) > $max_line_len) { + push @err, sprintf('line %d: long (%d > %d) line', $line, length($l), $max_line_len); + } + } + } + + my $line = 0; + for my $l (split(/\n/, $content)) { + $line++; + if($l =~ /( {$max_repeat_space,})/) { + push @err, sprintf('line %d: repeat spaces (%d >= %d)', $line, length($1), $max_repeat_space); + } + } + + my $search = $content; + my $linepos = 0; + while($search =~ /[^ ] "\n *" [^ ]/) { + my $part = substr($search, 0, $+[0]); + $search = substr($search, $+[0]); + my $line = ($part =~ tr/\n//); + push @err, sprintf('line %d: double spaces in folded string', $linepos + $line); + $linepos += $line; + } + + $search = $content; + $linepos = 0; + while($search =~ /\n\n *}\n/) { + my $part = substr($search, 0, $+[0] - 1); + $search = substr($search, $+[0]); + my $line = ($part =~ tr/\n//); + push @err, sprintf("line %d: '}' preceded by empty line", $linepos + $line); + $linepos += $line + 1; + } + + $search = $content; + $linepos = 0; + while($search =~ /\n\{\n\n/) { + my $part = substr($search, 0, $+[0]); + $search = substr($search, $+[0]); + my $line = ($part =~ tr/\n//); + push @err, sprintf("line %d: top-level '{' followed by empty line", $linepos + $line); + $linepos += $line; + } + if($content =~ /([\x00-\x08\x0b\x0c\x0e-\x1f\x7f])/) { - push @err, "content: has binary contents"; + push @err, 'content: has binary contents'; } if(!fn_match($filename, @non_ascii) && @@ -152,7 +258,7 @@ while(my $filename = <$git_ls_files>) { my $non = $1; my $hex; for my $e (split(//, $non)) { - $hex .= sprintf("%s%02x", $hex ? " ": "", ord($e)); + $hex .= sprintf('%s%02x', $hex ? ' ': '', ord($e)); } my $line; for my $l (split(/\n/, $content)) { diff --git a/src/blowfish.c b/src/blowfish.c index 5fdb6520..10353757 100644 --- a/src/blowfish.c +++ b/src/blowfish.c @@ -514,7 +514,6 @@ Blowfish_expandstate(blf_ctx *c, const uint8_t *data, uint16_t databytes, c->S[i][k + 1] = datar; } } - } #ifdef _DEBUG_BLOWFISH diff --git a/src/channel.c b/src/channel.c index cc3009c7..afa15123 100644 --- a/src/channel.c +++ b/src/channel.c @@ -872,7 +872,6 @@ libssh2_channel_forward_accept(LIBSSH2_LISTENER *listener) BLOCK_ADJUST_ERRNO(ptr, listener->session, channel_forward_accept(listener)); return ptr; - } /* @@ -2682,7 +2681,6 @@ int _libssh2_channel_close(LIBSSH2_CHANNEL * channel) _libssh2_error(session, rc, "Would block sending close-channel"); return rc; - } else if(rc) { _libssh2_error(session, rc, @@ -2690,7 +2688,6 @@ int _libssh2_channel_close(LIBSSH2_CHANNEL * channel) "but closing anyway"); /* skip waiting for the response and fall through to LIBSSH2_CHANNEL_CLOSE below */ - } else channel->close_state = libssh2_NB_state_sent; diff --git a/src/kex.c b/src/kex.c index 180fc2db..e2947144 100644 --- a/src/kex.c +++ b/src/kex.c @@ -2200,7 +2200,6 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, ret = _libssh2_error(session, LIBSSH2_ERROR_KEX_FAILURE, "Unknown SHA digest for EC curve"); goto clean_exit; - } ret = finish_kex(session, exchange_state, digest_len, sha_algo_value); if(ret == LIBSSH2_ERROR_EAGAIN) { @@ -2518,7 +2517,7 @@ mlkem_nistp(LIBSSH2_SESSION *session, if(_libssh2_bn_to_bin(exchange_state->k, shared_secret + LIBSSH2_MLKEM_SHARED_SECRET_LEN)) { ret = _libssh2_error(session, LIBSSH2_ERROR_OUT_OF_BOUNDARY, - "Can't write shared secret"); + "Can't write shared secret"); goto clean_exit; } @@ -3756,7 +3755,6 @@ static int kexinit(LIBSSH2_SESSION * session) p += lang_sc_len; _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Sent first_kex_packet_follows: %02x", p[0])); - } #endif /* LIBSSH2DEBUG */ @@ -3781,7 +3779,6 @@ static int kexinit(LIBSSH2_SESSION * session) session->kexinit_state = libssh2_NB_state_idle; return _libssh2_error(session, rc, "Unable to send KEXINIT packet to remote host"); - } if(session->local.kexinit) { diff --git a/src/packet.c b/src/packet.c index b4ae55a9..8574c69b 100644 --- a/src/packet.c +++ b/src/packet.c @@ -266,7 +266,6 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data, else if(rc) { listen_state->state = libssh2_NB_state_idle; return _libssh2_error(session, rc, "Unable to send open failure"); - } listen_state->state = libssh2_NB_state_idle; return 0; @@ -1190,7 +1189,6 @@ libssh2_packet_add_jump_point1: channelp->local.id, channelp->remote.id)); } - } else if(len == strlen("exit-signal") && !memcmp("exit-signal", request, diff --git a/src/pem.c b/src/pem.c index b79d4805..557fd923 100644 --- a/src/pem.c +++ b/src/pem.c @@ -873,7 +873,6 @@ out: LIBSSH2_FREE(session, b64data); } return ret; - } static int diff --git a/src/scp.c b/src/scp.c index 9685d068..977906a4 100644 --- a/src/scp.c +++ b/src/scp.c @@ -900,7 +900,6 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, /* no NUL-termination needed, so memcpy will do */ memcpy(&session->scpSend_command[cmd_len], path, path_len); cmd_len += path_len; - } else { cmd_len += shell_quotearg(path, diff --git a/src/sftp.c b/src/sftp.c index 4ee73159..03a1ba25 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -1004,7 +1004,6 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) strncmp("posix-rename@openssh.com", (char *)extname, 24) == 0) { sftp_handle->posix_rename_version = extversion; } - } LIBSSH2_FREE(session, data); @@ -2317,7 +2316,6 @@ libssh2_sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer, BLOCK_ADJUST(rc, handle->sftp->channel->session, sftp_write(handle, buffer, count)); return rc; - } static int sftp_fsync(LIBSSH2_SFTP_HANDLE *handle) @@ -2641,7 +2639,6 @@ static void sftp_packet_flush(LIBSSH2_SFTP *sftp) LIBSSH2_FREE(session, zombie); zombie = next; } - } /* sftp_close_handle @@ -2733,7 +2730,6 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle) /* if it reaches this point with data unset, something unwanted happened for which we should have set an error code */ assert(rc); - } else { uint32_t retcode = _libssh2_ntohu32(data + 5); diff --git a/src/transport.c b/src/transport.c index e2603b1f..9511595b 100644 --- a/src/transport.c +++ b/src/transport.c @@ -232,7 +232,6 @@ fullpacket(LIBSSH2_SESSION * session, int encrypted /* 1 or 0 */ ) _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, "Failed MAC check")); session->fullpacket_macstate = LIBSSH2_MAC_INVALID; - } else if(etm) { /* MAC was ok and we start by decrypting the first block that @@ -968,7 +967,6 @@ send_existing(LIBSSH2_SESSION *session, const unsigned char *data, a send success now, so that we don't risk sending EAGAIN later which then would confuse the parent function */ return LIBSSH2_ERROR_NONE; - } else if(rc < 0) { /* nothing was sent */ diff --git a/src/wincng.c b/src/wincng.c index daecc362..7944b657 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -1958,7 +1958,6 @@ _libssh2_wincng_publickey_from_point(IN _libssh2_wincng_ecc_keytype keytype, IN _libssh2_ecdsa_point *point, OUT BCRYPT_KEY_HANDLE *key) { - int result = LIBSSH2_ERROR_NONE; NTSTATUS status; @@ -3150,7 +3149,6 @@ _libssh2_wincng_pub_priv_keyfile_parse(LIBSSH2_SESSION *session, else { ret = -1; } - } else { ret = -1;