1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-08-07 08:02:56 +03:00

checksrc: update and fix warnings (#890)

Update from:
5fec927374/scripts/checksrc.pl

- suppress these new checks:

  - EQUALSNULL: 320 warnings
  - NOTEQUALSZERO: 142 warnings
  - TYPEDEFSTRUCT: 16 warnings

  We can enabled them in the future.

- fix all other new ones.

- also fix whitespace in two `NMakefile` files.
This commit is contained in:
Viktor Szakats
2023-03-28 09:37:46 +02:00
committed by GitHub
parent 480965e2d9
commit 4b800182c5
16 changed files with 272 additions and 97 deletions

View File

@@ -30,4 +30,3 @@ win32\objects.mk: Makefile.inc
@echo OBJECTS = \>$@ @echo OBJECTS = \>$@
@for %O in ($(OBJECTS)) do @echo $$(INTDIR)\%O \>>$@ @for %O in ($(OBJECTS)) do @echo $$(INTDIR)\%O \>>$@
@echo $$(EOL)>>$@ @echo $$(EOL)>>$@

View File

@@ -6,11 +6,11 @@
# | (__| |_| | _ <| |___ # | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____| # \___|\___/|_| \_\_____|
# #
# Copyright (C) 2011 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
# #
# This software is licensed as described in the file COPYING, which # This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms # you should have received as part of this distribution. The terms
# are also available at https://curl.haxx.se/docs/copyright.html. # are also available at https://curl.se/docs/copyright.html.
# #
# You may opt to use, copy, modify, merge, publish, distribute and/or sell # You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is # copies of the Software, and permit persons to whom the Software is
@@ -19,6 +19,8 @@
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied. # KIND, either express or implied.
# #
# SPDX-License-Identifier: curl
#
########################################################################### ###########################################################################
use strict; use strict;
@@ -31,14 +33,14 @@ my $warnings = 0;
my $swarnings = 0; my $swarnings = 0;
my $errors = 0; my $errors = 0;
my $serrors = 0; my $serrors = 0;
my $suppressed; # whitelisted problems my $suppressed; # skipped problems
my $file; my $file;
my $dir="."; my $dir=".";
my $wlist=""; my $wlist="";
my @alist; my @alist;
my $windows_os = $^O eq 'MSWin32' || $^O eq 'msys' || $^O eq 'cygwin'; my $windows_os = $^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'msys';
my $verbose; my $verbose;
my %whitelist; my %skiplist;
my %ignore; my %ignore;
my %ignore_set; my %ignore_set;
@@ -47,47 +49,59 @@ my @ignore_line;
my %warnings_extended = ( my %warnings_extended = (
'COPYRIGHTYEAR' => 'copyright year incorrect', 'COPYRIGHTYEAR' => 'copyright year incorrect',
'STRERROR', => 'strerror() detected',
); );
my %warnings = ( my %warnings = (
'LONGLINE' => "Line longer than $max_column", 'ASSIGNWITHINCONDITION' => 'assignment within conditional expression',
'TABS' => 'TAB characters not allowed', 'ASTERISKNOSPACE' => 'pointer declared without space before asterisk',
'TRAILINGSPACE' => 'Trailing white space on the line', 'ASTERISKSPACE' => 'pointer declared with space after asterisk',
'BADCOMMAND' => 'bad !checksrc! instruction',
'BANNEDFUNC' => 'a banned function was used',
'BRACEELSE' => '} else on the same line',
'BRACEPOS' => 'wrong position for an open brace',
'BRACEWHILE' => 'A single space between open brace and while',
'COMMANOSPACE' => 'comma without following space',
'COMMENTNOSPACEEND' => 'no space before */',
'COMMENTNOSPACESTART' => 'no space following /*',
'COPYRIGHT' => 'file missing a copyright statement',
'CPPCOMMENTS' => '// comment detected', 'CPPCOMMENTS' => '// comment detected',
'SPACEBEFOREPAREN' => 'space before an open parenthesis', 'DOBRACE' => 'A single space between do and open brace',
'EMPTYLINEBRACE' => 'Empty line before the open brace',
'EQUALSNOSPACE' => 'equals sign without following space',
'EQUALSNULL' => 'if/while comparison with == NULL',
'EXCLAMATIONSPACE' => 'Whitespace after exclamation mark in expression',
'FOPENMODE' => 'fopen needs a macro for the mode string',
'INCLUDEDUP', => 'same file is included again',
'INDENTATION' => 'wrong start column for code',
'LONGLINE' => "Line longer than $max_column",
'MULTISPACE' => 'multiple spaces used when not suitable',
'NOSPACEEQUALS' => 'equals sign without preceding space',
'NOTEQUALSZERO', => 'if/while comparison with != 0',
'ONELINECONDITION' => 'conditional block on the same line as the if()',
'OPENCOMMENT' => 'file ended with a /* comment still "open"',
'PARENBRACE' => '){ without sufficient space',
'RETURNNOSPACE' => 'return without space',
'SEMINOSPACE' => 'semicolon without following space',
'SIZEOFNOPAREN' => 'use of sizeof without parentheses',
'SNPRINTF' => 'use of snprintf',
'SPACEAFTERPAREN' => 'space after open parenthesis', 'SPACEAFTERPAREN' => 'space after open parenthesis',
'SPACEBEFORECLOSE' => 'space before a close parenthesis', 'SPACEBEFORECLOSE' => 'space before a close parenthesis',
'SPACEBEFORECOMMA' => 'space before a comma', 'SPACEBEFORECOMMA' => 'space before a comma',
'RETURNNOSPACE' => 'return without space', 'SPACEBEFOREPAREN' => 'space before an open parenthesis',
'COMMANOSPACE' => 'comma without following space',
'BRACEELSE' => '} else on the same line',
'PARENBRACE' => '){ without sufficient space',
'SPACESEMICOLON' => 'space before semicolon', 'SPACESEMICOLON' => 'space before semicolon',
'BANNEDFUNC' => 'a banned function was used', 'TABS' => 'TAB characters not allowed',
'FOPENMODE' => 'fopen needs a macro for the mode string', 'TRAILINGSPACE' => 'Trailing whitespace on the line',
'BRACEPOS' => 'wrong position for an open brace', 'TYPEDEFSTRUCT' => 'typedefed struct',
'INDENTATION' => 'wrong start column for code',
'COPYRIGHT' => 'file missing a copyright statement',
'BADCOMMAND' => 'bad !checksrc! instruction',
'UNUSEDIGNORE' => 'a warning ignore was not used', 'UNUSEDIGNORE' => 'a warning ignore was not used',
'OPENCOMMENT' => 'file ended with a /* comment still "open"',
'ASTERISKSPACE' => 'pointer declared with space after asterisk',
'ASTERISKNOSPACE' => 'pointer declared without space before asterisk',
'ASSIGNWITHINCONDITION' => 'assignment within conditional expression',
'EQUALSNOSPACE' => 'equals sign without following space',
'NOSPACEEQUALS' => 'equals sign without preceding space',
'SEMINOSPACE' => 'semicolon without following space',
'MULTISPACE' => 'multiple spaces used when not suitable',
'SIZEOFNOPAREN' => 'use of sizeof without parentheses',
'SNPRINTF' => 'use of snprintf',
); );
sub readwhitelist { sub readskiplist {
open(W, "<$dir/checksrc.whitelist") or return; open(W, "<$dir/checksrc.skip") or return;
my @all=<W>; my @all=<W>;
for(@all) { for(@all) {
$windows_os ? $_ =~ s/\r?\n$// : chomp; $windows_os ? $_ =~ s/\r?\n$// : chomp;
$whitelist{$_}=1; $skiplist{$_}=1;
} }
close(W); close(W);
} }
@@ -115,10 +129,19 @@ sub readlocalfile {
} }
$warnings{$1} = $warnings_extended{$1}; $warnings{$1} = $warnings_extended{$1};
} }
elsif (/^\s*disable ([A-Z]+)$/) {
if(!defined($warnings{$1})) {
print STDERR "invalid warning specified in .checksrc: \"$1\"\n";
next;
}
# Accept-list
push @alist, $1;
}
else { else {
die "Invalid format in $dir/.checksrc on line $i\n"; die "Invalid format in $dir/.checksrc on line $i\n";
} }
} }
close($rcfile);
} }
sub checkwarn { sub checkwarn {
@@ -131,8 +154,8 @@ sub checkwarn {
# print STDERR "Dev! there's no description for $name!\n"; # print STDERR "Dev! there's no description for $name!\n";
#} #}
# checksrc.whitelist # checksrc.skip
if($whitelist{$line}) { if($skiplist{$line}) {
$nowarn = 1; $nowarn = 1;
} }
# !checksrc! controlled # !checksrc! controlled
@@ -176,7 +199,7 @@ sub checkwarn {
$file = shift @ARGV; $file = shift @ARGV;
while(1) { while(defined $file) {
if($file =~ /-D(.*)/) { if($file =~ /-D(.*)/) {
$dir = $1; $dir = $1;
@@ -217,17 +240,25 @@ if(!$file) {
print " -A[rule] Accept this violation, can be used multiple times\n"; print " -A[rule] Accept this violation, can be used multiple times\n";
print " -D[DIR] Directory to prepend file names\n"; print " -D[DIR] Directory to prepend file names\n";
print " -h Show help output\n"; print " -h Show help output\n";
print " -W[file] Whitelist the given file - ignore all its flaws\n"; print " -W[file] Skip the given file - ignore all its flaws\n";
print " -i<n> Indent spaces. Default: 2\n"; print " -i<n> Indent spaces. Default: 2\n";
print " -m<n> Maximum line length. Default: 79\n"; print " -m<n> Maximum line length. Default: 79\n";
print "\nDetects and warns for these problems:\n"; print "\nDetects and warns for these problems:\n";
for(sort keys %warnings) { my @allw = keys %warnings;
printf (" %-18s: %s\n", $_, $warnings{$_}); push @allw, keys %warnings_extended;
for my $w (sort @allw) {
if($warnings{$w}) {
printf (" %-18s: %s\n", $w, $warnings{$w});
} }
else {
printf (" %-18s: %s[*]\n", $w, $warnings_extended{$w});
}
}
print " [*] = disabled by default\n";
exit; exit;
} }
readwhitelist(); readskiplist();
readlocalfile(); readlocalfile();
do { do {
@@ -344,11 +375,15 @@ sub scanfile {
my $line = 1; my $line = 1;
my $prevl=""; my $prevl="";
my $l; my $prevpl="";
my $l = "";
my $prep = 0;
my $prevp = 0;
open(R, "<$file") || die "failed to open $file"; open(R, "<$file") || die "failed to open $file";
my $incomment=0; my $incomment=0;
my @copyright=(); my @copyright=();
my %includes;
checksrc_clear(); # for file based ignores checksrc_clear(); # for file based ignores
accept_violations(); accept_violations();
@@ -365,7 +400,8 @@ sub scanfile {
} }
# check for a copyright statement and save the years # check for a copyright statement and save the years
if($l =~ /\* +copyright .* \d\d\d\d/i) { if($l =~ /\* +copyright .* (\d\d\d\d|)/i) {
my $count = 0;
while($l =~ /([\d]{4})/g) { while($l =~ /([\d]{4})/g) {
push @copyright, { push @copyright, {
year => $1, year => $1,
@@ -373,6 +409,16 @@ sub scanfile {
col => index($l, $1), col => index($l, $1),
code => $l code => $l
}; };
$count++;
}
if(!$count) {
# year-less
push @copyright, {
year => -1,
line => $line,
col => index($l, $1),
code => $l
};
} }
} }
@@ -392,6 +438,18 @@ sub scanfile {
$line, length($1), $file, $l, "Trailing whitespace"); $line, length($1), $file, $l, "Trailing whitespace");
} }
# no space after comment start
if($l =~ /^(.*)\/\*\w/) {
checkwarn("COMMENTNOSPACESTART",
$line, length($1) + 2, $file, $l,
"Missing space after comment start");
}
# no space at comment end
if($l =~ /^(.*)\w\*\//) {
checkwarn("COMMENTNOSPACEEND",
$line, length($1) + 1, $file, $l,
"Missing space end comment end");
}
# ------------------------------------------------------------ # ------------------------------------------------------------
# Above this marker, the checks were done on lines *including* # Above this marker, the checks were done on lines *including*
# comments # comments
@@ -426,13 +484,37 @@ sub scanfile {
# comments # comments
# ------------------------------------------------------------ # ------------------------------------------------------------
# prev line was a preprocessor **and** ended with a backslash
if($prep && ($prevpl =~ /\\ *\z/)) {
# this is still a preprocessor line
$prep = 1;
goto preproc;
}
$prep = 0;
# crude attempt to detect // comments without too many false # crude attempt to detect // comments without too many false
# positives # positives
if($l =~ /^([^"\*]*)[^:"]\/\//) { if($l =~ /^(([^"\*]*)[^:"]|)\/\//) {
checkwarn("CPPCOMMENTS", checkwarn("CPPCOMMENTS",
$line, length($1), $file, $l, "\/\/ comment"); $line, length($1), $file, $l, "\/\/ comment");
} }
if($l =~ /^(\#\s*include\s+)([\">].*[>}"])/) {
my ($pre, $path) = ($1, $2);
if($includes{$path}) {
checkwarn("INCLUDEDUP",
$line, length($1), $file, $l, "duplicated include");
}
$includes{$path} = $l;
}
# detect and strip preprocessor directives
if($l =~ /^[ \t]*\#/) {
# preprocessor line
$prep = 1;
goto preproc;
}
my $nostr = nostrings($l); my $nostr = nostrings($l);
# check spaces after for/if/while/function call # check spaces after for/if/while/function call
if($nostr =~ /^(.*)(for|if|while| ([a-zA-Z0-9_]+)) \((.)/) { if($nostr =~ /^(.*)(for|if|while| ([a-zA-Z0-9_]+)) \((.)/) {
@@ -456,14 +538,57 @@ sub scanfile {
"$2 with space"); "$2 with space");
} }
} }
# check for '== NULL' in if/while conditions but not if the thing on
# the left of it is a function call
if($nostr =~ /^(.*)(if|while)(\(.*?)([!=]= NULL|NULL [!=]=)/) {
checkwarn("EQUALSNULL", $line,
length($1) + length($2) + length($3),
$file, $l, "we prefer !variable instead of \"== NULL\" comparisons");
}
if($nostr =~ /^((.*)(if) *\()(.*)\)/) { # check for '!= 0' in if/while conditions but not if the thing on
# the left of it is a function call
if($nostr =~ /^(.*)(if|while)(\(.*[^)]) != 0[^x]/) {
checkwarn("NOTEQUALSZERO", $line,
length($1) + length($2) + length($3),
$file, $l, "we prefer if(rc) instead of \"rc != 0\" comparisons");
}
# check spaces in 'do {'
if($nostr =~ /^( *)do( *)\{/ && length($2) != 1) {
checkwarn("DOBRACE", $line, length($1) + 2, $file, $l, "one space after do before brace");
}
# check spaces in 'do {'
elsif($nostr =~ /^( *)\}( *)while/ && length($2) != 1) {
checkwarn("BRACEWHILE", $line, length($1) + 2, $file, $l, "one space between brace and while");
}
if($nostr =~ /^((.*\s)(if) *\()(.*)\)(.*)/) {
my $pos = length($1); my $pos = length($1);
if($4 =~ / = /) { my $postparen = $5;
my $cond = $4;
if($cond =~ / = /) {
checkwarn("ASSIGNWITHINCONDITION", checkwarn("ASSIGNWITHINCONDITION",
$line, $pos+1, $file, $l, $line, $pos+1, $file, $l,
"assignment within conditional expression"); "assignment within conditional expression");
} }
my $temp = $cond;
$temp =~ s/\(//g; # remove open parens
my $openc = length($cond) - length($temp);
$temp = $cond;
$temp =~ s/\)//g; # remove close parens
my $closec = length($cond) - length($temp);
my $even = $openc == $closec;
if($l =~ / *\#/) {
# this is a #if, treat it differently
}
elsif($even && $postparen &&
($postparen !~ /^ *$/) && ($postparen !~ /^ *[,{&|\\]+/)) {
checkwarn("ONELINECONDITION",
$line, length($l)-length($postparen), $file, $l,
"conditional block on the same line");
}
} }
# check spaces after open parentheses # check spaces after open parentheses
if($l =~ /^(.*[a-z])\( /i) { if($l =~ /^(.*[a-z])\( /i) {
@@ -551,16 +676,22 @@ sub scanfile {
checkwarn("PARENBRACE", checkwarn("PARENBRACE",
$line, length($1)+1, $file, $l, "missing space after close paren"); $line, length($1)+1, $file, $l, "missing space after close paren");
} }
# check for "^{" with an empty line before it
if(($l =~ /^\{/) && ($prevl =~ /^[ \t]*\z/)) {
checkwarn("EMPTYLINEBRACE",
$line, 0, $file, $l, "empty line before open brace");
}
# check for space before the semicolon last in a line # check for space before the semicolon last in a line
if($l =~ /^(.*[^ ].*) ;$/) { if($l =~ /^(.*[^ ].*) ;$/) {
checkwarn("SPACESEMICOLON", checkwarn("SPACESEMICOLON",
$line, length($1), $file, $ol, "space before last semicolon"); $line, length($1), $file, $ol, "no space before semicolon");
} }
# scan for use of banned functions # scan for use of banned functions
if($l =~ /^(.*\W) if($l =~ /^(.*\W)
(gets| (gmtime|localtime|
gets|
strtok| strtok|
v?sprintf| v?sprintf|
(str|_mbs|_tcs|_wcs)n?cat| (str|_mbs|_tcs|_wcs)n?cat|
@@ -571,7 +702,18 @@ sub scanfile {
$line, length($1), $file, $ol, $line, length($1), $file, $ol,
"use of $2 is banned"); "use of $2 is banned");
} }
if($warnings{"STRERROR"}) {
# scan for use of banned strerror. This is not a BANNEDFUNC to
# allow for individual enable/disable of this warning.
if($l =~ /^(.*\W)(strerror)\s*\(/x) {
if($1 !~ /^ *\#/) {
# skip preprocessor lines
checkwarn("STRERROR",
$line, length($1), $file, $ol,
"use of $2 is banned");
}
}
}
# scan for use of snprintf for curl-internals reasons # scan for use of snprintf for curl-internals reasons
if($l =~ /^(.*\W)(v?snprintf)\s*\(/x) { if($l =~ /^(.*\W)(v?snprintf)\s*\(/x) {
checkwarn("SNPRINTF", checkwarn("SNPRINTF",
@@ -589,10 +731,9 @@ sub scanfile {
} }
} }
# check for open brace first on line but not first column # check for open brace first on line but not first column only alert
# only alert if previous line ended with a close paren and wasn't a cpp # if previous line ended with a close paren and it wasn't a cpp line
# line if(($prevl =~ /\)\z/) && ($l =~ /^( +)\{/) && !$prevp) {
if((($prevl =~ /\)\z/) && ($prevl !~ /^ *#/)) && ($l =~ /^( +)\{/)) {
checkwarn("BRACEPOS", checkwarn("BRACEPOS",
$line, length($1), $file, $ol, "badly placed open brace"); $line, length($1), $file, $ol, "badly placed open brace");
} }
@@ -600,11 +741,10 @@ sub scanfile {
# if the previous line starts with if/while/for AND ends with an open # if the previous line starts with if/while/for AND ends with an open
# brace, or an else statement, check that this line is indented $indent # brace, or an else statement, check that this line is indented $indent
# more steps, if not a cpp line # more steps, if not a cpp line
if($prevl =~ /^( *)((if|while|for)\(.*\{|else)\z/) { if(!$prevp && ($prevl =~ /^( *)((if|while|for)\(.*\{|else)\z/)) {
my $first = length($1); my $first = length($1);
# this line has some character besides spaces # this line has some character besides spaces
if(($l !~ /^ *#/) && ($l =~ /^( *)[^ ]/)) { if($l =~ /^( *)[^ ]/) {
my $second = length($1); my $second = length($1);
my $expect = $first+$indent; my $expect = $first+$indent;
if($expect != $second) { if($expect != $second) {
@@ -617,10 +757,10 @@ sub scanfile {
} }
# check for 'char * name' # check for 'char * name'
if(($l =~ /(^.*(char|int|long|void|curl_slist|CURL|CURLM|CURLMsg|curl_httppost) *(\*+)) (\w+)/) && ($4 ne "const")) { if(($l =~ /(^.*(char|int|long|void|CURL|CURLM|CURLMsg|[cC]url_[A-Za-z_]+|struct [a-zA-Z_]+) *(\*+)) (\w+)/) && ($4 !~ /^(const|volatile)$/)) {
checkwarn("ASTERISKNOSPACE", checkwarn("ASTERISKSPACE",
$line, length($1), $file, $ol, $line, length($1), $file, $ol,
"no space after declarative asterisk"); "space after declarative asterisk");
} }
# check for 'char*' # check for 'char*'
if(($l =~ /(^.*(char|int|long|void|curl_slist|CURL|CURLM|CURLMsg|curl_httppost|sockaddr_in|FILE)\*)/)) { if(($l =~ /(^.*(char|int|long|void|curl_slist|CURL|CURLM|CURLMsg|curl_httppost|sockaddr_in|FILE)\*)/)) {
@@ -675,6 +815,19 @@ sub scanfile {
"no space after semicolon"); "no space after semicolon");
} }
# typedef struct ... {
if($nostr =~ /^(.*)typedef struct.*{/) {
checkwarn("TYPEDEFSTRUCT",
$line, length($1)+1, $file, $ol,
"typedef'ed struct");
}
if($nostr =~ /(.*)! +(\w|\()/) {
checkwarn("EXCLAMATIONSPACE",
$line, length($1)+1, $file, $ol,
"space after exclamation mark");
}
# check for more than one consecutive space before open brace or # check for more than one consecutive space before open brace or
# question mark. Skip lines containing strings since they make it hard # question mark. Skip lines containing strings since they make it hard
# due to artificially getting multiple spaces # due to artificially getting multiple spaces
@@ -682,13 +835,13 @@ sub scanfile {
$nostr =~ /^(.*(\S)) + [{?]/i) { $nostr =~ /^(.*(\S)) + [{?]/i) {
checkwarn("MULTISPACE", checkwarn("MULTISPACE",
$line, length($1)+1, $file, $ol, $line, length($1)+1, $file, $ol,
"multiple space"); "multiple spaces");
print STDERR "L: $l\n";
print STDERR "nostr: $nostr\n";
} }
preproc:
$line++; $line++;
$prevl = $ol; $prevp = $prep;
$prevl = $ol if(!$prep);
$prevpl = $ol if($prep);
} }
if(!scalar(@copyright)) { if(!scalar(@copyright)) {
@@ -717,13 +870,18 @@ sub scanfile {
my $commityear = undef; my $commityear = undef;
@copyright = sort {$$b{year} cmp $$a{year}} @copyright; @copyright = sort {$$b{year} cmp $$a{year}} @copyright;
# if the file is modified, assume commit year this year
if(`git status -s -- $file` =~ /^ [MARCU]/) { if(`git status -s -- $file` =~ /^ [MARCU]/) {
$commityear = (localtime(time))[5] + 1900; $commityear = (localtime(time))[5] + 1900;
} }
elsif (`git rev-list --count origin/master..HEAD -- $file` !~ /^0/) { else {
my $grl = `git rev-list --max-count=1 --timestamp HEAD -- $file`; # min-parents=1 to ignore wrong initial commit in truncated repos
my $grl = `git rev-list --max-count=1 --min-parents=1 --timestamp HEAD -- $file`;
if($grl) {
chomp $grl;
$commityear = (localtime((split(/ /, $grl))[0]))[5] + 1900; $commityear = (localtime((split(/ /, $grl))[0]))[5] + 1900;
} }
}
if(defined($commityear) && scalar(@copyright) && if(defined($commityear) && scalar(@copyright) &&
$copyright[0]{year} != $commityear) { $copyright[0]{year} != $commityear) {

View File

@@ -5,4 +5,12 @@ set -e
FILES="src/*.[ch] include/*.h example/*.c tests/*.[ch]" FILES="src/*.[ch] include/*.h example/*.c tests/*.[ch]"
WHITELIST="-Wsrc/libssh2_config.h" WHITELIST="-Wsrc/libssh2_config.h"
perl ./ci/checksrc.pl -i4 -m79 -ASIZEOFNOPAREN -ASNPRINTF -ACOPYRIGHT -AFOPENMODE $WHITELIST $FILES perl ./ci/checksrc.pl -i4 -m79 \
-ASIZEOFNOPAREN \
-ASNPRINTF \
-ACOPYRIGHT \
-AFOPENMODE \
-AEQUALSNULL \
-ANOTEQUALSZERO \
-ATYPEDEFSTRUCT \
$WHITELIST $FILES

View File

@@ -275,9 +275,11 @@ int main(int argc, char *argv[])
* See /etc/termcap for more options. This is useful when opening * See /etc/termcap for more options. This is useful when opening
* an interactive shell. * an interactive shell.
*/ */
// if(libssh2_channel_request_pty(channel, "vanilla")) { #if 0
// fprintf(stderr, "Failed requesting pty\n"); if(libssh2_channel_request_pty(channel, "vanilla")) {
// } fprintf(stderr, "Failed requesting pty\n");
}
#endif
if(argc > 5) { if(argc > 5) {
if(libssh2_channel_exec(channel, argv[5])) { if(libssh2_channel_exec(channel, argv[5])) {
@@ -287,10 +289,12 @@ int main(int argc, char *argv[])
/* Instead of just running a single command with libssh2_channel_exec, /* Instead of just running a single command with libssh2_channel_exec,
* a shell can be opened on the channel instead, for interactive use. * a shell can be opened on the channel instead, for interactive use.
* You usually want a pty allocated first in that case (see above). */ * You usually want a pty allocated first in that case (see above). */
// if(libssh2_channel_shell(channel)) { #if 0
// fprintf(stderr, "Unable to request shell on allocated pty\n"); if(libssh2_channel_shell(channel)) {
// goto shutdown; fprintf(stderr, "Unable to request shell on allocated pty\n");
// } goto shutdown;
}
#endif
/* At this point the shell can be interacted with using /* At this point the shell can be interacted with using
* libssh2_channel_read() * libssh2_channel_read()

View File

@@ -27,4 +27,3 @@ $(RESOURCE): win32\libssh2.rc
$(RC) $(RCFLAGS) /Fo"$@" $? $(RC) $(RCFLAGS) /Fo"$@" $?
!include "win32/rules.mk" !include "win32/rules.mk"

View File

@@ -1104,7 +1104,6 @@ static int
kex_method_diffie_hellman_group16_sha512_key_exchange(LIBSSH2_SESSION *session, kex_method_diffie_hellman_group16_sha512_key_exchange(LIBSSH2_SESSION *session,
key_exchange_state_low_t key_exchange_state_low_t
* key_state) * key_state)
{ {
static const unsigned char p_value[512] = { static const unsigned char p_value[512] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2,
@@ -1194,7 +1193,6 @@ static int
kex_method_diffie_hellman_group18_sha512_key_exchange(LIBSSH2_SESSION *session, kex_method_diffie_hellman_group18_sha512_key_exchange(LIBSSH2_SESSION *session,
key_exchange_state_low_t key_exchange_state_low_t
* key_state) * key_state)
{ {
static const unsigned char p_value[1024] = { static const unsigned char p_value[1024] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2,

View File

@@ -3199,13 +3199,19 @@ _libssh2_curve25519_gen_k(_libssh2_bn **k,
} }
rc = EVP_PKEY_derive_init(server_key_ctx); rc = EVP_PKEY_derive_init(server_key_ctx);
if(rc <= 0) goto cleanExit; if(rc <= 0) {
goto cleanExit;
}
rc = EVP_PKEY_derive_set_peer(server_key_ctx, peer_key); rc = EVP_PKEY_derive_set_peer(server_key_ctx, peer_key);
if(rc <= 0) goto cleanExit; if(rc <= 0) {
goto cleanExit;
}
rc = EVP_PKEY_derive(server_key_ctx, NULL, &out_len); rc = EVP_PKEY_derive(server_key_ctx, NULL, &out_len);
if(rc <= 0) goto cleanExit; if(rc <= 0) {
goto cleanExit;
}
if(out_len != LIBSSH2_ED25519_KEY_LEN) { if(out_len != LIBSSH2_ED25519_KEY_LEN) {
rc = -1; rc = -1;

View File

@@ -2142,7 +2142,6 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session,
unsigned char **method, size_t *method_len, unsigned char **method, size_t *method_len,
unsigned char **pubkeydata, size_t *pubkeydata_len, unsigned char **pubkeydata, size_t *pubkeydata_len,
const char *privatekey, const char *passphrase) const char *privatekey, const char *passphrase)
{ {
loadpubkeydata p; loadpubkeydata p;
int ret; int ret;

View File

@@ -402,8 +402,12 @@ get_socket_nonblocking(libssh2_socket_t sockfd)
callstat = getsockopt(sockfd, SOL_SOCKET, SO_STATE, callstat = getsockopt(sockfd, SOL_SOCKET, SO_STATE,
(char *)&sockstat, &size); (char *)&sockstat, &size);
if(callstat == -1) return 0; if(callstat == -1) {
if((sockstat&SS_NBIO) != 0) return 1; return 0;
}
if((sockstat&SS_NBIO) != 0) {
return 1;
}
return 0; return 0;
#undef GETBLOCK #undef GETBLOCK