Various small build improvements on mkdef.pl, progs.pl, crypto/init.c, crypto/mem.c
authorDavid von Oheimb <David.von.Oheimb@siemens.com>
Mon, 8 Jan 2018 13:13:51 +0000 (14:13 +0100)
committerRichard Levitte <levitte@openssl.org>
Tue, 9 Jan 2018 03:02:34 +0000 (04:02 +0100)
Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4994)

apps/progs.pl
crypto/init.c
crypto/mem.c
util/mkdef.pl

index 65e345334001a479a52d488b542cd44a216b14b0..921d3d19840d274a7652fb6ac3cb608069d1c6ad 100644 (file)
@@ -26,7 +26,7 @@ my @openssl_source =
         @{$unified_info{sources}->{$apps_openssl}};
 
 foreach my $filename (@openssl_source) {
         @{$unified_info{sources}->{$apps_openssl}};
 
 foreach my $filename (@openssl_source) {
-    open F, $filename or die "Couldn't open $_: $!\n";
+    open F, $filename or die "Couldn't open $filename: $!\n";
     foreach ( grep /$cmdre/, <F> ) {
         my @foo = /$cmdre/;
         $commands{$1} = 1;
     foreach ( grep /$cmdre/, <F> ) {
         my @foo = /$cmdre/;
         $commands{$1} = 1;
index 143e01a44a5b27b2157c526138e56c32d09b2cec..a10b48d435fe1feb3368ae778d8fd40268e0fd39 100644 (file)
@@ -73,7 +73,6 @@ struct ossl_init_stop_st {
 };
 
 static CRYPTO_RWLOCK *glock_lock = NULL;
 };
 
 static CRYPTO_RWLOCK *glock_lock = NULL;
-static CRYPTO_ONCE glock_once = CRYPTO_ONCE_STATIC_INIT;
 
 static OPENSSL_INIT_STOP *stop_handlers = NULL;
 static CRYPTO_RWLOCK *init_lock = NULL;
 
 static OPENSSL_INIT_STOP *stop_handlers = NULL;
 static CRYPTO_RWLOCK *init_lock = NULL;
@@ -726,6 +725,7 @@ DEFINE_RUN_ONCE_STATIC(glock_init)
  */
 CRYPTO_RWLOCK *CRYPTO_THREAD_glock_new(const char *name)
 {
  */
 CRYPTO_RWLOCK *CRYPTO_THREAD_glock_new(const char *name)
 {
+    static CRYPTO_ONCE glock_once = CRYPTO_ONCE_STATIC_INIT;
     GLOBAL_LOCK *newlock;
 
     if (glock_lock == NULL && !RUN_ONCE(&glock_once, glock_init))
     GLOBAL_LOCK *newlock;
 
     if (glock_lock == NULL && !RUN_ONCE(&glock_once, glock_init))
index c77584cd5f6c809d65a0d564bfacda7c4cdfd634..920f7999fc77b1140f483bc0384d3f3ced97930f 100644 (file)
@@ -136,9 +136,9 @@ static void parseit(void)
  * Some rand() implementations aren't good, but we're not
  * dealing with secure randomness here.
  */
  * Some rand() implementations aren't good, but we're not
  * dealing with secure randomness here.
  */
-#ifdef _WIN32
-# define random() rand()
-#endif
+# ifdef _WIN32
+#  define random() rand()
+# endif
 /*
  * See if the current malloc should fail.
  */
 /*
  * See if the current malloc should fail.
  */
@@ -146,6 +146,8 @@ static int shouldfail(void)
 {
     int roll = (int)(random() % 100);
     int shoulditfail = roll < md_fail_percent;
 {
     int roll = (int)(random() % 100);
     int shoulditfail = roll < md_fail_percent;
+# ifndef _WIN32
+/* suppressed on Windows as POSIX-like file descriptors are non-inheritable */
     int len;
     char buff[80];
 
     int len;
     char buff[80];
 
@@ -156,15 +158,16 @@ static int shouldfail(void)
         len = strlen(buff);
         if (write(md_tracefd, buff, len) != len)
             perror("shouldfail write failed");
         len = strlen(buff);
         if (write(md_tracefd, buff, len) != len)
             perror("shouldfail write failed");
-#ifndef OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE
+#  ifndef OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE
         if (shoulditfail) {
             void *addrs[30];
             int num = backtrace(addrs, OSSL_NELEM(addrs));
 
             backtrace_symbols_fd(addrs, num, md_tracefd);
         }
         if (shoulditfail) {
             void *addrs[30];
             int num = backtrace(addrs, OSSL_NELEM(addrs));
 
             backtrace_symbols_fd(addrs, num, md_tracefd);
         }
-#endif
+#  endif
     }
     }
+# endif
 
     if (md_count) {
         /* If we used up this one, go to the next. */
 
     if (md_count) {
         /* If we used up this one, go to the next. */
index 828ddc0f156fd66dcfde9744ce94b8daf773e709..16a660f5a5c9cf7a043c5235b7dfd583da10d0db 100755 (executable)
@@ -106,6 +106,8 @@ use OpenSSL::Glob;
 (my $SO_VARIANT = qq{\U$target{"shlib_variant"}}) =~ s/\W/_/g;
 
 my $debug=0;
 (my $SO_VARIANT = qq{\U$target{"shlib_variant"}}) =~ s/\W/_/g;
 
 my $debug=0;
+my $trace=0;
+my $verbose=0;
 
 my $crypto_num= catfile($config{sourcedir},"util","libcrypto.num");
 my $ssl_num=    catfile($config{sourcedir},"util","libssl.num");
 
 my $crypto_num= catfile($config{sourcedir},"util","libcrypto.num");
 my $ssl_num=    catfile($config{sourcedir},"util","libssl.num");
@@ -212,6 +214,8 @@ my $zlib;
 foreach (@ARGV, split(/ /, $config{options}))
        {
        $debug=1 if $_ eq "debug";
 foreach (@ARGV, split(/ /, $config{options}))
        {
        $debug=1 if $_ eq "debug";
+       $trace=1 if $_ eq "trace";
+       $verbose=1 if $_ eq "verbose";
        $W32=1 if $_ eq "32";
        die "win16 not supported" if $_ eq "16";
        if($_ eq "NT") {
        $W32=1 if $_ eq "32";
        die "win16 not supported" if $_ eq "16";
        if($_ eq "NT") {
@@ -389,6 +393,7 @@ sub do_defs
                {
                my $fn = catfile($config{sourcedir},$file);
                print STDERR "DEBUG: starting on $fn:\n" if $debug;
                {
                my $fn = catfile($config{sourcedir},$file);
                print STDERR "DEBUG: starting on $fn:\n" if $debug;
+               print STDERR "TRACE: start reading $fn\n" if $trace;
                open(IN,"<$fn") || die "Can't open $fn, $!,";
                my $line = "", my $def= "";
                my %tag = (
                open(IN,"<$fn") || die "Can't open $fn, $!,";
                my $line = "", my $def= "";
                my %tag = (
@@ -529,19 +534,19 @@ sub do_defs
                                push(@tag,$1);
                                $tag{$1}=-1;
                                print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
                                push(@tag,$1);
                                $tag{$1}=-1;
                                print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
-                       } elsif (/^\#\s*if\s+!defined\(([^\)]+)\)/) {
+                       } elsif (/^\#\s*if\s+!defined\s*\(([^\)]+)\)/) {
                                push(@tag,"-");
                                push(@tag,"-");
-                               if (/^\#\s*if\s+(!defined\(([^\)]+)\)(\s+\&\&\s+!defined\(([^\)]+)\))*)$/) {
+                               if (/^\#\s*if\s+(!defined\s*\(([^\)]+)\)(\s+\&\&\s+!defined\s*\(([^\)]+)\))*)$/) {
                                        my $tmp_1 = $1;
                                        my $tmp_;
                                        foreach $tmp_ (split '\&\&',$tmp_1) {
                                        my $tmp_1 = $1;
                                        my $tmp_;
                                        foreach $tmp_ (split '\&\&',$tmp_1) {
-                                               $tmp_ =~ /!defined\(([^\)]+)\)/;
+                                               $tmp_ =~ /!defined\s*\(([^\)]+)\)/;
                                                print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
                                                push(@tag,$1);
                                                $tag{$1}=-1;
                                        }
                                } else {
                                                print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
                                                push(@tag,$1);
                                                $tag{$1}=-1;
                                        }
                                } else {
-                                       print STDERR "Warning: $file: complicated expression: $_" if $debug; # because it is O...
+                                       print STDERR "Warning: $file: taking only '!defined($1)' of complicated expression: $_" if $verbose; # because it is O...
                                        print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
                                        push(@tag,$1);
                                        $tag{$1}=-1;
                                        print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
                                        push(@tag,$1);
                                        $tag{$1}=-1;
@@ -551,19 +556,19 @@ sub do_defs
                                push(@tag,$1);
                                $tag{$1}=1;
                                print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
                                push(@tag,$1);
                                $tag{$1}=1;
                                print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
-                       } elsif (/^\#\s*if\s+defined\(([^\)]+)\)/) {
+                       } elsif (/^\#\s*if\s+defined\s*\(([^\)]+)\)/) {
                                push(@tag,"-");
                                push(@tag,"-");
-                               if (/^\#\s*if\s+(defined\(([^\)]+)\)(\s+\|\|\s+defined\(([^\)]+)\))*)$/) {
+                               if (/^\#\s*if\s+(defined\s*\(([^\)]+)\)(\s+\|\|\s+defined\s*\(([^\)]+)\))*)$/) {
                                        my $tmp_1 = $1;
                                        my $tmp_;
                                        foreach $tmp_ (split '\|\|',$tmp_1) {
                                        my $tmp_1 = $1;
                                        my $tmp_;
                                        foreach $tmp_ (split '\|\|',$tmp_1) {
-                                               $tmp_ =~ /defined\(([^\)]+)\)/;
+                                               $tmp_ =~ /defined\s*\(([^\)]+)\)/;
                                                print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
                                                push(@tag,$1);
                                                $tag{$1}=1;
                                        }
                                } else {
                                                print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
                                                push(@tag,$1);
                                                $tag{$1}=1;
                                        }
                                } else {
-                                       print STDERR "Warning: $file: complicated expression: $_\n" if $debug; # because it is O...
+                                       print STDERR "Warning: $file: taking only 'defined($1)' of complicated expression: $_\n" if $verbose; # because it is O...
                                        print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
                                        push(@tag,$1);
                                        $tag{$1}=1;
                                        print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
                                        push(@tag,$1);
                                        $tag{$1}=1;
@@ -628,6 +633,7 @@ sub do_defs
                        } elsif (/^\#\s*if\s+/) {
                                #Some other unrecognized "if" style
                                push(@tag,"-");
                        } elsif (/^\#\s*if\s+/) {
                                #Some other unrecognized "if" style
                                push(@tag,"-");
+                               print STDERR "Warning: $file: ignoring unrecognized expression: $_\n" if $verbose; # because it is O...
                        } elsif (/^\#\s*define\s+(\w+)\s+(\w+)/
                                 && $symhacking && $tag{'TRUE'} != -1) {
                                # This is for aliasing.  When we find an alias,
                        } elsif (/^\#\s*define\s+(\w+)\s+(\w+)/
                                 && $symhacking && $tag{'TRUE'} != -1) {
                                # This is for aliasing.  When we find an alias,
@@ -921,11 +927,13 @@ sub do_defs
                        next if(/typedef\W/);
                        next if(/\#define/);
 
                        next if(/typedef\W/);
                        next if(/\#define/);
 
+                       print STDERR "TRACE: processing $_\n" if $trace && !/^\#INFO:/;
                        # Reduce argument lists to empty ()
                        # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {}
                        # Reduce argument lists to empty ()
                        # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {}
-                       while(/\(.*\)/s) {
-                               s/\([^\(\)]+\)/\{\}/gs;
-                               s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs;    #(*f{}) -> f
+                       my $nsubst = 1; # prevent infinite loop, e.g., on  int fn()
+                       while($nsubst && /\(.*\)/s) {
+                               $nsubst = s/\([^\(\)]+\)/\{\}/gs;
+                               $nsubst+= s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs;  #(*f{}) -> f
                        }
                        # pretend as we didn't use curly braces: {} -> ()
                        s/\{\}/\(\)/gs;
                        }
                        # pretend as we didn't use curly braces: {} -> ()
                        s/\{\}/\(\)/gs;
@@ -1400,9 +1408,9 @@ sub load_numbers
                $prev=$a[0];
        }
        if ($num_noinfo) {
                $prev=$a[0];
        }
        if ($num_noinfo) {
-               print STDERR "Warning: $num_noinfo symbols were without info.";
+               print STDERR "Warning: $num_noinfo symbols were without info." if $verbose || !$do_rewrite;
                if ($do_rewrite) {
                if ($do_rewrite) {
-                       printf STDERR "  The rewrite will fix this.\n";
+                       printf STDERR "  The rewrite will fix this.\n" if $verbose;
                } else {
                        printf STDERR "  You should do a rewrite to fix this.\n";
                }
                } else {
                        printf STDERR "  You should do a rewrite to fix this.\n";
                }