Latest update.

This commit is contained in:
2020-04-15 18:45:34 +09:00
parent be29e7bcc6
commit 2015c00c43
573 changed files with 22943 additions and 6714 deletions
+717
View File
@@ -0,0 +1,717 @@
/*
* Copyright 2007-2019 The OpenSSL Project Authors. All Rights Reserved.
* Copyright Nokia 2007-2019
* Copyright Siemens AG 2015-2019
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
/*
* A collection of test cases where check-format.pl should not report issues.
* There are some known false positives, though, which are marked below.
*/
/*-
* allow double space in format-tagged multi-line comment
*/
int f(void) /*
* trailing multi-line comment
*/
{
if (ctx == NULL) { /* non-leading intra-line comment */
if (pem_name != NULL)
/* entire-line comment indent usually like for the following line */
return NULL; /* hanging indent also for this line after comment */
/* leading comment has same indentation as normal code */ stmt;
/* entire-line comment may have same indent as normal code */
}
#if X
if (1) /* bad style: just part of control structure depends on #if */
#else
if (2) /*@ resulting false positive */
#endif
c; /*@ resulting false positive */
if (1)
if (2)
c;
else
e;
else
f;
do
do
2;
while (1);
while (2);
if (1)
f(a, b);
do
1; while (2); /*@ more than one stmt just to construct case */
if (1)
f(a, b);
else
do
1;
while (2);
if (1)
f(a, b);
else do /*@ (non-brace) code before 'do' just to construct case */
1;
while (2);
f1234(a,
b); do /*@ (non-brace) code before 'do' just to construct case */
1;
while (2);
if (1)
f(a,
b); do /*@ (non-brace) code before 'do' just to construct case */
1;
while (2);
if (1)
f(a, b);
else
do f(c, c); /*@ (non-brace) code after 'do' just to construct case */
while (2);
if (1)
f(a, b);
else
return;
if (1)
f(a,
b); else /*@ (non-brace) code before 'else' just to construct case */
do
1;
while (2);
if (1)
{ /*@ brace after 'if' not on same line just to construct case */
c;
d;
}
/* this comment is correctly indented if it refers to the following line */
d;
if (1) {
2;
} else /*@ no brace after 'else' just to construct case */
3;
do {
} while (x);
if (1) {
2;
} else {
3;
}
if (4)
5;
else
6;
if (1) {
if (2) {
case MAC_TYPE_MAC:
{
EVP_MAC_CTX *new_mac_ctx;
if (ctx->pkey == NULL)
return 0;
}
break;
default:
/* This should be dead code */
return 0;
}
}
if (expr_line1
== expr_line2
&& expr_line3) {
c1;
} else {
c;
d;
}
if (expr_line1
== expr_line2
&& expr_line3)
hanging_stmt;
}
const OPTIONS passwd_options[] = {
{"aixmd5", OPT_AIXMD5, '-', "AIX MD5-based password algorithm"},
#if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
{"crypt", OPT_CRYPT, '-', "Standard Unix password algorithm (default)"},
#endif
OPT_R_OPTIONS,
{NULL}
};
typedef * d(int)
x;
typedef (int)
x;
typedef (int)*()
x;
typedef *int *
x;
typedef OSSL_CMP_MSG *(*cmp_srv_process_cb_t)
(OSSL_CMP_SRV_CTX *ctx, OSSL_CMP_MSG *msg)
xx;
int f()
{
c;
if (1) {
c;
}
c;
if (1)
if (2)
{ /*@ brace after 'if' not on same line just to construct case */
c;
}
e;
const usign = {
0xDF,
{
dd
},
dd
};
const unsign = {
0xDF, {
dd
},
dd
};
}
const unsigned char trans_id[OSSL_CMP_TRANSACTIONID_LENGTH] = {
0xDF,
};
const unsigned char trans_id[OSSL_CMP_TRANSACTIONID_LENGTH] =
{
0xDF,
};
typedef
int
a;
typedef
struct
{
int a;
} b;
typedef enum {
w = 0
} e_type;
typedef struct {
enum {
w = 0
} e_type;
enum {
w = 0
} e_type;
} e;
struct s_type {
enum e_type {
w = 0
};
};
struct s_type
{
enum e_type {
w = 0
};
enum e2_type {
w = 0
};
};
#define X 1 + 1
#define Y /* .. */ 2 + 2
#define Z 3 + 3
static varref cmp_vars[] = { /* comment */
{&opt_config}, {&opt_section},
{&opt_server}, {&opt_proxy}, {&opt_path},
};
#define SWITCH(x) \
switch (x) { \
case 0: \
break; \
default: \
break; \
}
#define DEFINE_SET_GET_BASE_TEST(PREFIX, SETN, GETN, DUP, FIELD, TYPE, ERR, \
DEFAULT, NEW, FREE) \
static int execute_CTX_##SETN##_##GETN##_##FIELD( \
TEST_FIXTURE *fixture) \
{ \
CTX *ctx = fixture->ctx; \
int (*set_fn)(CTX *ctx, TYPE) = \
(int (*)(CTX *ctx, TYPE))PREFIX##_##SETN##_##FIELD; \
/* comment */ \
}
/* 'struct' in function header */
static int f(struct pem_pass_data *pass_data)
{
if (pass_data == NULL)
return 0;
}
static void *fun(void)
{
if (pem_name != NULL)
/* comment */
return NULL;
do {
size_t available_len, data_len;
const char *curr = txt, *next = txt;
char *tmp;
} while (1);
char *intraline_string_with_comment_delimiters_and_dbl_space = "1 /*1";
char *multiline_string_with_comment_delimiters_and_dbl_space = "1 /*1\
2222222\'22222222222222222\"222222222" "33333 /*3333333333" "44 /*44444444444\
55555555555555\
6666";
}
ASN1_CHOICE(OSSL_CRMF_POPO) = {
ASN1_IMP(OSSL_CRMF_POPO, value.raVerified, ASN1_NULL, 0),
ASN1_EXP(OSSL_CRMF_POPO, value.keyAgreement, OSSL_CRMF_POPOPRIVKEY, 3)
} ASN1_CHOICE_END(OSSL_CRMF_POPO)
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_POPO)
ASN1_ADB(OSSL_CRMF_ATTRIBUTETYPEANDVALUE) = {
ADB_ENTRY(NID_id_regCtrl_regToken,
ASN1_SIMPLE(OSSL_CRMF_ATTRIBUTETYPEANDVALUE,
value.regToken, ASN1_UTF8STRING)),
} ASN1_ADB_END(OSSL_CRMF_ATTRIBUTETYPEANDVALUE, 0, type, 0,
&attributetypeandvalue_default_tt, NULL);
ASN1_ITEM_TEMPLATE(OSSL_CRMF_MSGS) =
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0,
OSSL_CRMF_MSGS, OSSL_CRMF_MSG)
ASN1_ITEM_TEMPLATE_END(OSSL_CRMF_MSGS)
void f_looong_body_200()
{ /* function body length up to 200 lines accepted */
}
void f_looong_body_201()
{ /* function body length > 200 lines, but LONG BODY marker present */
}
+345
View File
@@ -0,0 +1,345 @@
/*
* Copyright 2007-2019 The OpenSSL Project Authors. All Rights Reserved.
* Copyright Nokia 2007-2019
* Copyright Siemens AG 2015-2019
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
/*
* This demonstrates/tests cases where check-format.pl should report issues.
* Some of the reports are due to sanity checks for proper nesting of comment
* delimiters and parenthesis-like symbols, e.g., on unexpected/unclosed braces.
*/
/*
* The '@'s after '*' are used for self-tests: they mark lines containing
* a single flaw that should be reported. Normally it should be reported
* while handling the given line, but in case of delayed checks there is a
* following digit indicating the number of reports expected for this line.
*/
/* For each of the following set of lines the tool should complain once */
/*@ tab character: */
/*@ intra-line carriage return character: ␍ */
/*@ non-printable ASCII character:  */
/*@ non-ASCII character: ä */
/*@ whitespace at EOL: */
// /*@ end-of-line comment style not allowed (for C90 compatibility) */
/*@0 intra-line comment indent off by 1, reported unless sloppy-cmt */
/*X */ /*@2 no space nor '*' after comment start, reported unless sloppy-spc */
/* X*/ /*@ no space before comment end , reported unless sloppy-spc */
/*@ comment starting delimiter: /* inside intra-line comment */
/*@0
*@ above multi-line comment start indent off by 1, reported unless sloppy-cmt; this comment line is too long
*@ multi-line comment indent further off by 1 relative to comment start
*@ multi-line comment ending with text on last line */
/*@2 multi-line comment starting with text on first line
*@ comment starting delimiter: /* inside multi-line comment
*@ multi-line comment indent off by -1
*X*@ no spc after leading '*' in multi-line comment, reported unless sloppy-spc
*@0 more than two spaces after . in comment, reported unless sloppy-spc
*/ /*@2 multi-line comment end indent off by -1 (relative to comment start) */
*/ /*@ unexpected comment ending delimiter outside comment */
/*@ comment line is 4 columns tooooooooooooooooo wide, reported unless sloppy-len */
/*@ comment line is 5 columns toooooooooooooooooooooooooooooooooooooooooooooo wide */
#define X 1 /*@0 double space false negative due to coincidence */
#define Y 2 /*@ indent of preprocessor directive off by 1 (must be 0) */
typedef struct { /*@0 double space in code, reported unless sloppy-spc */
enum { /*@1 double space in comment, reported unless sloppy-spc */
w = 0 /*@2 hanging expr indent off by 1, or 3 for lines after '{' */
&& 1, /*@ hanging expr indent off by 3, or -1 for leading '&&' */
x = 1, /*@ hanging expr indent off by -1 */
y,z /*@ no space after ',', reported unless sloppy-spc */
} e_member ; /*@ space before ';', reported unless sloppy-spc */
int v[1; /*@ unclosed bracket in type declaration */
union { /*@ statement/type declaration indent off by -1 */
struct{} s; /*@ no space before '{', reported unless sloppy-spc */
}u_member; /*@ no space after '}', reported unless sloppy-spc */
} s_type; /*@ statement/type declaration indent off by 4 */
int* somefunc(); /*@ no space before '*' in type decl, r unless sloppy-spc */
void main(int n) { /*@ opening brace at end of function definition header */
for (;;n++) { /*@ no space after ';', reported unless sloppy-spc */
return; /*@0 (1-line) single statement in braces */
}} /*@2 code after '}' outside expr */
} /*@ unexpected closing brace (too many '}') outside expr */
) /*@ unexpected closing paren outside expr */
#endif /*@ unexpected #endif */
int f (int a, /*@ space after fn before '(', reported unless sloppy-spc */
int b, /*@ hanging expr indent off by -1 */
long l) /*@ one-letter name 'l' */
{ int /*@ code after '{' opening a block */
xx = 1) + /*@ unexpected closing parenthesis */
2] - /*@ unexpected closing bracket */
3: * /*@ unexpected ':' (without preceding '?') within expr */
4}; /*@ unexpected closing brace within expression */
char y[] = { /*@0 unclosed brace within initializer/enum expression */
1* 1, /*@ no space etc. before '*', reported unless sloppy-spc */
2, /*@ hanging expr indent (for lines after '{') off by 1 */
(xx /*@0 unclosed parenthesis in expression */
? y /*@0 unclosed '? (conditional expression) */
[0; /*@4 unclosed bracket in expression */
s_type s; /*@ local variable declaration indent off by -1 */
somefunc(a, /*@ statement indent off by -1 */
"aligned" /*@ expr indent off by -2 accepted if sloppy-hang */ "right"
, b, /*@ expr indent off by -1 */
b, /*@ expr indent as on line above, accepted if sloppy-hang */
b, /*@ expr indent off -8 but @ extra indent accepted if sloppy-hang */
"again aligned" /*@ expr indent off by -9 (left of stmt indent, */ "right",
123 == /*@ .. so reported also with sloppy-hang; this line is too long */ 456
# define MAC(A) (A) /*@ nesting indent of preprocessor directive off by 1 */
? 1 /*@ hanging expr indent off by 1 */
: 2); /*@ hanging expr indent off by 2, or 1 for leading ':' */
if(a /*@ no space after 'if', reported unless sloppy-spc */
/*@0 intra-line comment indent off by -1 (not: by 3 due to '&&') */
&& ! 0 /*@2 space after '!', reported unless sloppy-spc */
|| b == /*@ hanging expr indent off by 2, or -2 for leading '||' */
(xx+= 2) + /*@ no space before '+=', reported unless sloppy-spc */
(a^ 1) + /*@ no space before '^', reported unless sloppy-spc */
a %2 / /*@ no space after '%', reported unless sloppy-spc */
1 +/* */ /*@ no space before comment, reported unless sloppy-spc */
/* */+ /*@ no space after comment, reported unless sloppy-spc */
s. e_member) /*@ space after '.', reported unless sloppy-spc */
xx = a + b /*@ extra single-statement indent off by 1 */
+ 0; /*@ two times extra single-statement indent off by 3 */
if (a ++) /*@ space before postfix '++', reported unless sloppy-spc */
{ /*@ {' not on same line as preceding 'if' */
c; /*@0 single stmt in braces, reported on 1-stmt */
} else /*@ no '{' on same line after '} else' */
{ /*@ statement indent off by 2 */
d; /*@0 single stmt in braces, reported on 1-stmt */
} /*@ statement indent off by 6 */
if (1) f(a, /*@ (non-brace) code after end of 'if' condition */
b); else /*@ (non-brace) code before 'else' */
do f(c, c); /*@ (non-brace) code after 'do' */
while ( 2); /*@ space after '(', reported unless sloppy-spc */
b; c; /*@ more than one statement per line */
do{ /*@ no space before '{', reported unless sloppy-spc */
f (3, /*@ space after fn before '(', reported unless sloppy-spc */
4); /*@0 false negative: should report single stmt in braces */
} /*@0 'while' not on same line as preceding '}' */
while (a+ 0); /*@2 no space before '+', reported unless sloppy-spc */
switch (b ) { /*@ space before ')', reported unless sloppy-spc */
case 1: /*@ 'case' special statement indent off by -1 */
case(2): /*@ no space after 'case', reported unless sloppy-spc */
default: ; /*@ code after 'default:' */
} /*@ statement indent off by -4 */
label: /*@ label special statement indent off by 1 */
return( /*@ no space after 'return', reported unless sloppy-spc */
x); } /*@ code before block-level '}' */
/* Here the tool should stop complaining apart from the below issues at EOF */
void f_looong_body()
{
} /*@ function body length > 200 lines */
#if 0 /*@0 unclosed #if */
struct t { /*@0 unclosed brace at decl/block level */
enum { /*@0 unclosed brace at enum/expression level */
v = (1 /*@0 unclosed parenthesis */
etyp /*@0 empty line follows just before EOF: */
+1119
View File
@@ -0,0 +1,1119 @@
#!/usr/bin/perl
#
# Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
# Copyright Siemens AG 2019-2020
#
# Licensed under the Apache License 2.0 (the "License").
# You may not use this file except in compliance with the License.
# You can obtain a copy in the file LICENSE in the source distribution
# or at https://www.openssl.org/source/license.html
#
# check-format.pl
# - check formatting of C source according to OpenSSL coding style
#
# usage:
# check-format.pl [-l|--sloppy-len] [-l|--sloppy-bodylen]
# [-s|--sloppy-spc] [-c|--sloppy-cmt] [-m|--sloppy-macro]
# [-h|--sloppy-hang] [-1|--1-stmt]
# <files>
#
# checks adherence to the formatting rules of the OpenSSL coding guidelines
# assuming that the input files contain syntactically correct C code.
# This pragmatic tool is incomplete and yields some false positives.
# Still it should be useful for detecting most typical glitches.
#
# options:
# -l | --sloppy-len increase accepted max line length from 80 to 84
# -l | --sloppy-bodylen do not report function body length > 200
# -s | --sloppy-spc do not report whitespace nits
# -c | --sloppy-cmt do not report indentation of comments
# Otherwise for each multi-line comment the indentation of
# its lines is checked for consistency. For each comment
# that does not begin to the right of normal code its
# indentation must be as for normal code, while in case it
# also has no normal code to its right it is considered to
# refer to the following line and may be indented equally.
# -m | --sloppy-macro allow missing extra indentation of macro bodies
# -h | --sloppy-hang when checking hanging indentation, do not report
# * same indentation as on line before
# * same indentation as non-hanging indent level
# * indentation moved left (not beyond non-hanging indent)
# just to fit contents within the line length limit
# -1 | --1-stmt do more aggressive checks for { 1 stmt } - see below
#
# There are non-trivial false positives and negatives such as the following.
#
# * When a line contains several issues of the same kind only one is reported.
#
# * When a line contains more than one statement this is (correctly) reported
# but in some situations the indentation checks for subsequent lines go wrong.
#
# * There is the special OpenSSL rule not to unnecessarily use braces around
# single statements:
# {
# stmt;
# }
# except within if ... else constructs where some branch contains more than one
# statement. Since the exception is hard to recognize when such branches occur
# after the current position (such that false positives would be reported)
# the tool by checks for this rule by defaul only for do/while/for bodies.
# Yet with the --1-stmt option false positives are preferred over negatives.
# False negatives occur if the braces are more than two non-empty lines apart.
#
# * Use of multiple consecutive spaces is regarded a coding style nit except
# when done in order to align certain columns over multiple lines, e.g.:
# # define AB 1
# # define CDE 22
# # define F 3333
# This pattern is recognized - and consequently double space not reported -
# for a given line if in the nonempty line before or after (if existing)
# for each occurrence of " \S" (where \S means non-space) in the given line
# there is " \S" in the other line in the respective column position.
# This may lead to both false negatives (in case of coincidental " \S")
# and false positives (in case of more complex multi-column alignment).
#
# * When just part of control structures depend on #if(n)(def), which can be
# considered bad programming style, indentation false positives occur, e.g.:
# #if X
# if (1) /* bad style */
# #else
# if (2) /* bad style resulting in false positive */
# #endif
# c; /* resulting further false positive */
use strict;
# use List::Util qw[min max];
use POSIX;
use constant INDENT_LEVEL => 4;
use constant MAX_LINE_LENGTH => 80;
use constant MAX_BODY_LENGTH => 200;
# global variables @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# command-line options
my $max_length = MAX_LINE_LENGTH;
my $sloppy_bodylen = 0;
my $sloppy_SPC = 0;
my $sloppy_hang = 0;
my $sloppy_cmt = 0;
my $sloppy_macro = 0;
my $extended_1_stmt = 0;
while ($ARGV[0] =~ m/^-(\w|-[\w\-]+)$/) {
my $arg = $1; shift;
if ($arg =~ m/^(l|-sloppy-len)$/) {
$max_length += INDENT_LEVEL;
} elsif ($arg =~ m/^(b|-sloppy-bodylen)$/) {
$sloppy_bodylen = 1;
} elsif ($arg =~ m/^(s|-sloppy-spc)$/) {
$sloppy_SPC = 1;
} elsif ($arg =~ m/^(c|-sloppy-cmt)$/) {
$sloppy_cmt = 1;
} elsif ($arg =~ m/^(m|-sloppy-macro)$/) {
$sloppy_macro = 1;
} elsif ($arg =~ m/^(h|-sloppy-hang)$/) {
$sloppy_hang = 1;
} elsif ($arg =~ m/^(1|-1-stmt)$/) {
$extended_1_stmt = 1;
} else {
die("unknown option: -$arg");
}
}
# status variables
my $self_test; # whether the current input file is regarded to contain (positive/negative) self-tests
my $line; # current line number
my $line_before; # number of previous not essentially empty line (containing at most whitespace and '\')
my $line_before2; # number of not essentially empty line before previous not essentially empty line
my $contents; # contents of current line
my $contents_before; # contents of $line_before, if $line_before > 0
my $contents_before_; # contents of $line_before after blinding comments etc., if $line_before > 0
my $contents_before2; # contents of $line_before2, if $line_before2 > 0
my $contents_before_2; # contents of $line_before2 after blinding comments etc., if $line_before2 > 0
my $in_multiline_string; # line starts within multi-line string literal
my $count; # -1 or number of leading whitespace characters (except newline) in current line,
# which should be $block_indent + $hanging_offset + $local_offset or $expr_indent
my $count_before; # number of leading whitespace characters (except line ending chars) in $contents_before
my $has_label; # current line contains label
my $local_offset; # current extra indent due to label, switch case/default, or leading closing brace(s)
my $line_body_start; # number of line where last function body started, or 0
my $line_function_start; # number of line where last function definition started, used if $line_body_start != 0
my $last_function_header; # header containing name of last function defined, used if $line_function_start != 0
my $line_opening_brace; # number of previous line with opening brace after do/while/for, optionally for if/else
my $keyword_opening_brace; # name of previous keyword, used if $line_opening_brace != 0
my $ifdef__cplusplus; # line before contained '#ifdef __cplusplus' (used in header files)
my $block_indent; # currently required normal indentation at block/statement level
my $hanging_offset; # extra indent, which may be nested, for just one hanging statement or expr or typedef
my @in_do_hanging_offsets; # stack of hanging offsets for nested 'do' ... 'while'
my @in_if_hanging_offsets; # stack of hanging offsets for nested 'if' (but not its potential 'else' branch)
my $if_maybe_terminated; # 'if' ends and $hanging_offset should be reset unless the next line starts with 'else'
my @nested_block_indents; # stack of indentations at block/statement level, needed due to hanging statements
my @nested_hanging_offsets;# stack of nested $hanging_offset values, in parallel to @nested_block_indents
my @nested_in_typedecl; # stack of nested $in_typedecl values, partly in parallel to @nested_block_indents
my @nested_indents; # stack of hanging indents due to parentheses, braces, brackets, or conditionals
my @nested_symbols; # stack of hanging symbols '(', '{', '[', or '?', in parallel to @nested_indents
my @nested_conds_indents; # stack of hanging indents due to conditionals ('?' ... ':')
my $expr_indent; # resulting hanging indent within (multi-line) expressions including type exprs, else 0
my $hanging_symbol; # character ('(', '{', '[', not: '?') responsible for $expr_indent, if $expr_indent != 0
my $in_expr; # in expression after if/while/for/switch/return/enum/LHS of assignment
my $in_paren_expr; # in parenthesized if/while/for condition and switch expression, if $expr_indent != 0
my $in_typedecl; # nesting level of typedef/struct/union/enum
my $in_directive; # number of lines so far within preprocessor directive, e.g., macro definition
my $directive_nesting; # currently required indentation of preprocessor directive according to #if(n)(def)
my $directive_offset; # indent offset within multi-line preprocessor directive, if $in_directive > 0
my $in_macro_header; # number of open parentheses + 1 in (multi-line) header of #define, if $in_directive > 0
my $in_comment; # number of lines so far within multi-line comment, or < 0 when end is on current line
my $leading_comment; # multi-line comment has no code before its beginning delimiter
my $formatted_comment; # multi-line comment beginning with "/*-", which indicates/allows special formatting
my $comment_indent; # comment indent, if $in_comment != 0
my $num_reports_line = 0; # number of issues found on current line
my $num_reports = 0; # total number of issues found
my $num_indent_reports = 0;# total number of indentation issues found
my $num_nesting_issues = 0;# total number of directive nesting issues found
my $num_syntax_issues = 0; # total number of syntax issues found during sanity checks
my $num_SPC_reports = 0; # total number of whitespace issues found
my $num_length_reports = 0;# total number of line length issues found
sub reset_file_state {
$line = 0;
$line_before = 0;
$line_before2 = 0;
@nested_block_indents = ();
@nested_hanging_offsets = ();
@nested_in_typedecl = ();
@nested_symbols = ();
@nested_indents = ();
@nested_conds_indents = ();
$expr_indent = 0;
$in_paren_expr = 0;
$in_expr = 0;
$hanging_offset = 0;
@in_do_hanging_offsets = ();
@in_if_hanging_offsets = ();
$if_maybe_terminated = 0;
$block_indent = 0;
$ifdef__cplusplus = 0;
$in_multiline_string = 0;
$line_body_start = 0;
$line_opening_brace = 0;
$in_typedecl = 0;
$in_directive = 0;
$directive_nesting = 0;
$in_comment = 0;
}
# auxiliary submodules @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
sub report_flexibly {
my $line = shift;
my $msg = shift;
my $contents = shift;
my $report_SPC = $msg =~ /SPC/;
return if $report_SPC && $sloppy_SPC;
print "$ARGV:$line:$msg:$contents" unless $self_test;
$num_reports_line++;
$num_reports++;
$num_indent_reports++ if $msg =~ m/indent/;
$num_nesting_issues++ if $msg =~ m/directive nesting/;
$num_syntax_issues++ if $msg =~ m/unclosed|unexpected/;
$num_SPC_reports++ if $report_SPC;
$num_length_reports++ if $msg =~ m/length/;
}
sub report {
my $msg = shift;
report_flexibly($line, $msg, $contents);
}
sub parens_balance { # count balance of opening parentheses - closing parentheses
my $str = shift;
return $str =~ tr/\(// - $str =~ tr/\)//;
}
sub blind_nonspace { # blind non-space text of comment as @, preserving length and spaces
# the @ character is used because it cannot occur in normal program code so there is no confusion
# comment text is not blinded to whitespace in order to be able to check double SPC also in comments
my $comment_text = shift;
$comment_text =~ s/\.\s\s/.. /g; # in double SPC checks allow one extra space after period '.' in comments
return $comment_text =~ tr/ /@/cr;
}
# submodule for indentation checking/reporting @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
sub check_indent { # used for lines outside multi-line string literals
my $stmt_indent = $block_indent + $hanging_offset + $local_offset;
$stmt_indent = 0 if $stmt_indent < 0; # TODO maybe give warning/error
my $stmt_desc = $contents =~
m/^\s*\/\*/ ? "intra-line comment" :
$has_label ? "label" :
($hanging_offset != 0 ? "hanging " : "").
($hanging_offset != 0 ? "stmt/expr" : "stmt/decl"); # $in_typedecl is not fully to the point here
my ($ref_desc, $ref_indent) = $expr_indent == 0 ? ($stmt_desc, $stmt_indent)
: ("hanging '$hanging_symbol'", $expr_indent);
my ($alt_desc, $alt_indent) = ("", $ref_indent);
# allow indent 1 for labels - this cannot happen for leading ':'
($alt_desc, $alt_indent) = ("outermost position", 1) if $expr_indent == 0 && $has_label;
if (@nested_conds_indents != 0 && substr($_, $count, 1) eq ":") {
# leading ':' within stmt/expr/decl - this cannot happen for labels nor leading '&&' or '||'
# allow special indent at level of corresponding "?"
($alt_desc, $alt_indent) = ("leading ':'", @nested_conds_indents[-1]);
}
# allow extra indent offset leading '&&' or '||' - this cannot happen for leading ":"
($alt_desc, $alt_indent) = ("leading '$1'", $ref_indent + INDENT_LEVEL) if $contents =~ m/^[\s@]*(\&\&|\|\|)/;
if ($expr_indent < 0) { # implies @nested_symbols != 0 && @nested_symbols[0] eq "{" && @nested_indents[-1] < 0
# allow normal stmt indentation level for hanging initializer/enum expressions after trailing '{'
# this cannot happen for labels and overrides special treatment of ':', '&&' and '||' for this line
($alt_desc, $alt_indent) = ("lines after '{'", $stmt_indent);
# decide depending on current actual indentation, preventing forth and back
@nested_indents[-1] = $count == $stmt_indent ? $stmt_indent : -@nested_indents[-1]; # allow $stmt_indent
$ref_indent = $expr_indent = @nested_indents[-1];
}
# check consistency of indentation within multi-line comment (i.e., between its first, inner, and last lines)
if ($in_comment != 0 && $in_comment != 1) { # in multi-line comment but not on its first line
if (!$sloppy_cmt) {
if ($in_comment > 0) { # not at its end
report("indent = $count != $comment_indent within multi-line comment")
if $count != $comment_indent;
} else {
my $tweak = $in_comment == -2 ? 1 : 0;
report("indent = ".($count + $tweak)." != $comment_indent at end of multi-line comment")
if $count + $tweak != $comment_indent;
}
}
# do not check indentation of last line of non-leading multi-line comment
if ($in_comment < 0 && !$leading_comment) {
s/^(\s*)@/$1*/; # blind first '@' as '*' to prevent below delayed check for the line before
return;
}
return if $in_comment > 0; # not on its last line
# $comment_indent will be checked by the below checks for end of multi-line comment
}
# else check indentation of entire-line comment or entire-line end of multi-line comment
# ... w.r.t. indent of the following line by delayed check for the line before
if (($in_comment == 0 || $in_comment == 1) # no comment, intra-line comment, or begin of multi-line comment
&& $line_before > 0 # there is a line before
&& $contents_before_ =~ m/^(\s*)@[\s@]*$/) { # line before begins with '@', no code follows (except '\')
report_flexibly($line_before, "entire-line comment indent = $count_before != $count (of following line)",
$contents_before) if !$sloppy_cmt && $count_before != $count;
}
# ... but allow normal indentation for the current line, else above check will be done for the line before
if (($in_comment == 0 || $in_comment < 0) # (no commment,) intra-line comment or end of multi-line comment
&& m/^(\s*)@[\s@]*$/) { # line begins with '@', no code follows (except '\')
if ($count == $ref_indent) { # indentation is like for (normal) code in this line
s/^(\s*)@/$1*/; # blind first '@' as '*' to prevent above delayed check for the line before
return;
}
return if !eof; # defer check of entire-line comment to next line
}
# else check indentation of leading intra-line comment or end of multi-line comment
if (m/^(\s*)@/) { # line begins with '@', i.e., any (remaining type of) comment
if (!$sloppy_cmt && $count != $ref_indent) {
report("intra-line comment indent = $count != $ref_indent") if $in_comment == 0;
report("multi-line comment indent = $count != $ref_indent") if $in_comment < 0;
}
return;
}
if ($sloppy_hang && ($hanging_offset != 0 || $expr_indent != 0)) {
# do not report same indentation as on the line before (potentially due to same violations)
return if $line_before > 0 && $count == $count_before;
# do not report indentation at normal indentation level while hanging expression indent would be required
return if $expr_indent != 0 && $count == $stmt_indent;
# do not report if contents have been shifted left of nested expr indent (but not as far as stmt indent)
# apparently aligned to the right in order to fit within line length limit
return if $stmt_indent < $count && $count < $expr_indent &&
length($contents) == MAX_LINE_LENGTH + length("\n");
}
report("indent = $count != $ref_indent for $ref_desc".
($alt_desc eq ""
|| $alt_indent == $ref_indent # prevent showing alternative that happens to have equal value
? "" : " or $alt_indent for $alt_desc"))
if $count != $ref_indent && $count != $alt_indent;
}
# submodules handling indentation within expressions @@@@@@@@@@@@@@@@@@@@@@@@@@@
sub update_nested_indents { # may reset $in_paren_expr and in this case also resets $in_expr
my $str = shift;
my $start = shift; # defaults to 0
my $terminator_position = -1;
for (my $i = $start; $i < length($str); $i++) {
my $c;
my $curr = substr($str, $i);
if ($curr =~ m/^(.*?)([{}()?:;\[\]])(.*)$/) { # match from position $i the first {}()?:;[]
$c = $2;
} else {
last;
}
my ($head, $tail) = (substr($str, 0, $i).$1, $3);
$i += length($1) + length($2) - 1;
# stop at terminator outside 'for(..;..;..)', assuming that 'for' is followed by '('
return $i if $c eq ";" && (!$in_paren_expr || @nested_indents == 0);
my $in_stmt = $in_expr || @nested_symbols != 0; # not: || $in_typedecl != 0
if ($c =~ m/[{([?]/) { # $c is '{', '(', '[', or '?'
if ($c eq "{") { # '{' in any context
# cancel newly hanging_offset if opening brace '{' is after non-whitespace non-comment:
$hanging_offset -= INDENT_LEVEL if $hanging_offset > 0 && $head =~ m/[^\s\@]/;
push @nested_block_indents, $block_indent;
push @nested_hanging_offsets, $in_expr ? $hanging_offset : 0;
push @nested_in_typedecl, $in_typedecl if $in_typedecl != 0;
$block_indent += INDENT_LEVEL + $hanging_offset;
$hanging_offset = 0;
}
if ($c ne "{" || $in_stmt) { # for '{' inside stmt/expr (not: decl), for '(', '[', or '?' anywhere
$tail =~ m/^([\s@]*)([^\s\@])/;
push @nested_indents, defined $2
? $i + 1 + length($1) # actual indentation of following non-space non-comment
: $c ne "{" ? +($i + 1) # just after '(' or '[' if only whitespace thereafter
: -($i + 1); # allow also $stmt_indent if '{' with only whitespace thereafter
push @nested_symbols, $c; # done also for '?' to be able to check correct nesting
push @nested_conds_indents, $i if $c eq "?"; # remember special alternative indent for ':'
}
} elsif ($c =~ m/[})\]:]/) { # $c is '}', ')', ']', or ':'
my $opening_c = ($c =~ tr/})]:/{([/r);
if (($c ne ":" || $in_stmt # ignore ':' outside stmt/expr/decl
# in the presence of ':', one could add this sanity check:
# && !(# ':' after initial label/case/default
# $head =~ m/^([\s@]*)(case\W.*$|\w+$)/ || # this matching would not work for
# # multi-line expr after 'case'
# # bitfield length within unsigned type decl
# $tail =~ m/^[\s@]*\d+/ # this matching would need improvement
# )
)) {
if ($c ne "}" || $in_stmt) { # for '}' inside stmt/expr/decl, ')', ']', or ':'
if (@nested_symbols != 0 &&
@nested_symbols[-1] == $opening_c) { # for $c there was a corresponding $opening_c
pop @nested_indents;
pop @nested_symbols;
pop @nested_conds_indents if $opening_c eq "?";
} else {
report("unexpected '$c' @ ".($in_paren_expr ? "(expr)" : "expr"));
next;
}
}
if ($c eq "}") { # '}' at block level but also inside stmt/expr/decl
if (@nested_block_indents == 0) {
report("unexpected '}'");
} else {
$block_indent = pop @nested_block_indents;
$hanging_offset = pop @nested_hanging_offsets;
$in_typedecl = pop @nested_in_typedecl if @nested_in_typedecl != 0;
}
}
if ($in_paren_expr && !grep(/\(/, @nested_symbols)) { # end of (expr)
check_nested_nonblock_indents("(expr)");
$in_paren_expr = $in_expr = 0;
report("code after (expr)")
if $tail =~ m/^([^{]*)/ && $1 =~ m/[^\s\@;]/; # non-space non-';' before any '{'
}
}
}
}
return -1;
}
sub check_nested_nonblock_indents {
my $position = shift;
while (@nested_symbols != 0) {
my $symbol = pop @nested_symbols;
report("unclosed '$symbol' in $position");
if ($symbol eq "{") { # repair stack of blocks
$block_indent = pop @nested_block_indents;
$hanging_offset = pop @nested_hanging_offsets;
$in_typedecl = pop @nested_in_typedecl if @nested_in_typedecl != 0;
}
}
@nested_indents = ();
@nested_conds_indents = ();
}
# start of main program @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
reset_file_state();
while (<>) { # loop over all lines of all input files
$self_test = $ARGV =~ m/check-format-test/;
$line++;
s/\r$//; # strip any trailing CR '\r' (which are typical on Windows systems)
$contents = $_;
# check for illegal characters
if (m/(.*?)([\x00-\x09\x0B-\x1F\x7F-\xFF])/) {
my $col = length($1);
report(($2 eq "\x09" ? "TAB" : $2 eq "\x0D" ? "CR " : $2 =~ m/[\x00-\x1F]/ ? "non-printable"
: "non-7bit char") . " at column $col") ;
}
# check for whitespace at EOL
report("trailing whitespace at EOL") if m/\s\n$/;
# assign to $count the actual indentation level of the current line
chomp; # remove trailing NL '\n'
m/^(\s*)/;
$count = length($1); # actual indentation
$has_label = 0;
$local_offset = 0;
# character/string literals @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
s/\\["']/@@/g; # blind all '"' and "'" escaped by '\' (typically within character literals or string literals)
# handle multi-line string literals to avoid confusion on starting/ending '"' and trailing '\'
if ($in_multiline_string) {
if (s#^([^"]*)"#($1 =~ tr/"/@/cr).'@'#e) { # string literal terminated by '"'
# string contents and its terminating '"' have been blinded as '@'
$count = -1; # do not check indentation
} else {
report("multi-line string literal not terminated by '\"' and trailing '\' is missing")
unless s#^([^\\]*)\s*\\\s*$#$1#; # strip trailing '\' plus any whitespace around
goto LINE_FINISHED;
}
}
# blind contents of character and string literals as @, preserving length (but not spaces)
# this prevents confusing any of the matching below, e.g., of whitespace and comment delimiters
s#('[^']*')#$1 =~ tr/'/@/cr#eg; # handle all intra-line character literals
s#("[^"]*")#$1 =~ tr/"/@/cr#eg; # handle all intra-line string literals
$in_multiline_string = # handle trailing string literal terminated by '\'
s#^(([^"]*"[^"]*")*[^"]*)("[^"]*)\\(\s*)$#$1.($3 =~ tr/"/@/cr).'"'.$4#e;
# its contents have been blinded and the trailing '\' replaced by '"'
# strip any other trailing '\' along with any whitespace around it such that it does not interfere with various
# matching below; the later handling of multi-line macro definitions uses $contents where it is not stripped
s#^(.*?)\s*\\\s*$#$1#; # trailing '\' possibly preceded and/or followed by whitespace
# comments @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# do/prepare checks within multi-line comments
my $self_test_exception = $self_test ? "@" : "";
if ($in_comment > 0) { # this still includes the last line of multi-line commment
my ($head, $any_symbol, $cmt_text) = m/^(\s*)(.?)(.*)$/;
if ($any_symbol eq "*") {
report("no SPC after leading '*' in multi-line comment") if $cmt_text =~ m|^[^/\s$self_test_exception]|;
} else {
report("no leading '*' in multi-line comment");
}
$in_comment++;
}
# detect end of comment, must be within multi-line comment, check if it is preceded by non-whitespace text
if ((my ($head, $tail) = m|^(.*?)\*/(.*)$|) && $1 ne '/') { # ending comment: '*/'
report("no SPC nor '*' before '*/'") if $head =~ m/[^*\s]$/;
report("no SPC after '*/'") if $tail =~ m/^[^\s,;)}\]]/; # no space or ,;)}] after '*/'
if (!($head =~ m|/\*|)) { # not begin of comment '/*', which is is handled below
if ($in_comment == 0) {
report("unexpected '*/' outside comment");
$_ = "$head@@".$tail; # blind the "*/"
} else {
report("text before '*/' in multi-line comment") if ($head =~ m/\S/); # non-SPC before '*/'
$in_comment = -1; # indicate that multi-line comment ends on current line
if ($count > 0) {
# make indentation of end of multi-line comment appear like of leading intra-line comment
$head =~ s/^(\s*)\s/$1@/; # replace the last leading space by '@'
$count--;
$in_comment = -2; # indicate that multi-line comment ends on current line, with tweak
}
my $cmt_text = $head;
$_ = blind_nonspace($cmt_text)."@@".$tail;
}
}
}
# detect begin of comment, check if it is followed by non-space text
MATCH_COMMENT:
if (my ($head, $opt_minus, $tail) = m|^(.*?)/\*(-?)(.*)$|) { # begin of comment: '/*'
report("no SPC before '/*'")
if $head =~ m/[^\s\*]$/; # no space (nor '*', needed to allow '*/' here) before comment delimiter
report("no SPC nor '*' after '/*' or '/*-'") if $tail =~ m/^[^\s*$self_test_exception]/;
my $cmt_text = $opt_minus.$tail; # preliminary
if ($in_comment > 0) {
report("unexpected '/*' inside multi-line comment");
} elsif ($tail =~ m|^(.*?)\*/(.*)$|) { # comment end: */ on same line
report("unexpected '/*' inside intra-line comment") if $1 =~ /\/\*/;
# blind comment text, preserving length and spaces
($cmt_text, my $rest) = ($opt_minus.$1, $2);
$_ = "$head@@".blind_nonspace($cmt_text)."@@".$rest;
goto MATCH_COMMENT;
} else { # begin of multi-line comment
my $self_test_exception = $self_test ? "(@\d?)?" : "";
report("text after '/*' in multi-line comment")
unless $tail =~ m/^$self_test_exception.?\s*$/;
# tail not essentially empty, first char already checked
# adapt to actual indentation of first line
$comment_indent = length($head) + 1;
$_ = "$head@@".blind_nonspace($cmt_text);
$in_comment = 1;
$leading_comment = $head =~ m/^\s*$/; # there is code before beginning delimiter
$formatted_comment = $opt_minus eq "-";
}
}
if ($in_comment > 1) { # still inside multi-line comment (not at its begin or end)
m/^(\s*)\*?(\s*)(.*)$/;
$_ = $1."@".$2.blind_nonspace($3);
}
# handle special case of line after '#ifdef __cplusplus' (which typically appears in header files)
if ($ifdef__cplusplus) {
$ifdef__cplusplus = 0;
$_ = "$1 $2" if $contents =~ m/^(\s*extern\s*"C"\s*)\{(\s*)$/; # ignore opening brace in 'extern "C" {'
goto LINE_FINISHED if m/^\s*\}\s*$/; # ignore closing brace '}'
}
# check for over-long lines,
# while allowing trailing (also multi-line) string literals to go past $max_length
my $len = length; # total line length (without trailing '\n')
if ($len > $max_length &&
!(m/^(.*)"[^"]*"\s*[\)\}\]]*[,;]?\s*$/ # string literal terminated by '"' (or '\'), then maybe )}],;
&& length($1) < $max_length)
# this allows over-long trailing string literals with beginning col before $max_length
) {
report("line length = $len > ".MAX_LINE_LENGTH);
}
# handle C++ / C99 - style end-of-line comments
if (my ($head, $cmt_text) = m|^(.*?)//(.*$)|) {
report("'//' end-of-line comment"); # the '//' comment style is not allowed for C90
# blind comment text, preserving length and spaces
$_ = "$head@@".blind_nonspace($cmt_text);
}
# at this point all non-space portions of any types of comments have been blinded as @
goto LINE_FINISHED if m/^\s*$/; # essentially empty line: just whitespace (and maybe a trailing '\')
# intra-line whitespace nits @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
my $in_multiline_comment = ($in_comment > 1 || $in_comment < 0); # $in_multiline_comment refers to line before
if (!$sloppy_SPC && !($in_multiline_comment && $formatted_comment)) {
sub dbl_SPC {
my $intra_line = shift;
return "double SPC".($intra_line =~ m/@\s\s/ ?
$in_comment != 0 ? " in multi-line comment"
: " in intra-line comment" : "");
}
sub split_line_head {
my $comment_symbol =
$in_comment != 0 ? "@" : ""; # '@' will match the blinded leading '*' in multi-line comment
# $in_comment may pertain to the following line due to delayed check
# do not check for double SPC in leading spaces including any '#' (or '*' within multi-line comment)
shift =~ m/^(\s*([#$comment_symbol]\s*)?)(.*?)\s*$/;
return ($1, $3);
}
my ($head , $intra_line ) = split_line_head($_);
my ($head1, $intra_line1) = split_line_head($contents_before_ ) if $line_before > 0;
my ($head2, $intra_line2) = split_line_head($contents_before_2) if $line_before2 > 0;
if ($line_before > 0) { # check with one line delay, such that at least $contents_before is available
sub column_alignments_only {
my $head = shift;
my $intra = shift;
my $contents = shift;
# check if all double SPC in $intra is used only for multi-line column alignment with $contents
my $offset = length($head);
for (my $col = 0; $col < length($intra) - 2; $col++) {
return 0 if substr($intra , $col, 3) =~ m/\s\s\S/ # double space (after leading space)
&& !(substr($contents, $col + $offset + 1, 2) =~ m/\s\S/)
}
return 1;
}
report_flexibly($line_before, dbl_SPC($intra_line1), $contents_before) if $intra_line1 =~ m/\s\s\S/ &&
!( column_alignments_only($head1, $intra_line1, $_ ) # compare with $line
|| ($line_before2 > 0 &&
column_alignments_only($head1, $intra_line1, $contents_before_2))); # compare w/ $line_before2
report(dbl_SPC($intra_line)) if $intra_line =~ m/\s\s\S/ && eof
&& ! column_alignments_only($head , $intra_line , $contents_before_ ) ; # compare w/ $line_before
} elsif (eof) { # special case: just one line exists
report(dbl_SPC($intra_line)) if $intra_line =~ m/\s\s\S/;
}
# ignore paths in #include
$intra_line =~ s/^(include\s*)(".*?"|<.*?>)/$1/e if $head =~ m/#/;
# treat op= and comparison operators as simple '=', simplifying matching below
$intra_line =~ s/([\+\-\*\/\/%\&\|\^\!<>=]|<<|>>)=/=/g;
# treat (type) variables within macro, indicated by trailing '\', as 'int' simplifying matching below
$intra_line =~ s/[A-Z_]+/int/g if $contents =~ m/^(.*?)\s*\\\s*$/;
# treat double &&, ||, <<, and >> as single ones, simplifying matching below
$intra_line =~ s/(&&|\|\||<<|>>)/substr($1, 0, 1)/eg;
# remove blinded comments etc. directly before ,;)}
while ($intra_line =~ s/\s*@+([,;)}\]])/$1/e) {} # /g does not work here
# treat remaining blinded comments and string literal contents as (single) space during matching below
$intra_line =~ s/@+/ /g; # note that double SPC has already been handled above
$intra_line =~ s/\s+$//; # strip any (resulting) space at EOL
$intra_line =~ s/(for\s*\();;(\))/"$1$2"/eg; # strip ';;' in for (;;)
$intra_line =~ s/(=\s*)\{ /"$1@ "/eg; # do not report {SPC in initializers such as ' = { 0, };'
$intra_line =~ s/, \};/, @;/g; # do not report SPC} in initializers such as ' = { 0, };'
report("SPC before '$1'") if $intra_line =~ m/[\w)\]]\s+(\+\+|--)/; # postfix ++/-- with preceding space
report("SPC after '$1'") if $intra_line =~ m/(\+\+|--)\s+[a-zA-Z_(]/; # prefix ++/-- with following space
$intra_line =~ s/\.\.\./@/g; # blind '...'
report("SPC before '$1'") if $intra_line =~ m/\s(\.|->)/; # '.' or '->' with preceding space
report("SPC after '$1'") if $intra_line =~ m/(\.|->)\s/; # '.' or '->' with following space
$intra_line =~ s/\-\>|\+\+|\-\-/@/g; # blind '->,', '++', and '--'
report("SPC before '$2'") if $intra_line =~ m/[^:]\s+(;)/; # space before ';' but not after ':'
report("SPC before '$1'") if $intra_line =~ m/\s([,)\]])/; # space before ,)]
report("SPC after '$1'") if $intra_line =~ m/([(\[~!])\s/; # space after ([~!
report("SPC after '$1'") if $intra_line =~ m/(defined)\s/; # space after 'defined'
report("no SPC before '=' or '<op>='") if $intra_line =~ m/\S(=)/; # '=' etc. without preceding space
report("no SPC before '$1'") if $intra_line =~ m/\S([|\/%<>^\?])/; # |/%<>^? without preceding space
# TODO ternary ':' without preceding SPC, while allowing no SPC before ':' after 'case'
report("no SPC before '$1'") if $intra_line =~ m/[^\s{()\[]([+\-])/;# +/- without preceding space or {()[
# or ')' (which is used f type casts)
report("no SPC before '$1'") if $intra_line =~ m/[^\s{()\[*]([*])/; # '*' without preceding space or {()[*
report("no SPC before '$1'") if $intra_line =~ m/[^\s{()\[]([&])/; # '&' without preceding space or {()[
report("no SPC after ternary '$1'") if $intra_line =~ m/(:)[^\s\d]/; # ':' without following space or digit
report("no SPC after '$1'") if $intra_line =~ m/([,;=|\/%<>^\?])\S/; # ,;=|/%<>^? without following space
report("no SPC after binary '$1'") if $intra_line=~m/([*])[^\sa-zA-Z_(),*]/;# '*' w/o space or \w(),* after
# TODO unary '*' must not be followed by SPC
report("no SPC after binary '$1'") if $intra_line=~m/([&])[^\sa-zA-Z_(]/; # '&' w/o following space or \w(
# TODO unary '&' must not be followed by SPC
report("no SPC after binary '$1'") if $intra_line=~m/([+\-])[^\s\d(]/; # +/- w/o following space or \d(
# TODO unary '+' and '-' must not be followed by SPC
report("no SPC after '$2'") if $intra_line =~ m/(^|\W)(if|while|for|switch|case)[^\w\s]/; # kw w/o SPC
report("no SPC after '$2'") if $intra_line =~ m/(^|\W)(return)[^\w\s;]/; # return w/o SPC or ';'
report("SPC after function/macro name")
if $intra_line =~ m/(\w+)\s+\(/ # fn/macro name with space before '('
&& !($1 =~ m/^(if|while|for|switch|return|typedef|void|char|unsigned|int|long|float|double)$/) # not keyword
&& !(m/^\s*#\s*define\s/); # we skip macro definitions here because macros
# without parameters but with body beginning with '(', e.g., '#define X (1)',
# would lead to false positives - TODO also check for macros with parameters
report("no SPC before '{'") if $intra_line =~ m/[^\s{(\[]\{/; # '{' without preceding space or {([
report("no SPC after '}'") if $intra_line =~ m/\}[^\s,;\])}]/; # '}' without following space or ,;])}
}
# preprocessor directives @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# handle preprocessor directives
if (m/^\s*#(\s*)(\w+)/) { # line beginning with '#'
my $space_count = length($1); # maybe could also use indentation before '#'
my $directive = $2;
report("indent = $count != 0 for '#'") if $count != 0;
$directive_nesting-- if $directive =~ m/^(else|elif|endif)$/;
if ($directive_nesting < 0) {
$directive_nesting = 0;
report("unexpected '#$directive'");
}
report("'#' directive nesting = $space_count != $directive_nesting") if $space_count != $directive_nesting;
$directive_nesting++ if $directive =~ m/^if|ifdef|ifndef|else|elif$/;
$ifdef__cplusplus = m/^\s*#\s*ifdef\s+__cplusplus\s*$/;
goto POSTPROCESS_DIRECTIVE unless $directive =~ m/^define$/; # skip normal code handling except for #define
# TODO improve handling of indents of preprocessor directives ('\', $in_directive != 0) vs. normal C code
$count = -1; # do not check indentation of #define
}
# adapt required indentation @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
s/(\w*ASN1_[A-Z_]+END\w*([^(]|\(.*?\)|$))/$1;/g; # treat *ASN1_*END*(..) macro calls as if followed by ';'
my $nested_indents_position = 0;
# update indents according to leading closing brace(s) '}' or label or switch case
my $in_stmt = $in_expr || @nested_symbols != 0 || $in_typedecl != 0;
if ($in_stmt) { # expr/stmt/type decl/var def/fn hdr, i.e., not at block level
if (m/^([\s@]*\})/) { # leading '}', any preceding blinded comment must not be matched
my $head = $1;
update_nested_indents($head);
$nested_indents_position = length($head);
if (@nested_symbols >= 1) {
$hanging_symbol = @nested_symbols[-1];
$expr_indent = @nested_indents[-1];
} else { # typically end of initialiizer expr or enum
$expr_indent = 0;
}
} elsif (m/^([\s@]*)(static_)?ASN1_ITEM_TEMPLATE_END(\W|$)/) { # workaround for ASN1 macro indented as '}'
$local_offset = -INDENT_LEVEL;
$expr_indent = 0;
} elsif (m/;.*?\}/) { # expr ends with ';' before '}'
report("code before '}'");
}
}
if (@in_do_hanging_offsets != 0 && # note there is nothing like "unexpected 'while'"
m/^[\s@]*while(\W|$)/) { # leading 'while'
$hanging_offset = pop @in_do_hanging_offsets;
}
if ($if_maybe_terminated) {
if (m/(^|\W)else(\W|$)/) { # (not necessarily leading) 'else'
if (@in_if_hanging_offsets == 0) {
report("unexpected 'else'");
} else {
$hanging_offset = pop @in_if_hanging_offsets;
}
} else {
@in_if_hanging_offsets = (); # note there is nothing like "unclosed 'if'"
$hanging_offset = 0;
}
}
if (!$in_stmt) { # at block level, i.e., outside expr/stmt/type decl/var def/fn hdr
$if_maybe_terminated = 0;
if (my ($head, $before, $tail) = m/^([\s@]*([^{}]*)\})[\s@]*(.*)$/) { # leading closing '}', but possibly
# with non-whitespace non-'{' before
report("code after '}'") unless $tail eq "" || $tail =~ m/(else|while|OSSL_TRACE_END)(\W|$)/;
my $outermost_level = @nested_block_indents == 1 && @nested_block_indents[0] == 0;
if (!$sloppy_bodylen && $outermost_level && $line_body_start != 0) {
my $body_len = $line - $line_body_start - 1;
report_flexibly($line_function_start, "function body length = $body_len > ".MAX_BODY_LENGTH." lines",
$last_function_header) if $body_len > MAX_BODY_LENGTH;
$line_body_start = 0;
}
if ($before ne "") { # non-whitespace non-'{' before '}'
report("code before '}'");
} else { # leading '}', any preceding blinded comment must not be matched
$local_offset = $block_indent + $hanging_offset - INDENT_LEVEL;
update_nested_indents($head);
$nested_indents_position = length($head);
$local_offset -= ($block_indent + $hanging_offset);
# in effect $local_offset = -INDENT_LEVEL relative to $block_indent + $hanging_offset values before
}
}
# handle opening brace '{' after if/else/while/for/switch/do on line before
if ($hanging_offset > 0 && m/^[\s@]*{/ && # leading opening '{'
$line_before > 0 &&
$contents_before_ =~ m/(^|^.*\W)(if|else|while|for|switch|do)(\W.*$|$)/) {
$keyword_opening_brace = $1;
$hanging_offset -= INDENT_LEVEL; # cancel newly hanging_offset
}
if (m/^[\s@]*(case|default)(\W.*$|$)/) { # leading 'case' or 'default'
my $keyword = $1;
report("code after $keyword: ") if $2 =~ /:.*[^\s@].*$/;
$local_offset = -INDENT_LEVEL;
} else {
if (m/^([\s@]*)(\w+):/) { # (leading) label, cannot be "default"
$local_offset = -INDENT_LEVEL + 1 ;
$has_label = 1;
}
}
}
# potential adaptations of indent in first line of macro body in multi-line macro definition
if ($in_directive > 0 && $in_macro_header > 0) {
if ($in_macro_header > 1) { # still in macro definition header
$in_macro_header += parens_balance($_);
} else { # begin of macro body
$in_macro_header = 0;
if ($count == $block_indent - $directive_offset # body began with same indentation as preceding code
&& $sloppy_macro) { # workaround for this situation is enabled
$block_indent -= $directive_offset;
$directive_offset = 0;
}
}
}
# check required indentation @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
check_indent() if $count >= 0; # not for #define and not if multi-line string literal is continued
$in_comment = 0 if $in_comment < 0; # multi-line comment has ended
# do some further checks @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
my $outermost_level = $block_indent == 0 + ($in_directive > 0 ? $directive_offset : 0);
report("more than one stmt") if !m/(^|\W)for(\W.*|$)/ && # no 'for' - TODO improve matching
m/;.*;/; # two or more terminators ';', so more than one statement
# check for code block containing a single line/statement
if ($line_before2 > 0 && !$outermost_level && # within function body
$in_typedecl == 0 && @nested_indents == 0 && # not within type declaration nor inside stmt/expr
m/^[\s@]*\}/) { # leading closing brace '}', any preceding blinded comment must not be matched
# TODO extend detection from single-line to potentially multi-line statement
if ($line_opening_brace > 0 &&
($line_opening_brace == $line_before2 ||
$line_opening_brace == $line_before)
&& $contents_before =~ m/;/) { # there is at least one terminator ';', so there is some stmt
# TODO do not report cases where a further else branch
# follows with a block containg more than one line/statement
report_flexibly($line_before, "'$keyword_opening_brace' { 1 stmt }", $contents_before);
}
}
report("one-letter name '$2'") if (m/(^|.*\W)([lIO])(\W.*|$)/); # single-letter name 'l', 'I', or 'O'
# TODO report empty line within local variable definitions
# TODO report missing empty line after local variable definitions
# TODO report needless use of parentheses, while
# macro parameters should always be in parens (except when passed on), e.g., '#define ID(x) (x)'
# adapt required indentation for following lines @@@@@@@@@@@@@@@@@@@@@@@@@@@
# set $in_expr, $in_paren_expr, and $hanging_offset for if/while/for/switch, return/enum, and assignment RHS
my $paren_expr_start = 0;
my $return_enum_start = 0;
my $assignment_start = 0;
my $tmp = $_;
$tmp =~ s/[\!<>=]=/@@/g; # blind (in-)equality symbols like '<=' as '@@' to prevent matching them as '=' below
if (m/^((^|.*\W)(if|while|for|switch))(\W.*|$)$/) { # (last) if/for/while/switch
$paren_expr_start = 1;
} elsif (m/^((^|.*\W)(return|enum))(\W.*|$)/ # (last) return/enum
&& !$in_expr && @nested_indents == 0 && parens_balance($1) == 0) { # not nested enum
$return_enum_start = 1;
} elsif ($tmp =~ m/^(([^=]*)(=))(.*)$/ # (last) '=', i.e., assignment
&& !$in_expr && @nested_indents == 0 && parens_balance($1) == 0) { # not nested assignment
$assignment_start = 1;
}
if ($paren_expr_start || $return_enum_start || $assignment_start)
{
my ($head, $mid, $tail) = ($1, $3, $4);
$keyword_opening_brace = $mid if $mid ne "=";
# to cope with multi-line expressions, do this also if !($tail =~ m/\{/)
push @in_if_hanging_offsets, $hanging_offset if $mid eq "if";
# already handle $head, i.e., anything before expression
update_nested_indents($head, $nested_indents_position);
$nested_indents_position = length($head);
# now can set $in_expr and $in_paren_expr
$in_expr = 1;
$in_paren_expr = 1 if $paren_expr_start;
if ($mid eq "while" && @in_do_hanging_offsets != 0) {
$hanging_offset = pop @in_do_hanging_offsets;
} else {
$hanging_offset += INDENT_LEVEL; # tentatively set hanging_offset, may be canceled by following '{'
}
}
# set $hanging_offset and $keyword_opening_brace for do/else
if (my ($head, $mid, $tail) = m/(^|^.*\W)(else|do)(\W.*|$)$/) { # last else/do, where 'do' is preferred
my $code_before = $head =~ m/[^\s\@}]/; # leading non-whitespace non-comment non-'}'
report("code before '$mid'") if $code_before;
report("code after '$mid'" ) if $tail =~ m/[^\s\@{]/# trailing non-whitespace non-comment non-'{' (non-'\')
&& !($mid eq "else" && $tail =~ m/[\s@]*if(\W|$)/);
if ($mid eq "do") { # workarounds for code before 'do'
if ($head =~ m/(^|^.*\W)(else)(\W.*$|$)/) { # 'else' ... 'do'
$hanging_offset += INDENT_LEVEL; # tentatively set hanging_offset, may be canceled by following '{'
}
if ($head =~ m/;/) { # terminator ';' ... 'do'
@in_if_hanging_offsets = (); # note there is nothing like "unclosed 'if'"
$hanging_offset = 0;
}
}
push @in_do_hanging_offsets, $hanging_offset if $mid eq "do";
if ($code_before && $mid eq "do") {
$hanging_offset = length($head) - $block_indent;
}
if (!$in_paren_expr) {
$keyword_opening_brace = $mid if $tail =~ m/\{/;
$hanging_offset += INDENT_LEVEL;
}
}
# set $in_typedecl and potentially $hanging_offset for type declaration
if (!$in_expr && @nested_indents == 0 && # not in expression
m/(^|^.*\W)(typedef|struct|union|enum)(\W.*|$)$/ &&
parens_balance($1) == 0) { # not in newly started expression
# not needed: $keyword_opening_brace = $2 if $3 =~ m/\{/;
$in_typedecl++;
$hanging_offset += INDENT_LEVEL if m/\*.*\(/; # '*' followed by '(' - seems consistent with Emacs C mode
}
my $bak_in_expr = $in_expr;
my $terminator_position = update_nested_indents($_, $nested_indents_position);
if ($bak_in_expr) {
# on end of non-if/while/for/switch (multi-line) expression (i.e., return/enum/assignment) and
# on end of statement/type declaration/variable definition/function header
if ($terminator_position >= 0 && ($in_typedecl == 0 || @nested_indents == 0)) {
check_nested_nonblock_indents("expr");
$in_expr = 0;
}
} else {
check_nested_nonblock_indents($in_typedecl == 0 ? "stmt" : "decl") if $terminator_position >= 0;
}
# on ';', which terminates the current statement/type declaration/variable definition/function declaration
if ($terminator_position >= 0) {
my $tail = substr($_, $terminator_position + 1);
if (@in_if_hanging_offsets != 0) {
if ($tail =~ m/\s*else(\W|$)/) {
pop @in_if_hanging_offsets;
$hanging_offset -= INDENT_LEVEL;
} elsif ($tail =~ m/[^\s@]/) { # code (not just comment) follows
@in_if_hanging_offsets = (); # note there is nothing like "unclosed 'if'"
$hanging_offset = 0;
} else {
$if_maybe_terminated = 1;
}
} elsif ($tail =~ m/^[\s@]*$/) { # ';' has been trailing, i.e. there is nothing but whitespace and comments
$hanging_offset = 0; # reset in case of terminated assignment ('=') etc.
}
$in_typedecl-- if $in_typedecl != 0 && @nested_in_typedecl == 0; # TODO handle multiple type decls per line
m/(;[^;]*)$/; # match last ';'
$terminator_position = length($_) - length($1) if $1;
# new $terminator_position value may be after the earlier one in case multiple terminators on current line
# TODO check treatment in case of multiple terminators on current line
update_nested_indents($_, $terminator_position + 1);
}
# set hanging expression indent according to nested indents - TODO maybe do better in update_nested_indents()
# also if $in_expr is 0: in statement/type declaration/variable definition/function header
$expr_indent = 0;
for (my $i = -1; $i >= -@nested_symbols; $i--) {
if (@nested_symbols[$i] ne "?") { # conditionals '?' ... ':' are treated specially in check_indent()
$hanging_symbol = @nested_symbols[$i];
$expr_indent = $nested_indents[$i];
# $expr_indent is guaranteed to be != 0 unless @nested_indents contains just outer conditionals
last;
}
}
# remember line number and header containing name of last function defined for reports w.r.t. MAX_BODY_LENGTH
if ($outermost_level && m/(\w+)\s*\(/ && $1 ne "STACK_OF") {
$line_function_start = $line;
$last_function_header = $contents;
}
# special checks for last, typically trailing opening brace '{' in line
if (my ($head, $tail) = m/^(.*)\{(.*)$/) { # match last ... '{'
if ($in_directive == 0 && !$in_expr && $in_typedecl == 0) {
if ($outermost_level) {
if (!$assignment_start && !$bak_in_expr) {
# at end of function definition header (or stmt or var definition)
report("'{' not at beginning") if $head ne "";
$line_body_start = $contents =~ m/LONG BODY/ ? 0 : $line;
}
} else {
$line_opening_brace = $line if $keyword_opening_brace =~ m/do|while|for/;
# using, not assigning, $keyword_opening_brace here because it could be on an earlier line
$line_opening_brace = $line if $keyword_opening_brace =~ m/if|else/ && $extended_1_stmt &&
# TODO prevent false positives for if/else where braces around single-statement branches
# should be avoided but only if all branches have just single statements
# The following helps detecting the exception when handling multiple 'if ... else' branches:
!($keyword_opening_brace eq "else" && $line_opening_brace < $line_before2);
}
report("code after '{'") if $tail=~ m/[^\s\@]/ && # trailing non-whitespace non-comment (non-'\')
!($tail=~ m/\}/); # no '}' after last '{'
}
}
# check for opening brace after if/while/for/switch/do not on same line
# note that "no '{' on same line after '} else'" is handled further below
if (/^[\s@]*{/ && # leading '{'
$line_before > 0 && !($contents_before_ =~ m/^\s*#/) && # not preprocessor directive '#if
(my ($head, $mid, $tail) = ($contents_before_ =~ m/(^|^.*\W)(if|while|for|switch|do)(\W.*$|$)/))) {
my $brace_after = $tail =~ /^[\s@]*{/; # any whitespace or comments then '{'
report("'{' not on same line as preceding '$mid'") if !$brace_after;
}
# check for closing brace on line before 'else' not followed by leading '{'
elsif (my ($head, $tail) = m/(^|^.*\W)else(\W.*$|$)/) {
if (parens_balance($tail) == 0 && # avoid false positive due to unfinished expr on current line
!($tail =~ m/{/) && # after 'else' no '{' on same line
!($head =~ m/}[\s@]*$/) && # not: '}' then any whitespace or comments before 'else'
$line_before > 0 && $contents_before_ =~ /}[\s@]*$/) { # trailing '}' on line before
report("no '{' after '} else'");
}
}
# check for closing brace before 'while' not on same line
if (my ($head, $tail) = m/(^|^.*\W)while(\W.*$|$)/) {
my $brace_before = $head =~ m/}[\s@]*$/; # '}' then any whitespace or comments
# possibly 'if (...)' (with potentially inner '(' and ')') then any whitespace or comments then '{'
if (!$brace_before &&
# does not work here: @in_do_hanging_offsets != 0 && #'while' terminates loop
parens_balance($tail) == 0 && # avoid false positive due to unfinished expr on current line
$tail =~ /;/ && # 'while' terminates loop (by ';')
$line_before > 0 &&
$contents_before_ =~ /}[\s@]*$/) { # on line before: '}' then any whitespace or comments
report("'while' not on same line as preceding '}'");
}
}
# check for missing brace on same line before or after 'else'
if (my ($head, $tail) = m/(^|^.*\W)else(\W.*$|$)/) {
my $brace_before = $head =~ /}[\s@]*$/; # '}' then any whitespace or comments
my $brace_after = $tail =~ /^[\s@]*if[\s@]*\(.*\)[\s@]*{|[\s@]*{/;
# possibly 'if (...)' (with potentially inner '(' and ')') then any whitespace or comments then '{'
if (!$brace_before) {
if ($line_before > 0 && $contents_before_ =~ /}[\s@]*$/) {
report("'else' not on same line as preceding '}'");
} elsif (parens_balance($tail) == 0) { # avoid false positive due to unfinished expr on current line
report("no '}' on same line before 'else ... {'") if $brace_after;
}
} elsif (parens_balance($tail) == 0) { # avoid false positive due to unfinished expr on current line
report("no '{' on same line after '} else'") if $brace_before && !$brace_after;
}
}
POSTPROCESS_DIRECTIVE:
# on begin of multi-line preprocessor directive, adapt indent
# need to use original line contents because trailing '\' may have been stripped above
if ($contents =~ m/^(.*?)[\s@]*\\[\s@]*$/) { # trailing '\' (which is not stripped from $contents),
# typically used in macro definitions (or other preprocessor directives)
if ($in_directive == 0) {
$in_macro_header = m/^\s*#\s*define(\W|$)?(.*)/ ? 1 + parens_balance($2) : 0; # '#define' is beginning
$directive_offset = INDENT_LEVEL;
$block_indent += $directive_offset;
}
$in_directive += 1;
}
# post-processing at end of line @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
LINE_FINISHED:
# on end of multi-line preprocessor directive, adapt indent
if ($in_directive > 0 &&
# need to use original line contents because trailing \ may have been stripped
!($contents =~ m/^(.*?)[\s@]*\\[\s@]*$/)) { # no trailing '\'
$block_indent -= $directive_offset;
$in_directive = 0;
# macro body typically does not include terminating ';'
$hanging_offset = 0; # compensate for this in case macro ends, e.g., as 'while (0)'
}
unless (m/^\s*$/) { # essentially empty line: just whitespace (and maybe a '\')
$line_before2 = $line_before;
$contents_before2 = $contents_before;
$contents_before_2 = $contents_before_;
$line_before = $line;
$contents_before = $contents;
$contents_before_ = $_;
$count_before = $count;
}
if ($self_test) { # debugging
my $should_report = $contents =~ m/\*@(\d)?/ ? 1 : 0;
$should_report = +$1 if $should_report != 0 && defined $1;
print("$ARGV:$line:$num_reports_line reports on:$contents")
if $num_reports_line != $should_report;
}
$num_reports_line = 0;
# post-processing at end of file @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
if (eof) {
# check for essentially empty line (which may include a '\') just before EOF
report(($1 eq "\n" ? "empty line" : $2 ne "" ? "'\\'" : "whitespace")." at EOF")
if $contents =~ m/^(\s*(\\?)\s*)$/;
# report unclosed expression-level nesting
check_nested_nonblock_indents("expr at EOF"); # also adapts @nested_block_indents
# sanity-check balance of block-level { ... } via final $block_indent at end of file
report_flexibly($line, +@nested_block_indents." unclosed '{'", "(EOF)\n") if @nested_block_indents != 0;
# sanity-check balance of #if ... #endif via final preprocessor directive indent at end of file
report_flexibly($line, "$directive_nesting unclosed '#if'", "(EOF)\n") if $directive_nesting != 0;
reset_file_state();
}
}
# final summary report @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
my $num_other_reports = $num_reports - $num_indent_reports - $num_nesting_issues
- $num_syntax_issues - $num_SPC_reports - $num_length_reports;
print "$num_reports ($num_indent_reports indentation, $num_nesting_issues directive nesting, ".
"$num_syntax_issues syntax, $num_SPC_reports whitespace, $num_length_reports length, $num_other_reports other)".
" issues have been found by $0\n" if $num_reports != 0 && !$self_test;
+165 -129
View File
@@ -79,7 +79,6 @@ die "Need one of -[cdehlnouv] flags.\n"
my $temp = '/tmp/docnits.txt';
my $OUT;
my %public;
my $status = 0;
my @sections = ( 'man1', 'man3', 'man5', 'man7' );
@@ -89,7 +88,17 @@ my %mandatory_sections = (
3 => [ 'SYNOPSIS', 'RETURN VALUES' ],
5 => [ ],
7 => [ ]
);
);
# Symbols that we ignored.
# They are internal macros that we currently don't document
my $ignored = qr/(?| ^i2d_
| ^d2i_
| ^DEPRECATEDIN
| \Q_fnsig(3)\E$
| ^IMPLEMENT_
| ^_?DECLARE_
)/x;
# Collect all POD files, both internal and public, and regardless of location
# We collect them in a hash table with each file being a key, so we can attach
@@ -266,13 +275,13 @@ sub name_synopsis {
return unless $contents =~ /=head1 NAME(.*)=head1 SYNOPSIS/ms;
my $tmp = $1;
$tmp =~ tr/\n/ /;
err($id, "trailing comma before - in NAME")
err($id, "Trailing comma before - in NAME")
if $tmp =~ /, *-/;
$tmp =~ s/ -.*//g;
err($id, "POD markup among the names in NAME")
if $tmp =~ /[<>]/;
$tmp =~ s/ */ /g;
err($id, "missing comma in NAME")
err($id, "Missing comma in NAME")
if $tmp =~ /[^,] /;
my $dirname = dirname($filename);
@@ -284,7 +293,7 @@ sub name_synopsis {
foreach my $n ( split ',', $tmp ) {
$n =~ s/^\s+//;
$n =~ s/\s+$//;
err($id, "the name '$n' contains white-space")
err($id, "The name '$n' contains white-space")
if $n =~ /\s/;
$names{$n} = 1;
$foundfilename++ if $n eq $simplename;
@@ -293,17 +302,11 @@ sub name_synopsis {
files(TAGS => [ 'manual', $section ]) )
&& $n ne $simplename );
}
err($id, "the following exist as other .pod files:",
err($id, "The following exist as other .pod files:",
sort keys %foundfilenames)
if %foundfilenames;
err($id, "$simplename (filename) missing from NAME section")
unless $foundfilename;
if ( $filename !~ /internal/ ) {
foreach my $n ( keys %names ) {
err($id, "$n is not public")
if !defined $public{$n};
}
}
# Find all functions in SYNOPSIS
return unless $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms;
@@ -318,7 +321,7 @@ sub name_synopsis {
if ( $line =~ /typedef.*\(\*\S+\)\s+\(/ ) {
# a callback function with whitespace before the argument list:
# typedef ... (*NAME) (...
err($id, "function typedef has space before arg list: $line");
err($id, "Function typedef has space before arg list: $line");
}
if ( $line =~ /env (\S*)=/ ) {
# environment variable env NAME=...
@@ -350,7 +353,7 @@ sub name_synopsis {
$names{$sym} = 2;
# Do some sanity checks on the prototype.
err($id, "prototype missing spaces around commas: $line")
err($id, "Prototype missing spaces around commas: $line")
if $is_prototype && $line =~ /[a-z0-9],[^ ]/;
}
@@ -386,20 +389,20 @@ sub check_head_style {
foreach my $line ( split /\n+/, $contents ) {
next unless $line =~ /^=head/;
if ( $line =~ /head1/ ) {
err($id, "duplicate section $line")
err($id, "Duplicate section $line")
if defined $head1{$line};
$head1{$line} = 1;
%subheads = ();
} else {
err($id, "duplicate subsection $line")
err($id, "Duplicate subsection $line")
if defined $subheads{$line};
$subheads{$line} = 1;
}
err($id, "period in =head")
err($id, "Period in =head")
if $line =~ /\.[^\w]/ or $line =~ /\.$/;
err($id, "not all uppercase in =head1")
if $line =~ /head1.*[a-z]/;
err($id, "all uppercase in subhead")
err($id, "All uppercase in subhead")
if $line =~ /head[234][ A-Z0-9]+$/;
}
}
@@ -537,7 +540,7 @@ sub functionname_check {
$unmarked =~ s/[BIL]<|>//msg;
err($id, "Malformed symbol: $symbol")
unless $symbol =~ /^B<.*>$/ && $unmarked =~ /^${symbol_re}$/
unless $symbol =~ /^B<.*?>$/ && $unmarked =~ /^${symbol_re}$/
}
# We can't do the kind of collecting coolness that option_check()
@@ -596,25 +599,26 @@ sub wording {
# Sigh, trademark
next if $k eq 'file system'
and $contents =~ /Microsoft Encrypted File System/;
err($id, "found '$k' should use '$preferred_words{$k}'")
err($id, "Found '$k' should use '$preferred_words{$k}'")
if $contents =~ /\b\Q$k\E\b/i;
}
err($id, "found 'epoch' should use 'Epoch'")
err($id, "Found 'epoch' should use 'Epoch'")
if $contents =~ /\bepoch\b/;
if ( $id =~ m@man1/@ ) {
err($id, "found 'tool' in NAME, should use 'command'")
if $contents =~ /=head1 NAME.*\btool\b.*=head1 SYNOPSIS/s;
err($id, "found 'utility' in NAME, should use 'command'")
if $contents =~ /NAME.*\butility\b.*=head1 SYNOPSIS/s;
}
}
# Perform all sorts of nit/error checks on a manpage
sub check {
my $filename = shift;
my %podinfo = @_;
my $filename = $podinfo{filename};
my $dirname = basename(dirname($filename));
my $contents = '';
{
local $/ = undef;
open POD, $filename or die "Couldn't open $filename, $!";
$contents = <POD>;
close POD;
}
my $contents = $podinfo{contents};
my $id = "${filename}:1:";
check_head_style($id, $contents);
@@ -656,7 +660,7 @@ sub check {
unless $target =~ /^[_[:alpha:]][_[:alnum:]]*$/
}
unless ( $contents =~ /=for openssl generic/ ) {
unless ( $contents =~ /^=for openssl generic/ms ) {
if ( $filename =~ m|man3/| ) {
name_synopsis($id, $filename, $contents);
functionname_check($id, $filename, $contents);
@@ -667,25 +671,25 @@ sub check {
wording($id, $contents);
err($id, "doesn't start with =pod")
err($id, "Doesn't start with =pod")
if $contents !~ /^=pod/;
err($id, "doesn't end with =cut")
err($id, "Doesn't end with =cut")
if $contents !~ /=cut\n$/;
err($id, "more than one cut line.")
err($id, "More than one cut line.")
if $contents =~ /=cut.*=cut/ms;
err($id, "EXAMPLE not EXAMPLES section.")
if $contents =~ /=head1 EXAMPLE[^S]/;
err($id, "WARNING not WARNINGS section.")
if $contents =~ /=head1 WARNING[^S]/;
err($id, "missing copyright")
err($id, "Missing copyright")
if $contents !~ /Copyright .* The OpenSSL Project Authors/;
err($id, "copyright not last")
err($id, "Copyright not last")
if $contents =~ /head1 COPYRIGHT.*=head/ms;
err($id, "head2 in All uppercase")
if $contents =~ /head2\s+[A-Z ]+\n/;
err($id, "extra space after head")
err($id, "Extra space after head")
if $contents =~ /=head\d\s\s+/;
err($id, "period in NAME section")
err($id, "Period in NAME section")
if $contents =~ /=head1 NAME.*\.\n.*=head1 SYNOPSIS/ms;
err($id, "Duplicate $1 in L<>")
if $contents =~ /L<([^>]*)\|([^>]*)>/ && $1 eq $2;
@@ -701,7 +705,7 @@ sub check {
my $count = 0;
foreach my $line ( split /\n+/, $1 ) {
if ( $line =~ m@include <openssl/@ ) {
err($id, "has multiple includes")
err($id, "Has multiple includes")
if ++$count == 2;
} else {
$count = 0;
@@ -728,15 +732,43 @@ sub check {
$section = $1 if $dirname =~ /man([1-9])/;
foreach ( (@{$mandatory_sections{'*'}}, @{$mandatory_sections{$section}}) ) {
err($id, "missing $_ head1 section")
err($id, "Missing $_ head1 section")
if $contents !~ /^=head1\s+${_}\s*$/m;
}
}
# Information database ###############################################
# Map of links in each POD file; filename => [ "foo(1)", "bar(3)", ... ]
my %link_map = ();
# Map of names in each POD file or from "missing" files; possible values are:
# If found in a POD files, "name(s)" => filename
# If found in a "missing" file or external, "name(s)" => ''
my %name_map = ();
# State of man-page names.
# %state is affected by loading util/*.num and util/*.syms
# Values may be one of:
# 'crypto' : belongs in libcrypto (loaded from libcrypto.num)
# 'ssl' : belongs in libssl (loaded from libssl.num)
# 'other' : belongs in libcrypto or libssl (loaded from other.syms)
# 'internal' : Internal
# 'public' : Public (generic name or external documentation)
# Any of these values except 'public' may be prefixed with 'missing_'
# to indicate that they are known to be missing.
my %state;
# %missing is affected by loading util/missing*.txt. Values may be one of:
# 'crypto' : belongs in libcrypto (loaded from libcrypto.num)
# 'ssl' : belongs in libssl (loaded from libssl.num)
# 'other' : belongs in libcrypto or libssl (loaded from other.syms)
# 'internal' : Internal
my %missing;
# Parse libcrypto.num, etc., and return sorted list of what's there.
sub parsenum {
sub loadnum ($;$) {
my $file = shift;
my @apis;
my $type = shift;
my @symbols;
open my $IN, '<', catfile($config{sourcedir}, $file)
or die "Can't open $file, $!, stopped";
@@ -745,44 +777,54 @@ sub parsenum {
next if /^#/;
next if /\bNOEXIST\b/;
my @fields = split();
die "Malformed line $_"
die "Malformed line $. in $file: $_"
if scalar @fields != 2 && scalar @fields != 4;
push @apis, $fields[0];
$state{$fields[0].'(3)'} = $type // 'internal';
}
close $IN;
return sort @apis;
}
# Parse all the manpages, getting return map of what they document
# (by looking at their NAME sections).
# Map of links in each POD file; filename => [ "foo(1)", "bar(3)", ... ]
my %link_map = ();
# Map of names in each POD file; "name(s)" => filename
my %name_map = ();
# Load file of symbol names that we know aren't documented.
sub loadmissing($)
sub loadmissing($;$)
{
my $missingfile = shift;
my @missing;
my $type = shift;
open FH, catfile($config{sourcedir}, $missingfile)
or die "Can't open $missingfile";
while ( <FH> ) {
chomp;
next if /^#/;
push @missing, $_;
$missing{$_} = $type // 'internal';
}
close FH;
}
for (@missing) {
err("$missingfile:", "$_ is documented in $name_map{$_}")
if !$opt_o && exists $name_map{$_} && defined $name_map{$_};
# Check that we have consistent public / internal documentation and declaration
sub checkstate () {
# Collect all known names, no matter where they come from
my %names = map { $_ => 1 } (keys %name_map, keys %state, keys %missing);
# Check section 3, i.e. functions and macros
foreach ( grep { $_ =~ /\(3\)$/ } sort keys %names ) {
next if ( $name_map{$_} // '') eq '' || $_ =~ /$ignored/;
# If a man-page isn't recorded public or if it's recorded missing
# and internal, it's declared to be internal.
my $declared_internal =
($state{$_} // 'internal') eq 'internal'
|| ($missing{$_} // '') eq 'internal';
# If a man-page isn't recorded internal or if it's recorded missing
# and not internal, it's declared to be public
my $declared_public =
($state{$_} // 'internal') ne 'internal'
|| ($missing{$_} // 'internal') ne 'internal';
err("$_ is supposedly public but is documented as internal")
if ( $declared_public && $name_map{$_} =~ /\/internal\// );
err("$_ is supposedly internal but is documented as public")
if ( $declared_internal && $name_map{$_} !~ /\/internal\// );
}
return @missing;
}
# Check for undocumented macros; ignore those in the "missing" file
@@ -790,13 +832,6 @@ sub loadmissing($)
sub checkmacros {
my $count = 0;
my %seen;
my @missing;
if ( $opt_o ) {
@missing = loadmissing('util/missingmacro111.txt');
} elsif ( $opt_v ) {
@missing = loadmissing('util/missingmacro.txt');
}
foreach my $f ( files(TAGS => 'public_header') ) {
# Skip some internals we don't want to document yet.
@@ -809,16 +844,10 @@ sub checkmacros {
while ( <IN> ) {
next unless /^#\s*define\s*(\S+)\(/;
my $macro = "$1(3)"; # We know they're all in section 3
next if exists $name_map{$macro} || defined $seen{$macro};
next if $macro =~ /^i2d_/
|| $macro =~ /^d2i_/
|| $macro =~ /^DEPRECATEDIN/
|| $macro =~ /\Q_fnsig(3)\E$/
|| $macro =~ /^IMPLEMENT_/
|| $macro =~ /^_?DECLARE_/;
# Skip macros known to be missing
next if $opt_v && grep( /^\Q$macro\E$/, @missing);
next if defined $name_map{$macro}
|| defined $missing{$macro}
|| defined $seen{$macro}
|| $macro =~ /$ignored/;
err("$f:", "macro $macro undocumented")
if $opt_d || $opt_e;
@@ -833,39 +862,38 @@ sub checkmacros {
# Find out what is undocumented (filtering out the known missing ones)
# and display them.
sub printem {
my $libname = shift;
my $numfile = shift;
my $missingfile = shift;
sub printem ($) {
my $type = shift;
my $count = 0;
my %seen;
my @missing = loadmissing($missingfile) if $opt_v;
foreach my $func ( parsenum($numfile) ) {
foreach my $func ( grep { $_ eq $type } sort keys %state ) {
$func .= '(3)'; # We know they're all in section 3
next if exists $name_map{$func} || defined $seen{$func};
# Skip functions known to be missing.
next if $opt_v && grep( /^\Q$func\E$/, @missing);
# Skip functions known to be missing
next if $opt_v && defined $name_map{$func} && $name_map{$func} eq '';
err("$libname:", "function $func undocumented")
# Skip known names
next if defined $name_map{$func} || defined $seen{$func};
err("$type:", "function $func undocumented")
if $opt_d || $opt_e;
$count++;
$seen{$func} = 1;
}
err("# $count in $numfile are not documented")
err("# $count lib$type names are not documented")
if $count > 0;
}
# Collect all the names in a manpage.
sub collectnames {
my $filename = shift;
my %podinfo = @_;
my $filename = $podinfo{filename};
$filename =~ m|man(\d)/|;
my $section = $1;
my $simplename = basename($filename, ".pod");
my $id = "${filename}:1:";
my %podinfo = extract_pod_info($filename, { debug => $debug });
my $is_generic = $podinfo{contents} =~ /^=for openssl generic/ms;
unless ( grep { $simplename eq $_ } @{$podinfo{names}} ) {
err($id, "$simplename not in NAME section");
@@ -876,12 +904,15 @@ sub collectnames {
err($id, "'$name' contains white space")
if $name =~ /\s/;
my $name_sec = "$name($section)";
if ( !exists $name_map{$name_sec} ) {
if ( !defined $name_map{$name_sec} ) {
$name_map{$name_sec} = $filename;
$state{$name_sec} =
( $filename =~ /\/internal\// ? 'internal' : 'public' )
if $is_generic;
} elsif ( $filename eq $name_map{$name_sec} ) {
err($id, "$name_sec duplicated in NAME section of",
$name_map{$name_sec});
} else {
} elsif ( $name_map{$name_sec} ne '' ) {
err($id, "$name_sec also in NAME section of",
$name_map{$name_sec});
}
@@ -889,7 +920,8 @@ sub collectnames {
if ( $podinfo{contents} =~ /=for openssl foreign manual (.*)\n/ ) {
foreach my $f ( split / /, $1 ) {
$name_map{$f} = undef; # It still exists!
$name_map{$f} = ''; # It still exists!
$state{$f} = 'public'; # We assume!
}
}
@@ -911,24 +943,15 @@ sub checklinks {
foreach my $filename ( sort keys %link_map ) {
foreach my $link ( @{$link_map{$filename}} ) {
err("${filename}:1:", "reference to non-existing $link")
unless exists $name_map{$link};
unless defined $name_map{$link} || defined $missing{$link};
err("${filename}:1:", "reference of internal $link in public documentation $filename")
if ( ( ($state{$link} // '') eq 'internal'
|| ($missing{$link} // '') eq 'internal' )
&& $filename !~ /\/internal\// );
}
}
}
# Load the public symbol/macro names
sub publicize {
foreach my $name ( parsenum('util/libcrypto.num') ) {
$public{$name} = 1;
}
foreach my $name ( parsenum('util/libssl.num') ) {
$public{$name} = 1;
}
foreach my $name ( parsenum('util/other.syms') ) {
$public{$name} = 1;
}
}
# Cipher/digests to skip if they show up as "not implemented"
# because they are, via the "-*" construct.
my %skips = (
@@ -1055,26 +1078,42 @@ if ( $opt_c ) {
exit $status;
}
# Preparation for some options, populate %name_map and %link_map
if ( $opt_l || $opt_u || $opt_v ) {
foreach ( files(TAGS => 'manual') ) {
collectnames($_);
# Populate %state
loadnum('util/libcrypto.num', 'crypto');
loadnum('util/libssl.num', 'ssl');
loadnum('util/other.syms', 'other');
loadnum('util/other-internal.syms');
if ( $opt_o ) {
loadmissing('util/missingmacro111.txt', 'crypto');
loadmissing('util/missingcrypto111.txt', 'crypto');
loadmissing('util/missingssl111.txt', 'ssl');
} else {
loadmissing('util/missingmacro.txt', 'crypto');
loadmissing('util/missingcrypto.txt', 'crypto');
loadmissing('util/missingssl.txt', 'ssl');
loadmissing('util/missingcrypto-internal.txt');
loadmissing('util/missingssl-internal.txt');
}
if ( $opt_n || $opt_l || $opt_u || $opt_v ) {
my @files_to_read = ( $opt_n && @ARGV ) ? @ARGV : files(TAGS => 'manual');
foreach (@files_to_read) {
my %podinfo = extract_pod_info($_, { debug => $debug });
collectnames(%podinfo)
if ( $opt_l || $opt_u || $opt_v );
check(%podinfo)
if ( $opt_n );
}
}
if ( $opt_l ) {
foreach my $func ( loadmissing("util/missingcrypto.txt") ) {
$name_map{$func} = undef;
}
checklinks();
}
if ( $opt_n ) {
publicize();
foreach ( @ARGV ? @ARGV : files(TAGS => 'manual') ) {
check($_);
}
# If not given args, check that all man1 commands are named properly.
if ( scalar @ARGV == 0 ) {
foreach ( files(TAGS => [ 'public_manual', 'man1' ]) ) {
@@ -1084,14 +1123,11 @@ if ( $opt_n ) {
}
}
checkstate();
if ( $opt_u || $opt_v) {
if ( $opt_o ) {
printem('crypto', 'util/libcrypto.num', 'util/missingcrypto111.txt');
printem('ssl', 'util/libssl.num', 'util/missingssl111.txt');
} else {
printem('crypto', 'util/libcrypto.num', 'util/missingcrypto.txt');
printem('ssl', 'util/libssl.num', 'util/missingssl.txt');
}
printem('crypto');
printem('ssl');
checkmacros();
}
+102 -8
View File
@@ -4604,8 +4604,8 @@ OSSL_PARAM_get_utf8_ptr ? 3_0_0 EXIST::FUNCTION:
OSSL_PARAM_set_utf8_ptr ? 3_0_0 EXIST::FUNCTION:
OSSL_PARAM_get_octet_ptr ? 3_0_0 EXIST::FUNCTION:
OSSL_PARAM_set_octet_ptr ? 3_0_0 EXIST::FUNCTION:
X509_set0_sm2_id ? 3_0_0 EXIST::FUNCTION:SM2
X509_get0_sm2_id ? 3_0_0 EXIST::FUNCTION:SM2
X509_set0_distinguishing_id ? 3_0_0 EXIST::FUNCTION:
X509_get0_distinguishing_id ? 3_0_0 EXIST::FUNCTION:
EVP_PKEY_get0_engine ? 3_0_0 EXIST::FUNCTION:ENGINE
EVP_MD_up_ref ? 3_0_0 EXIST::FUNCTION:
EVP_MD_fetch ? 3_0_0 EXIST::FUNCTION:
@@ -4650,8 +4650,8 @@ BN_CTX_new_ex ? 3_0_0 EXIST::FUNCTION:
BN_CTX_secure_new_ex ? 3_0_0 EXIST::FUNCTION:
OPENSSL_thread_stop_ex ? 3_0_0 EXIST::FUNCTION:
OSSL_PARAM_locate_const ? 3_0_0 EXIST::FUNCTION:
X509_REQ_set0_sm2_id ? 3_0_0 EXIST::FUNCTION:SM2
X509_REQ_get0_sm2_id ? 3_0_0 EXIST::FUNCTION:SM2
X509_REQ_set0_distinguishing_id ? 3_0_0 EXIST::FUNCTION:
X509_REQ_get0_distinguishing_id ? 3_0_0 EXIST::FUNCTION:
BN_rand_ex ? 3_0_0 EXIST::FUNCTION:
BN_priv_rand_ex ? 3_0_0 EXIST::FUNCTION:
BN_rand_range_ex ? 3_0_0 EXIST::FUNCTION:
@@ -4755,10 +4755,10 @@ OSSL_CMP_CTX_get_option ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_CTX_set_log_cb ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_CTX_print_errors ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_CTX_set1_serverPath ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_CTX_set1_serverName ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_CTX_set1_server ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_CTX_set_serverPort ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_CTX_set1_proxyName ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_CTX_set_proxyPort ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_CTX_set1_proxy ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_CTX_set1_no_proxy ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_CTX_set_http_cb ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_CTX_set_http_cb_arg ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_CTX_get_http_cb_arg ? 3_0_0 EXIST::FUNCTION:CMP
@@ -4802,6 +4802,7 @@ OSSL_CMP_CTX_set1_transactionID ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_CTX_set1_senderNonce ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_log_open ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_log_close ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_print_to_bio ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_print_errors_cb ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CRMF_CERTID_get0_issuer ? 3_0_0 EXIST::FUNCTION:CRMF
OSSL_CRMF_CERTID_get0_serialNumber ? 3_0_0 EXIST::FUNCTION:CRMF
@@ -4937,7 +4938,6 @@ X509_STORE_CTX_print_verify_cb ? 3_0_0 EXIST::FUNCTION:
X509_STORE_get1_all_certs ? 3_0_0 EXIST::FUNCTION:
OSSL_CMP_validate_msg ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_validate_cert_path ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_print_to_bio ? 3_0_0 EXIST::FUNCTION:CMP
EVP_PKEY_CTX_set_ecdh_cofactor_mode ? 3_0_0 EXIST::FUNCTION:EC
EVP_PKEY_CTX_get_ecdh_cofactor_mode ? 3_0_0 EXIST::FUNCTION:EC
EVP_PKEY_CTX_set_ecdh_kdf_type ? 3_0_0 EXIST::FUNCTION:EC
@@ -4950,10 +4950,104 @@ EVP_PKEY_CTX_set0_ecdh_kdf_ukm ? 3_0_0 EXIST::FUNCTION:EC
EVP_PKEY_CTX_get0_ecdh_kdf_ukm ? 3_0_0 EXIST::FUNCTION:EC
EVP_PKEY_CTX_set_rsa_pss_saltlen ? 3_0_0 EXIST::FUNCTION:RSA
EVP_PKEY_CTX_get_rsa_pss_saltlen ? 3_0_0 EXIST::FUNCTION:RSA
d2i_ISSUER_SIGN_TOOL ? 3_0_0 EXIST::FUNCTION:
i2d_ISSUER_SIGN_TOOL ? 3_0_0 EXIST::FUNCTION:
ISSUER_SIGN_TOOL_free ? 3_0_0 EXIST::FUNCTION:
ISSUER_SIGN_TOOL_new ? 3_0_0 EXIST::FUNCTION:
ISSUER_SIGN_TOOL_it ? 3_0_0 EXIST::FUNCTION:
OSSL_SELF_TEST_new ? 3_0_0 EXIST::FUNCTION:
OSSL_SELF_TEST_free ? 3_0_0 EXIST::FUNCTION:
OSSL_SELF_TEST_onbegin ? 3_0_0 EXIST::FUNCTION:
OSSL_SELF_TEST_oncorrupt_byte ? 3_0_0 EXIST::FUNCTION:
OSSL_SELF_TEST_onend ? 3_0_0 EXIST::FUNCTION:
OSSL_PROVIDER_set_default_search_path ? 3_0_0 EXIST::FUNCTION:
X509_digest_sig ? 3_0_0 EXIST::FUNCTION:
OSSL_CMP_MSG_dup ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_ITAV_dup ? 3_0_0 EXIST::FUNCTION:CMP
d2i_OSSL_CMP_PKISI ? 3_0_0 EXIST::FUNCTION:CMP
i2d_OSSL_CMP_PKISI ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_PKISI_free ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_PKISI_new ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_PKISI_it ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_PKISI_dup ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_snprint_PKIStatusInfo ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_STATUSINFO_new ? 3_0_0 EXIST::FUNCTION:CMP
d2i_OSSL_CMP_MSG_bio ? 3_0_0 EXIST::FUNCTION:CMP
i2d_OSSL_CMP_MSG_bio ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_SRV_process_request ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_CTX_server_perform ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_SRV_CTX_new ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_SRV_CTX_free ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_SRV_CTX_init ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_SRV_CTX_get0_cmp_ctx ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_SRV_CTX_get0_custom_ctx ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_SRV_CTX_set_send_unprotected_errors ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_SRV_CTX_set_accept_unprotected ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_SRV_CTX_set_accept_raverified ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_SRV_CTX_set_grant_implicit_confirm ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_exec_IR_ses ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_exec_CR_ses ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_exec_P10CR_ses ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_exec_KUR_ses ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_try_certreq ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_certConf_cb ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_exec_RR_ses ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_exec_GENM_ses ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_MSG_http_perform ? 3_0_0 EXIST::FUNCTION:CMP
EVP_PKEY_gen ? 3_0_0 EXIST::FUNCTION:
EVP_PKEY_CTX_set_rsa_keygen_bits ? 3_0_0 EXIST::FUNCTION:RSA
EVP_PKEY_CTX_set_rsa_keygen_pubexp ? 3_0_0 EXIST::FUNCTION:RSA
EVP_PKEY_CTX_set_rsa_keygen_primes ? 3_0_0 EXIST::FUNCTION:RSA
NCONF_new_with_libctx ? 3_0_0 EXIST::FUNCTION:
CONF_modules_load_file_with_libctx ? 3_0_0 EXIST::FUNCTION:
OPENSSL_CTX_load_config ? 3_0_0 EXIST::FUNCTION:
OSSL_PARAM_BLD_to_param ? 3_0_0 EXIST::FUNCTION:
OSSL_PARAM_BLD_free_params ? 3_0_0 EXIST::FUNCTION:
OSSL_PARAM_BLD_push_int ? 3_0_0 EXIST::FUNCTION:
OSSL_PARAM_BLD_push_uint ? 3_0_0 EXIST::FUNCTION:
OSSL_PARAM_BLD_push_long ? 3_0_0 EXIST::FUNCTION:
OSSL_PARAM_BLD_push_ulong ? 3_0_0 EXIST::FUNCTION:
OSSL_PARAM_BLD_push_int32 ? 3_0_0 EXIST::FUNCTION:
OSSL_PARAM_BLD_push_uint32 ? 3_0_0 EXIST::FUNCTION:
OSSL_PARAM_BLD_push_int64 ? 3_0_0 EXIST::FUNCTION:
OSSL_PARAM_BLD_push_uint64 ? 3_0_0 EXIST::FUNCTION:
OSSL_PARAM_BLD_push_size_t ? 3_0_0 EXIST::FUNCTION:
OSSL_PARAM_BLD_push_double ? 3_0_0 EXIST::FUNCTION:
OSSL_PARAM_BLD_push_BN ? 3_0_0 EXIST::FUNCTION:
OSSL_PARAM_BLD_push_BN_pad ? 3_0_0 EXIST::FUNCTION:
OSSL_PARAM_BLD_push_utf8_string ? 3_0_0 EXIST::FUNCTION:
OSSL_PARAM_BLD_push_utf8_ptr ? 3_0_0 EXIST::FUNCTION:
OSSL_PARAM_BLD_push_octet_string ? 3_0_0 EXIST::FUNCTION:
OSSL_PARAM_BLD_push_octet_ptr ? 3_0_0 EXIST::FUNCTION:
OSSL_PARAM_BLD_new ? 3_0_0 EXIST::FUNCTION:
OSSL_PARAM_BLD_free ? 3_0_0 EXIST::FUNCTION:
EVP_PKEY_set_type_by_keymgmt ? 3_0_0 EXIST::FUNCTION:
OCSP_RESPID_set_by_key_ex ? 3_0_0 EXIST::FUNCTION:OCSP
OCSP_RESPID_match_ex ? 3_0_0 EXIST::FUNCTION:OCSP
SRP_create_verifier_ex ? 3_0_0 EXIST::FUNCTION:SRP
SRP_create_verifier_BN_ex ? 3_0_0 EXIST::FUNCTION:SRP
SRP_Calc_B_ex ? 3_0_0 EXIST::FUNCTION:SRP
SRP_Calc_u_ex ? 3_0_0 EXIST::FUNCTION:SRP
SRP_Calc_x_ex ? 3_0_0 EXIST::FUNCTION:SRP
SRP_Calc_client_key_ex ? 3_0_0 EXIST::FUNCTION:SRP
X509v3_cache_extensions ? 3_0_0 EXIST::FUNCTION:
EVP_PKEY_gettable_params ? 3_0_0 EXIST::FUNCTION:
EVP_PKEY_get_int_param ? 3_0_0 EXIST::FUNCTION:
EVP_PKEY_get_size_t_param ? 3_0_0 EXIST::FUNCTION:
EVP_PKEY_get_bn_param ? 3_0_0 EXIST::FUNCTION:
EVP_PKEY_get_utf8_string_param ? 3_0_0 EXIST::FUNCTION:
EVP_PKEY_get_octet_string_param ? 3_0_0 EXIST::FUNCTION:
EVP_PKEY_is_a ? 3_0_0 EXIST::FUNCTION:
EVP_PKEY_can_sign ? 3_0_0 EXIST::FUNCTION:
evp_pkey_get_EC_KEY_curve_nid ? 3_0_0 EXIST::FUNCTION:EC
X509_STORE_CTX_new_with_libctx ? 3_0_0 EXIST::FUNCTION:
CT_POLICY_EVAL_CTX_new_with_libctx ? 3_0_0 EXIST::FUNCTION:CT
CTLOG_new_with_libctx ? 3_0_0 EXIST::FUNCTION:CT
CTLOG_new_from_base64_with_libctx ? 3_0_0 EXIST::FUNCTION:CT
CTLOG_STORE_new_with_libctx ? 3_0_0 EXIST::FUNCTION:CT
EVP_PKEY_set_ex_data ? 3_0_0 EXIST::FUNCTION:
EVP_PKEY_get_ex_data ? 3_0_0 EXIST::FUNCTION:
EVP_PKEY_CTX_set_ec_paramgen_curve_name ? 3_0_0 EXIST::FUNCTION:EC
EVP_PKEY_CTX_get_ec_paramgen_curve_name ? 3_0_0 EXIST::FUNCTION:EC
EVP_PKEY_CTX_set_ec_paramgen_curve_nid ? 3_0_0 EXIST::FUNCTION:EC
EVP_chacha20_poly1305_draft ? 3_0_0 EXIST::FUNCTION:CHACHA,POLY1305
+3
View File
@@ -0,0 +1,3 @@
WPACKET(3)
WPACKET_init_der(3)
WPACKET_init_null_der(3)
+41 -17
View File
@@ -572,6 +572,39 @@ ENGINE_setup_bsd_cryptodev(3)
ENGINE_unregister_EC(3)
ENGINE_unregister_pkey_asn1_meths(3)
ENGINE_unregister_pkey_meths(3)
EVP_ASYM_CIPHER-RSA(7)
EVP_CIPHER-AES(7)
EVP_CIPHER-ARIA(7)
EVP_CIPHER-BF(7)
EVP_CIPHER-DES(7)
EVP_CIPHER-CAMELLIA(7)
EVP_CIPHER-CAST5(7)
EVP_CIPHER-ChaCha20(7)
EVP_CIPHER-ChaCha20-Poly1305(7)
EVP_CIPHER-DES(7)
EVP_CIPHER-IDEA(7)
EVP_CIPHER-RC2(7)
EVP_CIPHER-RC4(7)
EVP_CIPHER-RC5(7)
EVP_CIPHER-SEED(7)
EVP_CIPHER-SM4(7)
EVP_KDF-KBKDF(7)
EVP_KDF-SSKDF(7)
EVP_KDF-TLS1-PRF(7)
EVP_KEYEXCH-DH(7)
EVP_KEYEXCH-ECDH(7)
EVP_KEYEXCH-DSA(7)
EVP_KEYEXCH-RSA(7)
EVP_KEYEXCH-X25519(7)
EVP_KEYEXCH-X448(7)
EVP_KEYMGMT-DH(7)
EVP_KEYMGMT-EC(7)
EVP_KEYMGMT-DSA(7)
EVP_KEYMGMT-RSA(7)
EVP_KEYMGMT-X25519(7)
EVP_KEYMGMT-X448(7)
EVP_SIGNATURE-DSA(7)
EVP_SIGNATURE-RSA(7)
ERR_clear_last_mark(3)
ERR_get_state(3)
ERR_load_ASN1_strings(3)
@@ -666,8 +699,6 @@ EVP_PKEY_get_attr_by_OBJ(3)
EVP_PKEY_get_attr_count(3)
EVP_PKEY_save_parameters(3)
EVP_PKEY_set1_tls_encodedpoint(3)
EVP_PKEY_set_type(3)
EVP_PKEY_set_type_str(3)
EVP_add_alg_module(3)
EVP_add_cipher(3)
EVP_add_digest(3)
@@ -716,18 +747,14 @@ NAME_CONSTRAINTS_check_CN(3)
NAME_CONSTRAINTS_it(3)
NAMING_AUTHORITY_it(3)
NCONF_WIN32(3)
NCONF_default(3)
NCONF_dump_bio(3)
NCONF_dump_fp(3)
NCONF_free(3)
NCONF_free_data(3)
NCONF_get_number_e(3)
NCONF_get_section(3)
NCONF_get_string(3)
NCONF_load(3)
NCONF_load_bio(3)
NCONF_load_fp(3)
NCONF_new(3)
NETSCAPE_CERT_SEQUENCE_it(3)
NETSCAPE_SPKAC_it(3)
NETSCAPE_SPKI_b64_decode(3)
@@ -882,10 +909,12 @@ OPENSSL_strnlen(3)
OPENSSL_uni2asc(3)
OPENSSL_uni2utf8(3)
OPENSSL_utf82uni(3)
OSSL_CMP_MSG_http_perform(3)
OSSL_CMP_exec_GENM_ses(3)
OSSL_CMP_exec_IR_ses(3)
OSSL_CMP_exec_KUR_ses(3)
OSSL_SERIALIZER-DH(7)
OSSL_SERIALIZER-DSA(7)
OSSL_SERIALIZER-EC(7)
OSSL_SERIALIZER-RSA(7)
OSSL_SERIALIZER-X25519(7)
OSSL_SERIALIZER-X448(7)
OSSL_STORE_do_all_loaders(3)
OSSL_STORE_vctrl(3)
OTHERNAME_cmp(3)
@@ -1087,12 +1116,6 @@ SMIME_crlf_copy(3)
SMIME_read_ASN1(3)
SMIME_text(3)
SMIME_write_ASN1(3)
SRP_Calc_A(3)
SRP_Calc_B(3)
SRP_Calc_client_key(3)
SRP_Calc_server_key(3)
SRP_Calc_u(3)
SRP_Calc_x(3)
SRP_Verify_A_mod_N(3)
SRP_Verify_B_mod_N(3)
SSL_CTX_set0_ctlog_store(3)
@@ -1429,7 +1452,6 @@ X509_aux_print(3)
X509_certificate_type(3)
X509_chain_check_suiteb(3)
X509_check_akid(3)
X509_check_purpose(3)
X509_check_trust(3)
X509_email_free(3)
X509_find_by_issuer_and_serial(3)
@@ -1532,6 +1554,8 @@ conf_ssl_name_find(3)
d2i_X509_bio(3)
d2i_X509_fp(3)
err_free_strings_int(3)
# The following is internal but exported by libcrypto
evp_pkey_get_EC_KEY_curve_nid(3)
i2a_ACCESS_DESCRIPTION(3)
i2a_ASN1_ENUMERATED(3)
i2a_ASN1_INTEGER(3)
View File
+1
View File
@@ -450,6 +450,7 @@ foreach my $lib ( keys %errorfile ) {
#ifndef OPENSSL_${lib}ERR_H
# define OPENSSL_${lib}ERR_H
# pragma once
# include <openssl/opensslconf.h>
# include <openssl/symhacks.h>
-175
View File
@@ -1,175 +0,0 @@
#!/bin/sh
#
# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the Apache License 2.0 (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
#
# openssl-format-source
# - format source tree according to OpenSSL coding style using indent
#
# usage:
# openssl-format-source [-v] [-n] [file|directory] ...
#
# note: the indent options assume GNU indent v2.2.10 which was released
# Feb-2009 so if you have an older indent the options may not
# match what is expected
#
# any marked block comment blocks have to be moved to align manually after
# the reformatting has been completed as marking a block causes indent to
# not move it at all ...
#
PATH=/usr/local/bin:/bin:/usr/bin:$PATH
export PATH
HERE="`dirname $0`"
set -e
INDENT=indent
uname -s | grep BSD > /dev/null && type gindent > /dev/null 2>&1 && INDENT=gindent
if [ $# -eq 0 ]; then
echo "usage: $0 [-v] [-n] [-c] [sourcefile|sourcedir] ..." >&2
exit 1
fi
VERBOSE=false
DONT=false
STOPARGS=false
COMMENTS=false
CHANGED=false
DEBUG=""
# for this exercise, we want to force the openssl style, so we roll
# our own indent profile, which is at a well known location
INDENT_PROFILE="$HERE/indent.pro"
export INDENT_PROFILE
if [ ! -f "$INDENT_PROFILE" ]; then
echo "$0: unable to locate the openssl indent.pro file" >&2
exit 1
fi
# Extra arguments; for adding the comment-formatting
INDENT_ARGS=""
for i
do
if [ "$STOPARGS" != "true" ]; then
case $i in
--) STOPARGS="true"; continue;;
-n) DONT="true"; continue;;
-v) VERBOSE="true";
echo "INDENT_PROFILE=$INDENT_PROFILE";
continue;;
-c) COMMENTS="true";
INDENT_ARGS="-fc1 -fca -cdb -sc";
continue;;
-nc) COMMENTS="true";
continue;;
-d) DEBUG='eval tee "$j.pre" |'
continue;;
esac
fi
if [ -d "$i" ]; then
LIST=`find "$i" -name '*.[ch]' -print`
else
if [ ! -f "$i" ]; then
echo "$0: source file not found: $i" >&2
exit 1
fi
LIST="$i"
fi
for j in $LIST
do
# ignore symlinks - we only ever process the base file - so if we
# expand a directory tree we need to ignore any located symlinks
if [ -d "$i" ]; then
if [ -h "$j" ]; then
continue;
fi
fi
if [ "$DONT" = "false" ]; then
tmp=$(mktemp /tmp/indent.XXXXXX)
trap 'rm -f "$tmp"' HUP INT TERM EXIT
case `basename $j` in
# the list of files that indent is unable to handle correctly
# that we simply leave alone for manual formatting now
obj_dat.h|aes_core.c|aes_x86core.c|ecp_nistz256.c)
echo "skipping $j"
;;
*)
if [ "$COMMENTS" = "true" ]; then
# we have to mark single line comments as /*- ...*/ to stop indent
# messing with them, run expand then indent as usual but with the
# the process-comments options and then undo that marking, and then
# finally re-run indent without process-comments so the marked-to-
# be-ignored comments we did automatically end up getting moved
# into the right position within the code as indent leaves marked
# comments entirely untouched - we appear to have no way to avoid
# the double processing and get the desired output
cat "$j" | \
expand | \
perl -0 -np \
-e 's/(\n#[ \t]*ifdef[ \t]+__cplusplus\n[^\n]*\n#[ \t]*endif\n)/\n\/**INDENT-OFF**\/$1\/**INDENT-ON**\/\n/g;' \
-e 's/(\n\/\*\!)/\n\/**/g;' \
-e 's/(STACK_OF|LHASH_OF)\(([^ \t,\)]+)\)( |\n)/$1_$2_$3/g;' \
| \
perl -np \
-e 's/^([ \t]*)\/\*([ \t]+.*)\*\/[ \t]*$/my ($x1,$x2) = ($1, $2); if (length("$x1$x2")<75 && $x2 !~ m#^\s*\*INDENT-(ON|OFF)\*\s*$#) {$c="-"}else{$c=""}; "$x1\/*$c$x2*\/"/e;' \
-e 's/^\/\* ((Copyright|=|----).*)$/\/*-$1/;' \
-e 's/^((DECLARE|IMPLEMENT)_.*)$/\/**INDENT-OFF**\/\n$1\n\/**INDENT-ON**\//;' \
-e 's/^([ \t]*(make_dh|make_dh_bn|make_rfc5114_td)\(.*\)[ \t,]*)$/\/**INDENT-OFF**\/\n$1\n\/**INDENT-ON**\//;' \
-e 's/^(ASN1_ADB_TEMPLATE\(.*)$/\/**INDENT-OFF**\/\n$1\n\/**INDENT-ON**\//;' \
-e 's/^((ASN1|ADB)_.*_(end|END)\(.*[\){=,;]+[ \t]*)$/$1\n\/**INDENT-ON**\//;' \
-e '/ASN1_(ITEM_ref|ITEM_ptr|ITEM_rptr|PCTX)/ || s/^((ASN1|ADB)_[^\*]*[){=,]+[ \t]*)$/\/**INDENT-OFF**\/\n$1/;' \
-e 's/^(} (ASN1|ADB)_[^\*]*[\){=,;]+)$/$1\n\/**INDENT-ON**\//;' \
| \
$DEBUG $INDENT $INDENT_ARGS | \
perl -np \
-e 's/^([ \t]*)\/\*-(.*)\*\/[ \t]*$/$1\/*$2*\//;' \
-e 's/^\/\*-((Copyright|=|----).*)$/\/* $1/;' \
| $INDENT | \
perl -0 -np \
-e 's/\/\*\*INDENT-(ON|OFF)\*\*\/\n//g;' \
| perl -np \
-e 's/(STACK_OF|LHASH_OF)_([^ \t,]+)_( |\/)/$1($2)$3/g;' \
-e 's/(STACK_OF|LHASH_OF)_([^ \t,]+)_$/$1($2)/g;' \
| perl "$HERE"/su-filter.pl \
> "$tmp"
else
expand "$j" | $INDENT $INDENT_ARGS > "$tmp"
fi;
if cmp -s "$tmp" "$j"; then
if [ "$VERBOSE" = "true" ]; then
echo "$j unchanged"
fi
rm "$tmp"
else
if [ "$VERBOSE" = "true" ]; then
echo "$j changed"
fi
CHANGED=true
mv "$tmp" "$j"
fi
;;
esac
fi
done
done
if [ "$VERBOSE" = "true" ]; then
echo
if [ "$CHANGED" = "true" ]; then
echo "SOURCE WAS MODIFIED"
else
echo "SOURCE WAS NOT MODIFIED"
fi
fi
+3
View File
@@ -0,0 +1,3 @@
ossl_cmp_allow_unprotected_cb_t datatype
#
DEFINE_SPARSE_ARRAY_OF define
+21 -7
View File
@@ -11,7 +11,9 @@ OPENSSL_instrument_bus2 assembler
#
ADMISSION_SYNTAX datatype
ADMISSIONS datatype
ASN1_ITEM datatype
ASN1_STRING_TABLE datatype
ASYNC_callback_fn datatype
BIO_ADDR datatype
BIO_ADDRINFO datatype
BIO_callback_fn datatype
@@ -37,7 +39,6 @@ GEN_SESSION_CB datatype
OPENSSL_Applink external
OPENSSL_CTX datatype
NAMING_AUTHORITY datatype
OCSP_parse_url define
OSSL_HTTP_bio_cb_t datatype
OSSL_PARAM datatype
OSSL_PROVIDER datatype
@@ -68,6 +69,7 @@ RAND_poll_cb datatype
SSL_CTX_allow_early_data_cb_fn datatype
SSL_CTX_keylog_cb_func datatype
SSL_allow_early_data_cb_fn datatype
SSL_async_callback_fn datatype
SSL_client_hello_cb_fn datatype
SSL_custom_ext_add_cb_ex datatype
SSL_custom_ext_free_cb_ex datatype
@@ -111,9 +113,8 @@ custom_ext_free_cb datatype
custom_ext_parse_cb datatype
pem_password_cb datatype
ssl_ct_validation_cb datatype
ASYNC_callback_fn datatype
SSL_async_callback_fn datatype
#
ASN1_BIT_STRING_digest define
BIO_append_filename define
BIO_destroy_bio_pair define
BIO_do_accept define
@@ -124,6 +125,8 @@ BIO_flush define
BIO_get_accept_name define
BIO_get_accept_port define
BIO_get_accept_ip_family define
BIO_get_app_data define
BIO_get_ex_new_index define
BIO_get_peer_name define
BIO_get_peer_port define
BIO_get_bind_mode define
@@ -161,6 +164,7 @@ BIO_set_accept_bios define
BIO_set_accept_name define
BIO_set_accept_port define
BIO_set_accept_ip_family define
BIO_set_app_data define
BIO_set_bind_mode define
BIO_set_buffer_read_data define
BIO_set_buffer_size define
@@ -315,6 +319,7 @@ EVP_rc5_32_12_16_cfb define
EVP_seed_cfb define
EVP_sm4_cfb define
OBJ_cleanup define deprecated 1.1.0
OCSP_parse_url define
OPENSSL_FILE define
OPENSSL_FUNC define
OPENSSL_LINE define
@@ -352,7 +357,9 @@ OpenSSL_add_all_ciphers define deprecated 1.1.0
OpenSSL_add_all_digests define deprecated 1.1.0
OpenSSL_add_ssl_algorithms define
OSSL_CMP_CTX_set_log_verbosity define
OSSL_CMP_DEFAULT_PORT define
OSSL_CMP_CR define
OSSL_CMP_IR define
OSSL_CMP_KUR define
OSSL_CMP_LOG_ALERT define
OSSL_CMP_LOG_CRIT define
OSSL_CMP_LOG_DEBUG define
@@ -363,10 +370,17 @@ OSSL_CMP_LOG_NOTICE define
OSSL_CMP_LOG_WARNING define
OSSL_CMP_MSTR_HELPER define
OSSL_CMP_MSTR define
OSSL_CMP_P10CR define
OSSL_CMP_certConf_cb_t datatype
OSSL_CMP_log_cb_t datatype
OSSL_CMP_severity datatype
OSSL_cmp_certConf_cb_t datatype
OSSL_cmp_log_cb_t datatype
OSSL_cmp_transfer_cb_t datatype
OSSL_CMP_transfer_cb_t datatype
OSSL_CMP_SRV_cert_request_cb_t datatype
OSSL_CMP_SRV_rr_cb_t datatype
OSSL_CMP_SRV_certConf_cb_t datatype
OSSL_CMP_SRV_genm_cb_t datatype
OSSL_CMP_SRV_error_cb_t datatype
OSSL_CMP_SRV_pollReq_cb_t datatype
OSSL_PARAM_TYPE define
OSSL_PARAM_octet_ptr define
OSSL_PARAM_octet_string define
+392
View File
@@ -0,0 +1,392 @@
# Copyright 2016-2019 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the Apache License 2.0 (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
# Author note: this is originally RL::ASN1::OID,
# repurposed by the author for OpenSSL use.
package OpenSSL::OID;
use 5.10.0;
use strict;
use warnings;
use Carp;
use Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
@ISA = qw(Exporter);
@EXPORT = qw(parse_oid encode_oid register_oid
registered_oid_arcs registered_oid_leaves);
@EXPORT_OK = qw(encode_oid_nums);
# Unfortunately, the pairwise List::Util functionality came with perl
# v5.19.3, and I want to target absolute compatibility with perl 5.10
# and up. That means I have to implement quick pairwise functions here.
#use List::Util;
sub _pairs (@);
sub _pairmap (&@);
=head1 NAME
OpenSSL::OID - an OBJECT IDENTIFIER parser / encoder
=head1 VERSION
Version 0.1
=cut
our $VERSION = '0.1';
=head1 SYNOPSIS
use OpenSSL::OID;
# This gives the array ( 1 2 840 113549 1 1 )
my @nums = parse_oid('{ pkcs-1 1 }');
# This gives the array of DER encoded bytes for the OID, i.e.
# ( 42, 134, 72, 134, 247, 13, 1, 1 )
my @bytes = encode_oid('{ pkcs-1 1 }');
# This registers a name with an OID. It's saved internally and
# serves as repository of names for further parsing, such as 'pkcs-1'
# in the strings used above.
register_object('pkcs-1', '{ pkcs 1 }');
use OpenSSL::OID qw(:DEFAULT encode_oid_nums);
# This does the same as encode_oid(), but takes the output of
# parse_oid() as input.
my @bytes = encode_oid_nums(@nums);
=head1 EXPORT
The functions parse_oid and encode_oid are exported by default.
The function encode_oid_nums() can be exported explicitly.
=cut
######## REGEXPS
# ASN.1 object identifiers come in two forms: 1) the bracketed form
#(referred to as ObjectIdentifierValue in X.690), 2) the dotted form
#(referred to as XMLObjIdentifierValue in X.690)
#
# examples of 1 (these are all the OID for rsaEncrypted):
#
# { iso (1) 2 840 11349 1 1 }
# { pkcs 1 1 }
# { pkcs1 1 }
#
# examples of 2:
#
# 1.2.840.113549.1.1
# pkcs.1.1
# pkcs1.1
#
my $identifier_re = qr/[a-z](?:[-_A-Za-z0-9]*[A-Za-z0-9])?/;
# The only difference between $objcomponent_re and $xmlobjcomponent_re is
# the separator in the top branch. Each component is always parsed in two
# groups, so we get a pair of values regardless. That's the reason for the
# empty parentheses.
# Because perl doesn't try to do an exhaustive try of every branch it rather
# stops on the first that matches, we need to have them in order of longest
# to shortest where there may be ambiguity.
my $objcomponent_re = qr/(?|
(${identifier_re}) \s* \((\d+)\)
|
(${identifier_re}) ()
|
()(\d+)
)/x;
my $xmlobjcomponent_re = qr/(?|
(${identifier_re}) \. \((\d+)\)
|
(${identifier_re}) ()
|
() (\d+)
)/x;
my $obj_re =
qr/(?: \{ \s* (?: ${objcomponent_re} \s+ )* ${objcomponent_re} \s* \} )/x;
my $xmlobj_re =
qr/(?: (?: ${xmlobjcomponent_re} \. )* ${xmlobjcomponent_re} )/x;
######## NAME TO OID REPOSITORY
# Recorded OIDs, to support things like '{ pkcs1 1 }'
# Do note that we don't currently support relative OIDs
#
# The key is the identifier.
#
# The value is a hash, composed of:
# type => 'arc' | 'leaf'
# nums => [ LIST ]
# Note that the |type| always starts as a 'leaf', and may change to an 'arc'
# on the fly, as new OIDs are parsed.
my %name2oid = ();
########
=head1 SUBROUTINES/METHODS
=over 4
=item parse_oid()
TBA
=cut
sub parse_oid {
my $input = shift;
croak "Invalid extra arguments" if (@_);
# The components become a list of ( identifier, number ) pairs,
# where they can also be the empty string if they are not present
# in the input.
my @components;
if ($input =~ m/^\s*(${obj_re})\s*$/x) {
my $oid = $1;
@components = ( $oid =~ m/${objcomponent_re}\s*/g );
} elsif ($input =~ m/^\s*(${xmlobj_re})\s*$/) {
my $oid = $1;
@components = ( $oid =~ m/${xmlobjcomponent_re}\.?/g );
}
croak "Invalid ASN.1 object '$input'" unless @components;
die "Internal error when parsing '$input'"
unless scalar(@components) % 2 == 0;
# As we currently only support a name without number as first
# component, the easiest is to have a direct look at it and
# hack it.
my @first = _pairmap {
my ($a, $b) = @$_;
return $b if $b ne '';
return @{$name2oid{$a}->{nums}} if $a ne '' && defined $name2oid{$a};
croak "Undefined identifier $a" if $a ne '';
croak "Empty OID element (how's that possible?)";
} ( @components[0..1] );
my @numbers =
(
@first,
_pairmap {
my ($a, $b) = @$_;
return $b if $b ne '';
croak "Unsupported relative OID $a" if $a ne '';
croak "Empty OID element (how's that possible?)";
} @components[2..$#components]
);
# If the first component has an identifier and there are other
# components following it, we change the type of that identifier
# to 'arc'.
if (scalar @components > 2
&& $components[0] ne ''
&& defined $name2oid{$components[0]}) {
$name2oid{$components[0]}->{type} = 'arc';
}
return @numbers;
}
=item encode_oid()
=cut
# Forward declaration
sub encode_oid_nums;
sub encode_oid {
return encode_oid_nums parse_oid @_;
}
=item register_oid()
=cut
sub register_oid {
my $name = shift;
my @nums = parse_oid @_;
if (defined $name2oid{$name}) {
my $str1 = join(',', @nums);
my $str2 = join(',', @{$name2oid{$name}->{nums}});
croak "Invalid redefinition of $name with different value"
unless $str1 eq $str2;
} else {
$name2oid{$name} = { type => 'leaf', nums => [ @nums ] };
}
}
=item registered_oid_arcs()
=item registered_oid_leaves()
=cut
sub _registered_oids {
my $type = shift;
return grep { $name2oid{$_}->{type} eq $type } keys %name2oid;
}
sub registered_oid_arcs {
return _registered_oids( 'arc' );
}
sub registered_oid_leaves {
return _registered_oids( 'leaf' );
}
=item encode_oid_nums()
=cut
# Internal helper. It takes a numeric OID component and generates the
# DER encoding for it.
sub _gen_oid_bytes {
my $num = shift;
my $cnt = 0;
return ( $num ) if $num < 128;
return ( ( map { $_ | 0x80 } _gen_oid_bytes($num >> 7) ), $num & 0x7f );
}
sub encode_oid_nums {
my @numbers = @_;
croak 'Invalid OID values: ( ', join(', ', @numbers), ' )'
if (scalar @numbers < 2
|| $numbers[0] < 0 || $numbers[0] > 2
|| $numbers[1] < 0 || $numbers[1] > 39);
my $first = shift(@numbers) * 40 + shift(@numbers);
@numbers = ( $first, map { _gen_oid_bytes($_) } @numbers );
return @numbers;
}
=back
=head1 AUTHOR
Richard levitte, C<< <richard at levitte.org> >>
=cut
######## Helpers
sub _pairs (@) {
croak "Odd number of arguments" if @_ & 1;
my @pairlist = ();
while (@_) {
my $x = [ shift, shift ];
push @pairlist, $x;
}
return @pairlist;
}
sub _pairmap (&@) {
my $block = shift;
map { $block->($_) } _pairs @_;
}
######## UNIT TESTING
use Test::More;
sub TEST {
# Order is important, so we make it a pairwise list
my @predefined =
(
'pkcs' => '1.2.840.113549',
'pkcs-1' => 'pkcs.1',
);
my %good_cases =
(
' 1.2.840.113549.1.1 ' => [ 42, 134, 72, 134, 247, 13, 1, 1 ],
'pkcs.1.1' => [ 42, 134, 72, 134, 247, 13, 1, 1 ],
'pkcs-1.1' => [ 42, 134, 72, 134, 247, 13, 1, 1 ],
' { iso (1) 2 840 113549 1 1 } ' => [ 42, 134, 72, 134, 247, 13, 1, 1 ],
'{ pkcs 1 1 } ' => [ 42, 134, 72, 134, 247, 13, 1, 1 ],
'{pkcs-1 1 }' => [ 42, 134, 72, 134, 247, 13, 1, 1 ],
);
my @bad_cases =
(
' { 1.2.840.113549.1.1 } ',
);
plan tests =>
scalar ( @predefined ) / 2
+ scalar ( keys %good_cases )
+ scalar @bad_cases;
note 'Predefine a few names OIDs';
foreach my $pair ( _pairs @predefined ) {
ok( defined eval { register_oid(@$pair) },
"Registering $pair->[0] => $pair->[1]" );
}
note 'Good cases';
foreach ( keys %good_cases ) {
subtest "Checking '$_'" => sub {
my $oid = shift;
plan tests => 5;
my (@l, @e);
ok( scalar (@l = eval { parse_oid $oid }) > 0,
"Parsing" );
diag $@ unless @l;
ok( scalar (@e = eval { encode_oid_nums @l }) > 0,
"Encoding via encode_oid_nums()" );
diag $@ unless @e;
is_deeply(\@e, $good_cases{$oid}, "Checking encoding");
note "'$oid' => ", join(', ', @e) if @e;
ok( scalar (@e = eval { encode_oid $oid }) > 0,
"Encoding directly" );
diag $@ unless @e;
is_deeply(\@e, $good_cases{$oid}, "Checking encoding");
note "'$oid' => ", join(', ', @e) if @e;
},
$_;
}
note 'Bad cases';
foreach ( @bad_cases ) {
subtest "Checking '$_'" => sub {
my $oid = shift;
plan tests => 2;
my (@l, @e);
ok( scalar (@l = eval { parse_oid $oid }) == 0,
"Parsing '$oid'" );
note $@ unless @l;
ok( scalar (@e = eval { encode_oid_nums @l }) == 0,
"Encoding '$oid'" );
note $@ unless @e;
note "'$oid' => ", join(', ', @e) if @e;
},
$_;
}
}
1; # End of OpenSSL::OID
+2 -1
View File
@@ -185,7 +185,8 @@ sub extract_pod_info {
return ( section => $podinfo{section},
names => [ @names, @invisible_names ],
contents => $contents );
contents => $contents,
filename => $filename );
}
1;
+9 -6
View File
@@ -19,11 +19,7 @@ $ENV{OPENSSL_MODULES} = $std_providers
my $use_system = 0;
my @cmd;
if (($ENV{EXE_SHELL} // '') ne '') {
# We don't know what $ENV{EXE_SHELL} contains, so we must use the one
# string form to ensure that exec invokes a shell as needed.
@cmd = ( join(' ', $ENV{EXE_SHELL}, @ARGV) );
} elsif (-x $unix_shlib_wrap) {
if (-x $unix_shlib_wrap) {
@cmd = ( $unix_shlib_wrap, @ARGV );
} else {
# Hope for the best
@@ -39,5 +35,12 @@ my $waitcode = system @cmd;
# (exitcode << 8 | signalcode)
die "wrap.pl: Failed to execute '", join(' ', @cmd), "': $!\n"
if $waitcode == -1;
exit($? & 255) if ($? & 255) != 0;
# When the subprocess aborted on a signal, mimic what Unix shells do, by
# converting the signal code to an exit code by setting the high bit.
# This only happens on Unix flavored operating systems, the others don't
# have this sort of signaling to date, and simply leave the low byte zero.
exit(($? & 255) | 128) if ($? & 255) != 0;
# When not a signal, just shift down the subprocess exit code and use that.
exit($? >> 8);