UI_process() didn't generate errors
authorRichard Levitte <levitte@openssl.org>
Wed, 7 Dec 2016 15:36:44 +0000 (16:36 +0100)
committerRichard Levitte <levitte@openssl.org>
Wed, 7 Dec 2016 23:06:43 +0000 (00:06 +0100)
Since there are many parts of UI_process() that can go wrong, it isn't
very helpful to only return -1 with no further explanation.  With this
change, the error message will at least show which part went wrong.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/2037)

crypto/ui/ui_err.c
crypto/ui/ui_lib.c
include/openssl/ui.h

index ef03815ea2d8a6c89d38292efbbde4824013a32a..b89f9aebb5ad319b99079cd5d315e63d81238a50 100644 (file)
@@ -30,6 +30,7 @@ static ERR_STRING_DATA UI_str_functs[] = {
     {ERR_FUNC(UI_F_UI_DUP_VERIFY_STRING), "UI_dup_verify_string"},
     {ERR_FUNC(UI_F_UI_GET0_RESULT), "UI_get0_result"},
     {ERR_FUNC(UI_F_UI_NEW_METHOD), "UI_new_method"},
     {ERR_FUNC(UI_F_UI_DUP_VERIFY_STRING), "UI_dup_verify_string"},
     {ERR_FUNC(UI_F_UI_GET0_RESULT), "UI_get0_result"},
     {ERR_FUNC(UI_F_UI_NEW_METHOD), "UI_new_method"},
+    {ERR_FUNC(UI_F_UI_PROCESS), "UI_process"},
     {ERR_FUNC(UI_F_UI_SET_RESULT), "UI_set_result"},
     {0, NULL}
 };
     {ERR_FUNC(UI_F_UI_SET_RESULT), "UI_set_result"},
     {0, NULL}
 };
@@ -40,6 +41,7 @@ static ERR_STRING_DATA UI_str_reasons[] = {
     {ERR_REASON(UI_R_INDEX_TOO_LARGE), "index too large"},
     {ERR_REASON(UI_R_INDEX_TOO_SMALL), "index too small"},
     {ERR_REASON(UI_R_NO_RESULT_BUFFER), "no result buffer"},
     {ERR_REASON(UI_R_INDEX_TOO_LARGE), "index too large"},
     {ERR_REASON(UI_R_INDEX_TOO_SMALL), "index too small"},
     {ERR_REASON(UI_R_NO_RESULT_BUFFER), "no result buffer"},
+    {ERR_REASON(UI_R_PROCESSING_ERROR), "processing error"},
     {ERR_REASON(UI_R_RESULT_TOO_LARGE), "result too large"},
     {ERR_REASON(UI_R_RESULT_TOO_SMALL), "result too small"},
     {ERR_REASON(UI_R_UNKNOWN_CONTROL_COMMAND), "unknown control command"},
     {ERR_REASON(UI_R_RESULT_TOO_LARGE), "result too large"},
     {ERR_REASON(UI_R_RESULT_TOO_SMALL), "result too small"},
     {ERR_REASON(UI_R_UNKNOWN_CONTROL_COMMAND), "unknown control command"},
index 273bfb60959ab53a83d740da6b1b790cf8d818a5..838175d815d197aff8a82d9d9572ca9a93233052 100644 (file)
@@ -427,9 +427,13 @@ static int print_error(const char *str, size_t len, UI *ui)
 int UI_process(UI *ui)
 {
     int i, ok = 0;
 int UI_process(UI *ui)
 {
     int i, ok = 0;
+    const char *state = "processing";
 
 
-    if (ui->meth->ui_open_session && !ui->meth->ui_open_session(ui))
-        return -1;
+    if (ui->meth->ui_open_session && !ui->meth->ui_open_session(ui)) {
+        state = "opening session";
+        ok = -1;
+        goto err;
+    }
 
     if (ui->flags & UI_FLAG_PRINT_ERRORS)
         ERR_print_errors_cb((int (*)(const char *, size_t, void *))
 
     if (ui->flags & UI_FLAG_PRINT_ERRORS)
         ERR_print_errors_cb((int (*)(const char *, size_t, void *))
@@ -440,6 +444,7 @@ int UI_process(UI *ui)
             && !ui->meth->ui_write_string(ui,
                                           sk_UI_STRING_value(ui->strings, i)))
         {
             && !ui->meth->ui_write_string(ui,
                                           sk_UI_STRING_value(ui->strings, i)))
         {
+            state = "writing strings";
             ok = -1;
             goto err;
         }
             ok = -1;
             goto err;
         }
@@ -451,6 +456,7 @@ int UI_process(UI *ui)
             ok = -2;
             goto err;
         case 0:                /* Errors */
             ok = -2;
             goto err;
         case 0:                /* Errors */
+            state = "flushing";
             ok = -1;
             goto err;
         default:               /* Success */
             ok = -1;
             goto err;
         default:               /* Success */
@@ -467,6 +473,7 @@ int UI_process(UI *ui)
                 ok = -2;
                 goto err;
             case 0:            /* Errors */
                 ok = -2;
                 goto err;
             case 0:            /* Errors */
+                state = "reading strings";
                 ok = -1;
                 goto err;
             default:           /* Success */
                 ok = -1;
                 goto err;
             default:           /* Success */
@@ -476,8 +483,16 @@ int UI_process(UI *ui)
         }
     }
  err:
         }
     }
  err:
-    if (ui->meth->ui_close_session && !ui->meth->ui_close_session(ui))
-        return -1;
+    if (ui->meth->ui_close_session && !ui->meth->ui_close_session(ui)) {
+        if (state == NULL)
+            state = "closing session";
+        ok = -1;
+    }
+
+    if (ok == -1) {
+        UIerr(UI_F_UI_PROCESS, UI_R_PROCESSING_ERROR);
+        ERR_add_error_data(2, "while ", state);
+    }
     return ok;
 }
 
     return ok;
 }
 
index 26f4f04495a934e2a78acff614d3389df397d0fa..c62c05d17ee178124be62f08c339819134f20b74 100644 (file)
@@ -350,6 +350,7 @@ int ERR_load_UI_strings(void);
 # define UI_F_UI_DUP_VERIFY_STRING                        106
 # define UI_F_UI_GET0_RESULT                              107
 # define UI_F_UI_NEW_METHOD                               104
 # define UI_F_UI_DUP_VERIFY_STRING                        106
 # define UI_F_UI_GET0_RESULT                              107
 # define UI_F_UI_NEW_METHOD                               104
+# define UI_F_UI_PROCESS                                  113
 # define UI_F_UI_SET_RESULT                               105
 
 /* Reason codes. */
 # define UI_F_UI_SET_RESULT                               105
 
 /* Reason codes. */
@@ -357,6 +358,7 @@ int ERR_load_UI_strings(void);
 # define UI_R_INDEX_TOO_LARGE                             102
 # define UI_R_INDEX_TOO_SMALL                             103
 # define UI_R_NO_RESULT_BUFFER                            105
 # define UI_R_INDEX_TOO_LARGE                             102
 # define UI_R_INDEX_TOO_SMALL                             103
 # define UI_R_NO_RESULT_BUFFER                            105
+# define UI_R_PROCESSING_ERROR                            107
 # define UI_R_RESULT_TOO_LARGE                            100
 # define UI_R_RESULT_TOO_SMALL                            101
 # define UI_R_UNKNOWN_CONTROL_COMMAND                     106
 # define UI_R_RESULT_TOO_LARGE                            100
 # define UI_R_RESULT_TOO_SMALL                            101
 # define UI_R_UNKNOWN_CONTROL_COMMAND                     106