[openssl-dev] [PATCH] Some DJGPP specific fixes and improvements for OpenSSL_1_0_2-stable.

Juan Manuel Guerrero juan.guerrero at gmx.de
Sun Jun 4 00:15:04 UTC 2017


I do not know if patches for DJGPP/FreeDOS are still welcome at all for the
OpenSSL 1.0.2 branch but if yes, then I would like to propose some fixes and
improvements.  No one of the proposed changes have impact on any other port.
The patch is based on openssl-1.0.2-stable-SNAP-20170602.  Concerning its
functionality, the patch is identical to the one proposed some months ago for
the openssl-1.1.0 branch and that has found its way into that branch.

The patch will fix/improve the following issues:
1) In Configure:
      For some reason -DTERMIO is set but DJGPP has never offered TERMIO making
      the build fail.  I have changed this to -DTERMIOS as is used to be.
2) In crypto/bio/bss_dgram.c:
      I have removed superfluous macro definitions of sock_write, sock_read and
      sock_puts enclosed by WATT32.
3) In crypto/bio/bss_sock.c:
      Here the existing macro definitions for sock_write, sock_read and sock_puts
      are necessary and must be kept but they must be undefined before they can
      be defined.  This is because newer versions of Watt-32 also redefine them.
4) In crypto/conf/conf_def.c:
      If this port is used on MS-DOS or FreeDOS it becomes necessary to check if
      the underlying file system supports long file names (aka LFN) or not.  If
      it does not then file names with a leading dot like ".rnd" or ".ca_certs"
      are ilicit.  In function def_load_bio, the macros IS_RANDFILE and IS_CERT_DIR
      are used to check if the file system offers LFN support so that the file
      names with leading dots are licit.  If the tests fail then the new function
      dosify_filename is called and will substitute invalid characters in the file
      name by valid ones before using them.  This check and the call of dosify_filename
      is enclosed by OPENSSL_SYS_MSDOS.
5) In e_os.h:
      In the DJGPP section the macros IS_RANDFILE and IS_CERT_DIR are defined.
      Also some auxiliar macros like HAS_LFN_SUPPORT and FILE_EXISTS are defined.
      Because neither MS-DOS nor FreeDOS provide 'egd' sockets, the DEVRANDOM_EGD
      macro is undefined.  This shall inhibit the compilation of code that does
      not work on MS-DOS/FreeDOS.
6) In util/mklink.pl:
      Neither MS-DOS nor FreeDOS provide symlink support so copy files instead.
7) In INSTALL.DJGPP:
      Update URL of WATT-32 library.


I have checked the modified version of OpenSSL_1_0_2-stable on linux and Cygwin.
They are no issues.  This is no surprise because the changes are either guarded
by the __DJGPP__ or OPENSSL_SYS_MSDOS macros.
If more informaton is required please mail me.  Just in case it is required, I
have attached the patch as gzip'ed files too.


Regards,
Juan M. Guerrero





diff -aprNU5 openssl-1.0.2-stable-SNAP-20170602.orig/Configure openssl-1.0.2-stable-SNAP-20170602/Configure
--- openssl-1.0.2-stable-SNAP-20170602.orig/Configure	2017-06-01 20:51:32 +0000
+++ openssl-1.0.2-stable-SNAP-20170602/Configure	2017-06-03 19:41:20 +0000
@@ -632,11 +632,11 @@ my %table=(
  "netware-libc-bsdsock", "mwccnlm::::::BN_LLONG ${x86_gcc_opts}::",
  "netware-libc-gcc", "i586-netware-gcc:-nostdinc -I/ndk/libc/include -I/ndk/libc/include/winsock -DL_ENDIAN -DNETWARE_LIBC -DOPENSSL_SYSNAME_NETWARE -DTERMIO -O2 -Wall:::::BN_LLONG ${x86_gcc_opts}::",
  "netware-libc-bsdsock-gcc", "i586-netware-gcc:-nostdinc -I/ndk/libc/include -DNETWARE_BSDSOCK -DL_ENDIAN -DNETWARE_LIBC -DOPENSSL_SYSNAME_NETWARE -DTERMIO -O2 -Wall:::::BN_LLONG ${x86_gcc_opts}::",

  # DJGPP
-"DJGPP", "gcc:-I/dev/env/WATT_ROOT/inc -DTERMIO -DL_ENDIAN -fomit-frame-pointer -O2 -Wall:::MSDOS:-L/dev/env/WATT_ROOT/lib -lwatt:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_asm}:a.out:",
+"DJGPP", "gcc:-I/dev/env/WATT_ROOT/inc -DTERMIOS -DL_ENDIAN -fomit-frame-pointer -O2 -Wall:::MSDOS:-L/dev/env/WATT_ROOT/lib -lwatt:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_asm}:a.out:",

  # Ultrix from Bernhard Simon <simon at zid.tuwien.ac.at>
  "ultrix-cc","cc:-std1 -O -Olimit 2500 -DL_ENDIAN::(unknown):::::::",
  "ultrix-gcc","gcc:-O3 -DL_ENDIAN::(unknown):::BN_LLONG::::",
  # K&R C is no longer supported; you need gcc on old Ultrix installations
@@ -1532,10 +1532,27 @@ if ($sys_id ne "")
  if ($ranlib eq "")
  	{
  	$ranlib = $default_ranlib;
  	}

+# DJGPP specific CFLAG adjustments
+if ($target =~ /^DJGPP/)
+	{
+	my $gccver=0;
+	if (open(FD,"$cc --version |"))
+		{
+		while(<FD>) { $gccver=$1 if (/ (([1-3])\.|4\.([0-1])([.0-9]*))/); }
+		close(FD);
+		}
+	if ($gccver==0)
+		{
+		# For gcc 4.3.0 and above ensure that always old GNU extern inline semantics
+		# are used (aka -fgnu89-inline) even if ISO C99 semantics has been specified.
+		$cflags=~s/-fomit-frame-pointer/-fgnu89-inline -fomit-frame-pointer/;
+		}
+	}
+
  #my ($bn1)=split(/\s+/,$bn_obj);
  #$bn1 = "" unless defined $bn1;
  #$bn1=$bn_asm unless ($bn1 =~ /\.o$/);
  #$bn_obj="$bn1";

diff -aprNU5 openssl-1.0.2-stable-SNAP-20170602.orig/crypto/bio/bss_dgram.c openssl-1.0.2-stable-SNAP-20170602/crypto/bio/bss_dgram.c
--- openssl-1.0.2-stable-SNAP-20170602.orig/crypto/bio/bss_dgram.c	2017-06-01 20:51:32 +0000
+++ openssl-1.0.2-stable-SNAP-20170602/crypto/bio/bss_dgram.c	2017-06-03 19:41:20 +0000
@@ -92,16 +92,10 @@
          (((a)->s6_addr32[0] == 0) &&          \
           ((a)->s6_addr32[1] == 0) &&          \
           ((a)->s6_addr32[2] == htonl(0x0000ffff)))
  # endif

-# ifdef WATT32
-#  define sock_write SockWrite  /* Watt-32 uses same names */
-#  define sock_read  SockRead
-#  define sock_puts  SockPuts
-# endif
-
  static int dgram_write(BIO *h, const char *buf, int num);
  static int dgram_read(BIO *h, char *buf, int size);
  static int dgram_puts(BIO *h, const char *str);
  static long dgram_ctrl(BIO *h, int cmd, long arg1, void *arg2);
  static int dgram_new(BIO *h);
diff -aprNU5 openssl-1.0.2-stable-SNAP-20170602.orig/crypto/bio/bss_file.c openssl-1.0.2-stable-SNAP-20170602/crypto/bio/bss_file.c
--- openssl-1.0.2-stable-SNAP-20170602.orig/crypto/bio/bss_file.c	2017-06-01 20:51:32 +0000
+++ openssl-1.0.2-stable-SNAP-20170602/crypto/bio/bss_file.c	2017-06-03 19:41:20 +0000
@@ -93,10 +93,14 @@
  #  include <nwfileio.h>
  # endif

  # if !defined(OPENSSL_NO_STDIO)

+#ifdef OPENSSL_SYS_MSDOS
+# include <libc/unconst.h>
+static void dosify_filename(const char *filename);
+#endif
  static int MS_CALLBACK file_write(BIO *h, const char *buf, int num);
  static int MS_CALLBACK file_read(BIO *h, char *buf, int size);
  static int MS_CALLBACK file_puts(BIO *h, const char *str);
  static int MS_CALLBACK file_gets(BIO *h, char *str, int size);
  static long MS_CALLBACK file_ctrl(BIO *h, int cmd, long arg1, void *arg2);
@@ -159,10 +163,13 @@ static FILE *file_fopen(const char *file
          }
      } else if (GetLastError() == ERROR_NO_UNICODE_TRANSLATION) {
          file = fopen(filename, mode);
      }
  #  else
+#   ifdef OPENSSL_SYS_MSDOS
+    dosify_filename(filename);
+#   endif
      file = fopen(filename, mode);
  #  endif
      return (file);
  }

@@ -477,8 +484,25 @@ static int MS_CALLBACK file_puts(BIO *bp
      n = strlen(str);
      ret = file_write(bp, str, n);
      return (ret);
  }

+#  ifdef OPENSSL_SYS_MSDOS
+static void dosify_filename(const char *filename)
+{
+    if (filename && *filename && !HAS_LFN_SUPPORT(filename)) {
+        char *nextchar = unconst(filename, char *);
+
+        do {
+            if (nextchar[0] == '/' && nextchar[2] != '.' && nextchar[2] != '/') {
+
+                /* Leading dot not allowed on plain DOS.  */
+                if (nextchar[1] == '.')
+                    *++nextchar = '_';
+            }
+        } while (*++nextchar);
+    }
+}
+#  endif
  # endif                         /* OPENSSL_NO_STDIO */

  #endif                          /* HEADER_BSS_FILE_C */
diff -aprNU5 openssl-1.0.2-stable-SNAP-20170602.orig/crypto/bio/bss_sock.c openssl-1.0.2-stable-SNAP-20170602/crypto/bio/bss_sock.c
--- openssl-1.0.2-stable-SNAP-20170602.orig/crypto/bio/bss_sock.c	2017-06-01 20:51:32 +0000
+++ openssl-1.0.2-stable-SNAP-20170602/crypto/bio/bss_sock.c	2017-06-03 19:41:20 +0000
@@ -64,11 +64,15 @@
  #ifndef OPENSSL_NO_SOCK

  # include <openssl/bio.h>

  # ifdef WATT32
-#  define sock_write SockWrite  /* Watt-32 uses same names */
+/* Watt-32 uses same names */
+#  undef sock_write
+#  undef sock_read
+#  undef sock_puts
+#  define sock_write SockWrite
  #  define sock_read  SockRead
  #  define sock_puts  SockPuts
  # endif

  static int sock_write(BIO *h, const char *buf, int num);
diff -aprNU5 openssl-1.0.2-stable-SNAP-20170602.orig/e_os.h openssl-1.0.2-stable-SNAP-20170602/e_os.h
--- openssl-1.0.2-stable-SNAP-20170602.orig/e_os.h	2017-06-01 20:51:32 +0000
+++ openssl-1.0.2-stable-SNAP-20170602/e_os.h	2017-06-03 19:41:20 +0000
@@ -240,10 +240,12 @@ extern "C" {
  #   include <tcp.h>
  #   include <netdb.h>
  #   define _setmode setmode
  #   define _O_TEXT O_TEXT
  #   define _O_BINARY O_BINARY
+#   define HAS_LFN_SUPPORT(name)  (pathconf((name), _PC_NAME_MAX) > 12)
+#   undef DEVRANDOM_EGD  /*  Neither MS-DOS nor FreeDOS provide 'egd' sockets.  */
  #   undef DEVRANDOM
  #   define DEVRANDOM "/dev/urandom\x24"
  #  endif                        /* __DJGPP__ */

  #  ifndef S_IFDIR
diff -aprNU5 openssl-1.0.2-stable-SNAP-20170602.orig/INSTALL.DJGPP openssl-1.0.2-stable-SNAP-20170602/INSTALL.DJGPP
--- openssl-1.0.2-stable-SNAP-20170602.orig/INSTALL.DJGPP	2017-06-01 20:51:32 +0000
+++ openssl-1.0.2-stable-SNAP-20170602/INSTALL.DJGPP	2017-06-03 19:42:44 +0000
@@ -16,11 +16,11 @@
   All of these can be obtained from the usual DJGPP mirror sites or
   directly at "http://www.delorie.com/pub/djgpp". For help on which
   files to download, see the DJGPP "ZIP PICKER" page at
   "http://www.delorie.com/djgpp/zip-picker.html". You also need to have
   the WATT-32 networking package installed before you try to compile
- OpenSSL. This can be obtained from "http://www.bgnett.no/~giva/".
+ OpenSSL. This can be obtained from "http://www.watt-32.net/".
   The Makefile assumes that the WATT-32 code is in the directory
   specified by the environment variable WATT_ROOT. If you have watt-32
   in directory "watt32" under your main DJGPP directory, specify
   WATT_ROOT="/dev/env/DJDIR/watt32".

diff -aprNU5 openssl-1.0.2-stable-SNAP-20170602.orig/util/mklink.pl openssl-1.0.2-stable-SNAP-20170602/util/mklink.pl
--- openssl-1.0.2-stable-SNAP-20170602.orig/util/mklink.pl	2017-06-01 20:51:32 +0000
+++ openssl-1.0.2-stable-SNAP-20170602/util/mklink.pl	2017-06-03 19:41:20 +0000
@@ -49,11 +49,11 @@ foreach $dirname (@from_path) {

  my $to = join('/', @to_path);

  my $file;
  $symlink_exists=eval {symlink("",""); 1};
-if ($^O eq "msys") { $symlink_exists=0 };
+if ($^O eq "msys" || $^O eq 'dos') { $symlink_exists=0 };
  foreach $file (@files) {
      my $err = "";
      if ($symlink_exists) {
          if (!-l "$from/$file") {
  	    unlink "$from/$file";


More information about the openssl-dev mailing list