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

checksrc: update, check all sources, fix fallouts

update from curl:
cff75acfec/scripts/checksrc.pl

Closes #1457
This commit is contained in:
Viktor Szakats
2024-09-27 01:05:47 +02:00
parent d9c2e550ca
commit 1117b677a0
21 changed files with 667 additions and 513 deletions

View File

@ -1,3 +0,0 @@
disable FOPENMODE
disable SNPRINTF
disable TYPEDEFSTRUCT

View File

@ -81,6 +81,4 @@ gen-coverage:
coverage: init-coverage build-coverage gen-coverage
checksrc:
perl ci/checksrc.pl -i4 -m79 \
-Wsrc/libssh2_config.h \
src/*.[ch] include/*.h example/*.c tests/*.[ch]
ci/checksrc.sh

View File

@ -44,7 +44,6 @@ path = [
"vms/man2help.c",
"vms/readme.vms",
# dotfiles
".checksrc",
".editorconfig",
".gitignore",
"docs/.gitignore",

View File

@ -50,6 +50,7 @@ my @ignore_line;
my %warnings_extended = (
'COPYRIGHTYEAR' => 'copyright year incorrect',
'STRERROR', => 'strerror() detected',
'STRNCPY', => 'strncpy() detected',
'STDERR', => 'stderr detected',
);
@ -79,7 +80,10 @@ my %warnings = (
'LONGLINE' => "Line longer than $max_column",
'SPACEBEFORELABEL' => 'labels not at the start of the line',
'MULTISPACE' => 'multiple spaces used when not suitable',
'NOSPACEC' => 'missing space around ternary colon operator',
'NOSPACEEQUALS' => 'equals sign without preceding space',
'NOSPACEQ' => 'missing space around ternary question mark operator',
'NOSPACETHAN' => 'missing space around less or greater than',
'NOTEQUALSZERO', => 'if/while comparison with != 0',
'ONELINECONDITION' => 'conditional block on the same line as the if()',
'OPENCOMMENT' => 'file ended with a /* comment still "open"',
@ -115,11 +119,23 @@ sub readskiplist {
# and since that's already handled via !checksrc! commands there is probably
# little use to add it.
sub readlocalfile {
my ($file) = @_;
my $i = 0;
my $rcfile;
open(my $rcfile, "<", "$dir/.checksrc") or return;
if(($dir eq ".") && $file =~ /\//) {
my $ldir;
if($file =~ /(.*)\//) {
$ldir = $1;
open($rcfile, "<", "$dir/$ldir/.checksrc") or return;
}
}
else {
open($rcfile, "<", "$dir/.checksrc") or return;
}
while(<$rcfile>) {
$windows_os ? $_ =~ s/\r?\n$// : chomp;
$i++;
# Lines starting with '#' are considered comments
@ -263,7 +279,7 @@ if(!$file) {
}
readskiplist();
readlocalfile();
readlocalfile($file);
do {
if("$wlist" !~ / $file /) {
@ -403,6 +419,13 @@ sub scanfile {
checksrc($cmd, $line, $file, $l)
}
if($l =~ /^#line (\d+) \"([^\"]*)\"/) {
# a #line instruction
$file = $2;
$line = $1;
next;
}
# check for a copyright statement and save the years
if($l =~ /\* +copyright .* (\d\d\d\d|)/i) {
my $count = 0;
@ -603,6 +626,62 @@ sub scanfile {
"space after open parenthesis");
}
# check spaces before colon
if($nostr =~ /^(.*[^']\?[^'].*)(\w|\)|\]|')\:/i) {
my $m = $1;
my $e = $nostr;
$e =~ s/'(.)':'(.)'/$1:$2/g; # eliminate chars quotes that surround colon
$e =~ s/':'//g; # ignore these
if($e =~ /^(.*[^']\?[^'].*)(\w|\)|\]|')\:/i) {
checkwarn("NOSPACEC",
$line, length($m)+1, $file, $l,
"missing space before colon");
}
}
# check spaces after colon
if($nostr =~ /^(.*[^'"]\?[^'"].*)\:(\w|\)|\]|')/i) {
my $m = $1;
my $e = $nostr;
$e =~ s/'(.)':'(.)'/$1:$2/g; # eliminate chars quotes that surround colon
$e =~ s/':'//g; # ignore these
if($e =~ /^(.*[^'"]\?[^'"].*)\:(\w|\)|\]|')/i) {
checkwarn("NOSPACEC",
$line, length($m)+1, $file, $l,
"missing space after colon");
}
}
# check spaces before question mark
if($nostr =~ /^(.*)(\w|\)|\]|')\?/i) {
my $m = $1;
my $e = $nostr;
$e =~ s/'?'//g; # ignore these
if($e =~ /^(.*)(\w|\)|\]|')\?/i) {
checkwarn("NOSPACEQ",
$line, length($m)+1, $file, $l,
"missing space before question mark");
}
}
# check spaces after question mark
if($nostr =~ /^(.*)\?\w/i) {
checkwarn("NOSPACEQ",
$line, length($1)+1, $file, $l,
"missing space after question mark");
}
# check spaces before less or greater than
if($nostr =~ /^(.*)(\w|\)|\])[<>]/) {
checkwarn("NOSPACETHAN",
$line, length($1)+1, $file, $l,
"missing space before less or greater than");
}
# check spaces after less or greater than
if($nostr =~ /^(.*)[^-][<>](\w|\(|\[)/) {
checkwarn("NOSPACETHAN",
$line, length($1)+1, $file, $l,
"missing space after less or greater than");
}
# check spaces before close parentheses, unless it was a space or a
# close parenthesis!
if($l =~ /(.*[^\) ]) \)/) {
@ -712,7 +791,8 @@ sub scanfile {
strtok|
v?sprintf|
(str|_mbs|_tcs|_wcs)n?cat|
LoadLibrary(Ex)?(A|W)?)
LoadLibrary(Ex)?(A|W)?|
_?w?access)
\s*\(
/x) {
checkwarn("BANNEDFUNC",
@ -731,6 +811,18 @@ sub scanfile {
}
}
}
if($warnings{"STRNCPY"}) {
# scan for use of banned strncpy. This is not a BANNEDFUNC to
# allow for individual enable/disable of this warning.
if($l =~ /^(.*\W)(strncpy)\s*\(/x) {
if($1 !~ /^ *\#/) {
# skip preprocessor lines
checkwarn("STRNCPY",
$line, length($1), $file, $ol,
"use of $2 is banned");
}
}
}
if($warnings{"STDERR"}) {
# scan for use of banned stderr. This is not a BANNEDFUNC to
# allow for individual enable/disable of this warning.
@ -915,7 +1007,7 @@ sub scanfile {
checkwarn("COPYRIGHT", 1, 0, $file, "", "Missing copyright statement", 1);
}
# COPYRIGHTYEAR is a extended warning so we must first see if it has been
# COPYRIGHTYEAR is an extended warning so we must first see if it has been
# enabled in .checksrc
if(defined($warnings{"COPYRIGHTYEAR"})) {
# The check for updated copyrightyear is overly complicated in order to

View File

@ -6,6 +6,5 @@ set -e
cd "$(dirname "$0")/.."
perl ./ci/checksrc.pl -i4 -m79 \
-Wsrc/libssh2_config.h \
src/*.[ch] include/*.h example/*.c tests/*.[ch]
git ls-files "*.[ch]" | xargs -n1 \
./ci/checksrc.pl -i4 -m79 -AFOPENMODE -ASNPRINTF -ATYPEDEFSTRUCT

View File

@ -98,7 +98,7 @@ terminator_size(unsigned short ccsid)
/* Convert an UTF-8 NUL to the target CCSID: use the converted size as
result. */
memset((void *) &outcode, 0, sizeof outcode);
memset((void *) &outcode, 0, sizeof(outcode));
outcode.CCSID = ccsid;
cd = QtqIconvOpen(&outcode, (QtqCode_T *) &utf8code);
if(cd.return_value == -1)
@ -106,10 +106,10 @@ terminator_size(unsigned short ccsid)
inp = "";
ilen = 1;
outp = buf;
olen = sizeof buf;
olen = sizeof(buf);
iconv(cd, &inp, &ilen, &outp, &olen);
iconv_close(cd);
olen = sizeof buf - olen;
olen = sizeof(buf - olen);
return olen ? olen : -1;
}
@ -148,8 +148,8 @@ convert_ccsid(LIBSSH2_SESSION *session, libssh2_string_cache **cache,
return NULL;
/* Prepare conversion parameters. */
memset((void *) &incode, 0, sizeof incode);
memset((void *) &outcode, 0, sizeof outcode);
memset((void *) &incode, 0, sizeof(incode));
memset((void *) &outcode, 0, sizeof(outcode));
incode.CCSID = inccsid;
outcode.CCSID = outccsid;
curlen = OFFSET_OF(libssh2_string_cache, string);

View File

@ -102,11 +102,13 @@ libssh2_channel_subsystem(LIBSSH2_CHANNEL *channel, const char *subsystem);
LIBSSH2_API ssize_t
libssh2_channel_read(LIBSSH2_CHANNEL *channel, char *buf, size_t buflen);
LIBSSH2_API ssize_t
libssh2_channel_read_stderr(LIBSSH2_CHANNEL *channel, char *buf, size_t buflen);
libssh2_channel_read_stderr(LIBSSH2_CHANNEL *channel,
char *buf, size_t buflen);
LIBSSH2_API unsigned long
libssh2_channel_window_read(LIBSSH2_CHANNEL *channel);
LIBSSH2_API ssize_t
libssh2_channel_write(LIBSSH2_CHANNEL *channel, const char *buf, size_t buflen);
libssh2_channel_write(LIBSSH2_CHANNEL *channel,
const char *buf, size_t buflen);
LIBSSH2_API ssize_t
libssh2_channel_write_stderr(LIBSSH2_CHANNEL *channel,
const char *buf, size_t buflen);

View File

@ -79,7 +79,6 @@
static int
convert_sockaddr(struct sockaddr_storage *dstaddr,
const struct sockaddr *srcaddr, int srclen)
{
const struct sockaddr_un *srcu;
struct sockaddr_un *dstu;
@ -89,7 +88,7 @@ convert_sockaddr(struct sockaddr_storage * dstaddr,
/* Convert a socket address into job CCSID, if needed. */
if(!srcaddr || srclen < offsetof(struct sockaddr, sa_family) +
sizeof srcaddr->sa_family || srclen > sizeof *dstaddr) {
sizeof(srcaddr->sa_family) || srclen > sizeof(*dstaddr)) {
errno = EINVAL;
return -1;
}
@ -101,9 +100,10 @@ convert_sockaddr(struct sockaddr_storage * dstaddr,
case AF_UNIX:
srcu = (const struct sockaddr_un *) srcaddr;
dstu = (struct sockaddr_un *) dstaddr;
dstsize = sizeof *dstaddr - offsetof(struct sockaddr_un, sun_path);
dstsize = sizeof(*dstaddr) - offsetof(struct sockaddr_un, sun_path);
srclen -= offsetof(struct sockaddr_un, sun_path);
i = QadrtConvertA2E(dstu->sun_path, srcu->sun_path, dstsize - 1, srclen);
i = QadrtConvertA2E(dstu->sun_path, srcu->sun_path,
dstsize - 1, srclen);
dstu->sun_path[i] = '\0';
i += offsetof(struct sockaddr_un, sun_path);
srclen = i;
@ -115,7 +115,6 @@ convert_sockaddr(struct sockaddr_storage * dstaddr,
int
_libssh2_os400_connect(int sd, struct sockaddr *destaddr, int addrlen)
{
int i;
struct sockaddr_storage laddr;
@ -151,6 +150,7 @@ _libssh2_os400_vsnprintf(char *dst, size_t len, const char *fmt, va_list args)
return -1;
}
/* !checksrc! disable BANNEDFUNC 1 */ /* FIXME */
i = vsprintf(buf, fmt, args);
if(i < 0)

View File

@ -1,3 +1,7 @@
/* Copyright (C) The libssh2 project and its contributors.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <assert.h>
#include <errno.h>
#include <stdbool.h>

View File

@ -1,3 +1,7 @@
/* Copyright (C) The libssh2 project and its contributors.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdio.h>
#include <stdlib.h>

View File

@ -1,3 +1,7 @@
/* Copyright (C) The libssh2 project and its contributors.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <inttypes.h>
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);

View File

@ -1,3 +1,8 @@
/* Copyright (C) The libssh2 project and its contributors.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef LIBSSH2_CONFIG_H
#ifdef __VMS

View File

@ -1,3 +1,8 @@
/* Copyright (C) The libssh2 project and its contributors.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -34,7 +39,8 @@ if ( len ){
*os = *is;
}
*os = 0;
}else{
}
else {
output[0] = 0;
}
}
@ -64,8 +70,8 @@ pf->dfab.fab$l_dna = (char *) -1;
pf->dfab.fab$b_fns = 0;
pf->dfab.fab$w_ifi = 0;
pf->dnam.naml$l_long_defname = NULL; //inputfile;
pf->dnam.naml$l_long_defname_size = 0;//strlen( inputfile );
pf->dnam.naml$l_long_defname = NULL; /* inputfile; */
pf->dnam.naml$l_long_defname_size = 0; /* strlen(inputfile); */
pf->dnam.naml$l_long_filename = inputfile;
pf->dnam.naml$l_long_filename_size = strlen(inputfile);
@ -78,27 +84,34 @@ pf->dnam.naml$b_nop |= NAML$M_SYNCHK | NAML$M_PWD;
status = sys$parse(&pf->dfab, 0, 0);
if(!(status&1)) {
free(pf);
return( status );
return status;
}
fpcopy ( ipart[0], pf->dnam.naml$l_long_node , pf->dnam.naml$l_long_node_size);
fpcopy ( ipart[1], pf->dnam.naml$l_long_dev , pf->dnam.naml$l_long_dev_size);
fpcopy ( ipart[2], pf->dnam.naml$l_long_dir , pf->dnam.naml$l_long_dir_size);
fpcopy ( ipart[3], pf->dnam.naml$l_long_name , pf->dnam.naml$l_long_name_size);
fpcopy ( ipart[4], pf->dnam.naml$l_long_type , pf->dnam.naml$l_long_type_size);
fpcopy ( ipart[5], pf->dnam.naml$l_long_ver , pf->dnam.naml$l_long_ver_size);
fpcopy(ipart[0], pf->dnam.naml$l_long_node,
pf->dnam.naml$l_long_node_size);
fpcopy(ipart[1], pf->dnam.naml$l_long_dev,
pf->dnam.naml$l_long_dev_size);
fpcopy(ipart[2], pf->dnam.naml$l_long_dir,
pf->dnam.naml$l_long_dir_size);
fpcopy(ipart[3], pf->dnam.naml$l_long_name,
pf->dnam.naml$l_long_name_size);
fpcopy(ipart[4], pf->dnam.naml$l_long_type,
pf->dnam.naml$l_long_type_size);
fpcopy(ipart[5], pf->dnam.naml$l_long_ver,
pf->dnam.naml$l_long_ver_size);
for(i = ipart[whatpart], p = part; *i; ++i, ++p) {
if(p == part) {
*p = toupper(*i);
}else{
}
else {
*p = tolower(*i);
}
}
*p = 0;
free(pf);
return(1);
return 1;
}
/*----------------------------------------------------------*/
@ -122,12 +135,14 @@ gevondend.dsc$a_pointer = gevonden_file;
status = lib$find_file(&filespec, &gevondend, findex, 0, 0, 0, 0);
if((status & 1) == 1) {
/* !checksrc! disable BANNEDFUNC 1 */ /* FIXME */
strcpy(gevonden, strtok(gevonden_file, " "));
}else{
}
else {
gevonden[0] = 0;
}
return(status);
return status;
}
@ -138,17 +153,20 @@ manPtr addman( manPtr *manroot,char *filename )
manPtr m, f;
m = calloc(1, sizeof(man));
if ( !m ) return( NULL );
if(!m)
return NULL;
m->filename = strdup(filename);
if ( *manroot == NULL ){
if(!*manroot) {
*manroot = m;
}else{
for( f = *manroot; f->next ; f = f->next );
}
else {
for(f = *manroot; f->next; f = f->next)
;
f->next = m;
}
return(m);
return m;
}
/*--------------------------------------------*/
@ -173,22 +191,25 @@ int status;
int ffindex = 0;
char gevonden[NAM$C_MAXRSS + 1];
while(1){
for(;;) {
status = find_file(filespec, gevonden, &ffindex);
if((status&1)) {
r = addman(manroot, gevonden);
if ( r == NULL ) return(2);
}else{
if ( !( status&1 ) ) break;
if(!r)
return 2;
}
else {
if(!(status&1))
break;
}
}
lib$find_file_end(&ffindex);
if ( status == RMS$_NMF) status = 1;
if(status == RMS$_NMF)
status = 1;
return( status );
return status;
}
/*--------------------------------------------*/
@ -205,10 +226,12 @@ char subjectname[ NAM$C_MAXRSS + 1 ];
in = calloc(1, maxlen + 1);
uit = calloc(1, maxlen + 1);
if ( in == NULL || uit == NULL ) return(2);
if(!in || !uit)
return 2;
man = fopen(filespec, "r");
if ( man == NULL ) return(vaxc$errno);
if(!man)
return vaxc$errno;
for(len = 0; !feof(man) && len < maxlen; len += thislen) {
thislen = fread(in + len, 1, maxlen - len, man);
@ -229,7 +252,8 @@ for ( mode = 0, bol = 1 ; *m; ++m ){
case '.':
if(bol) {
mode = 1;
}else{
}
else {
*h = *m;
++h;
}
@ -251,11 +275,12 @@ for ( mode = 0, bol = 1 ; *m; ++m ){
break;
}
break;
case 1: /* after . at bol */
case 1: /* after . at bol */
switch(*m) {
case '\\':
while( *m != '\n' && *m != '\r' && *m )++m;
while(*m != '\n' && *m != '\r' && *m)
++m;
mode = 0;
break;
case 'B':
@ -267,26 +292,31 @@ for ( mode = 0, bol = 1 ; *m; ++m ){
/* remove preceding eol */
if(*(m + 1) != 'P') {
--h;
while ( (*h == '\n' || *h == '\r') && h > uit )--h;
while((*h == '\n' || *h == '\r') && h > uit)
--h;
++h;
}
/* skip .Ix */
for(;*m != ' ' && *m != '\n' && *m != '\r'; ++m);
for(; *m != ' ' && *m != '\n' && *m != '\r'; ++m)
;
/* copy line up to EOL */
for(;*m != '\n' && *m != '\r' && *m; ++m, ++h)*h = *m;
for(; *m != '\n' && *m != '\r' && *m; ++m, ++h)
*h = *m;
/* if line ends in ., this is an EOL */
if(*(h-1) == '.') {
--h;
--m;
}else{
}
else {
/* if line does not end in ., skip EOL in source */
if ( *(m+1) == '\n' || *(m+1) == '\r')++m;
if(*(m + 1) == '\n' || *(m + 1) == '\r')
++m;
}
mode = 0;
break;
@ -296,9 +326,11 @@ for ( mode = 0, bol = 1 ; *m; ++m ){
if(strncmp(m + 3, "NAME", 4) == 0 ||
strncmp(m + 3, "SYNOPSIS", 8) == 0 ||
strncmp(m + 3, "DESCRIPTION", 11) == 0) {
while( *m != '\n' && *m != '\r')++m;
while(*m != '\n' && *m != '\r')
++m;
mode = 0;
}else{
}
else {
++m;
/* write help level, and flag it */
@ -318,8 +350,10 @@ for ( mode = 0, bol = 1 ; *m; ++m ){
if(*m != '\"') {
*h = tolower(*m);
if (*h == ' ') *h = '_';
}else{
if(*h == ' ')
*h = '_';
}
else {
--h;
}
}
@ -345,7 +379,8 @@ for ( mode = 0, bol = 1 ; *m; ++m ){
*h = '('; ++h;
*h = ')'; ++h;
}
while( *m != '\n' && *m != '\r' && *m )++m;
while(*m != '\n' && *m != '\r' && *m)
++m;
mode = 0;
}
break;
@ -371,25 +406,31 @@ for ( mode = 0, bol = 1 ; *m; ++m ){
} /* end switch mode */
bol = 0;
if ( *m == '\n' || *m == '\r') bol = 1;
if(*m == '\n' || *m == '\r')
bol = 1;
} /* end for mode */
*h = 0;
if ( (return_status&2) ){
if(return_status & 2) {
fprintf(hlp, "%s\n\n", uit);
}else{
}
else {
fnamepart(filespec, subjectname, 3);
if(*subjectname) {
fprintf(hlp, "%d %s\n\n%s\n\n", base_level, subjectname, uit);
}else{
/* No filename (as is the case with a logical), use first word as subject name */
}
else {
/* No filename (as is the case with a logical),
use first word as subject name */
char *n, *s;
for(n = in; isspace( *n );++n);
for(s = subjectname; !(isspace( *n )); ++n,++s)*s = *n;
for(n = in; isspace(*n); ++n)
;
for(s = subjectname; !(isspace(*n)); ++n, ++s)
*s = *n;
*s = 0;
fprintf(hlp, "%d %s\n\n%s\n\n", base_level, subjectname, uit);
@ -404,12 +445,13 @@ if ( (return_status&2) ){
free(m);
free(h);
return ( 1 );
return 1;
}
/*--------------------------------------------*/
int convertmans( char *filespec, char *hlpfilename, int base_level, int append, int add_parentheses )
int convertmans(char *filespec, char *hlpfilename, int base_level, int append,
int add_parentheses)
{
int status = 1;
manPtr manroot = NULL, m;
@ -417,14 +459,17 @@ FILE *hlp;
if(append) {
hlp = fopen(hlpfilename, "a+");
}else{
}
else {
hlp = fopen(hlpfilename, "w");
}
if ( hlp == NULL ) return( vaxc$errno );
if(!hlp)
return vaxc$errno;
status = listofmans(filespec, &manroot);
if ( !(status&1) ) return( status );
if(!(status&1))
return status;
for(m = manroot; m; m = m->next) {
status = convertman(m->filename, hlp, base_level, add_parentheses);
@ -434,18 +479,19 @@ for ( m = manroot ; m ; m = m->next ){
}
}
freeman(&manroot);
return( status );
return status;
}
/*--------------------------------------------*/
void print_help()
void print_help(void)
{
fprintf( stderr, "Usage: [-a] [-b x] convertman <manfilespec> <helptextfile>\n" );
fprintf( stderr, " -a append <manfilespec> to <helptextfile>\n" );
fprintf( stderr, " -b <baselevel> if no headers found create one with level <baselevel>\n" );
fprintf( stderr, " and the filename as title.\n" );
fprintf( stderr, " -p add parentheses() to baselevel help items.\n" );
fprintf(stderr,
"Usage: [-a] [-b x] convertman <manfilespec> <helptextfile>\n"
" -a append <manfilespec> to <helptextfile>\n"
" -b <baselevel> if no headers found create one "
"with level <baselevel>\n"
" and the filename as title.\n"
" -p add parentheses() to baselevel help items.\n");
}
/*--------------------------------------------*/
@ -459,7 +505,7 @@ char *helpfile=NULL;
if(argc < 3) {
print_help();
return( 1 ) ;
return 1;
}
append = 0;
@ -489,26 +535,30 @@ for ( i = 1; i < argc; ++i){
basechange = 0;
i = i + 1;
}
}else{
if ( manfile == NULL ){
}
else {
if(!manfile) {
manfile = strdup(argv[i]);
} else if ( helpfile == NULL ){
}
else if(!helpfile) {
helpfile = strdup(argv[i]);
} else {
}
else {
fprintf(stderr, "Unrecognized parameter : %s\n", argv[i]);
}
}
}
/* fprintf( stderr,"manfile: %s, helpfile: %s, append: %d, base_level : %d\n",
/*
fprintf(stderr,"manfile: %s, helpfile: %s, append: %d, base_level : %d\n",
manfile, helpfile, append, base_level);
*/
status = convertmans( manfile, helpfile, base_level, append, add_parentheses );
status = convertmans(manfile, helpfile, base_level, append,
add_parentheses);
free(manfile);
free(helpfile);
return( status );
return status;
}