Extend the BIO callback tests to check the return value semantics
[openssl.git] / crypto / ui / ui_util.c
index 67b2ec22298d4277b335964380c3a361695afa1d..b379324f9bab3c6778a243c294946cc19fd1a3ba 100644 (file)
@@ -25,7 +25,7 @@ int UI_UTIL_read_pw_string(char *buf, int length, const char *prompt,
         UI_UTIL_read_pw(buf, buff, (length > BUFSIZ) ? BUFSIZ : length,
                         prompt, verify);
     OPENSSL_cleanse(buff, BUFSIZ);
-    return (ret);
+    return ret;
 }
 
 int UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt,
@@ -48,7 +48,7 @@ int UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt,
     }
     if (ok > 0)
         ok = 0;
-    return (ok);
+    return ok;
 }
 
 /*
@@ -104,7 +104,7 @@ static int ui_read(UI *ui, UI_STRING *uis)
     switch (UI_get_string_type(uis)) {
     case UIT_PROMPT:
         {
-            char result[PEM_BUFSIZE];
+            char result[PEM_BUFSIZE + 1];
             const struct pem_password_cb_data *data =
                 UI_method_get_ex_data(UI_get_method(ui), ui_method_data_index);
             int maxsize = UI_get_result_maxsize(uis);
@@ -112,9 +112,11 @@ static int ui_read(UI *ui, UI_STRING *uis)
                                maxsize > PEM_BUFSIZE ? PEM_BUFSIZE : maxsize,
                                data->rwflag, UI_get0_user_data(ui));
 
+            if (len >= 0)
+                result[len] = '\0';
             if (len <= 0)
                 return len;
-            if (UI_set_result(ui, uis, result) >= 0)
+            if (UI_set_result_ex(ui, uis, result, len) >= 0)
                 return 1;
             return 0;
         }