Fix OSSL_PARAM_allocate_from_text() for EBCDIC
authorRichard Levitte <levitte@openssl.org>
Tue, 26 Jan 2021 05:48:11 +0000 (06:48 +0100)
committerRichard Levitte <levitte@openssl.org>
Wed, 27 Jan 2021 11:06:29 +0000 (12:06 +0100)
OSSL_PARAM_allocate_from_text() converted text values to UTF-8
OSSL_PARAMs with a simple strncpy().  However, if the text is EBCDIC,
that won't become UTF-8.  Therefore, it's made to convert from EBCDIC
to ASCII on platforms where the native character encoding is the
former.

One might argue that the conversion should be the responsibility of
the application.  However, this is a helper function, and the calling
application can't easily know what sort of OSSL_PARAM the input values
are going to be used for.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13961)

crypto/params_from_text.c
doc/man3/OSSL_PARAM_allocate_from_text.pod

index d458d31b2ea154a54b4e086cfaa09212d1945f5e..24d96108d049830bc6a144b3413741a9f1675647 100644 (file)
@@ -9,6 +9,7 @@
  */
 
 #include <string.h>
+#include <openssl/ebcdic.h>
 #include <openssl/err.h>
 #include <openssl/params.h>
 
@@ -139,7 +140,11 @@ static int construct_from_text(OSSL_PARAM *to, const OSSL_PARAM *paramdef,
             }
             break;
         case OSSL_PARAM_UTF8_STRING:
+#ifdef CHARSET_EBCDIC
+            ebcdic2ascii(buf, value, buf_n);
+#else
             strncpy(buf, value, buf_n);
+#endif
             break;
         case OSSL_PARAM_OCTET_STRING:
             if (ishex) {
index 011685c8c82c2915189e27eeba7342d551cb9403..6522e3b135bf353ee8925698fd3299560e11cc20 100644 (file)
@@ -73,8 +73,10 @@ considers that an error.
 If I<key> started with "hex", OSSL_PARAM_allocate_from_text()
 considers that an error.
 
-Otherwise, I<value> is considered a C string and is copied with no
-further checks to the I<< to->data >> storage.
+Otherwise, I<value> is considered a C string and is copied to the
+I<< to->data >> storage.
+On systems where the native character encoding is EBCDIC, the bytes in
+I<< to->data >> are converted to ASCII.
 
 =item B<OSSL_PARAM_OCTET_STRING>