This _WIN32-specific patch makes it possible to "wrap" OpenSSL in another
[openssl.git] / crypto / ui / ui_util.c
index 7c6f7d3a73f615fb8dbb87fdc2d2b0799f796be6..5d9760bb7b3ff4d02460571122a1457f525eb6cf 100644 (file)
@@ -54,7 +54,7 @@
  */
 
 #include <string.h>
-#include <openssl/ui.h>
+#include "ui_locl.h"
 
 int UI_UTIL_read_pw_string(char *buf,int length,const char *prompt,int verify)
        {
@@ -62,7 +62,7 @@ int UI_UTIL_read_pw_string(char *buf,int length,const char *prompt,int verify)
        int ret;
 
        ret=UI_UTIL_read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify);
-       memset(buff,0,BUFSIZ);
+       OPENSSL_cleanse(buff,BUFSIZ);
        return(ret);
        }
 
@@ -71,16 +71,21 @@ int UI_UTIL_read_pw(char *buf,char *buff,int size,const char *prompt,int verify)
        int ok = 0;
        UI *ui;
 
+       if (size < 1)
+               return -1;
+
        ui = UI_new();
        if (ui)
                {
-               ok = UI_add_input_string(ui,prompt,0,buf,0,BUFSIZ-1);
-               if (ok == 0 && verify)
-                       ok = UI_add_verify_string(ui,prompt,0,buff,0,BUFSIZ-1,
+               ok = UI_add_input_string(ui,prompt,0,buf,0,size-1);
+               if (ok >= 0 && verify)
+                       ok = UI_add_verify_string(ui,prompt,0,buff,0,size-1,
                                buf);
-               if (ok == 0)
+               if (ok >= 0)
                        ok=UI_process(ui);
                UI_free(ui);
                }
+       if (ok > 0)
+               ok = 0;
        return(ok);
        }