Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/ui/ui_lib.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* | - | ||||||||||||||||||||||||
2 | * Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved. | - | ||||||||||||||||||||||||
3 | * | - | ||||||||||||||||||||||||
4 | * Licensed under the OpenSSL license (the "License"). You may not use | - | ||||||||||||||||||||||||
5 | * this file except in compliance with the License. You can obtain a copy | - | ||||||||||||||||||||||||
6 | * in the file LICENSE in the source distribution or at | - | ||||||||||||||||||||||||
7 | * https://www.openssl.org/source/license.html | - | ||||||||||||||||||||||||
8 | */ | - | ||||||||||||||||||||||||
9 | - | |||||||||||||||||||||||||
10 | #include <string.h> | - | ||||||||||||||||||||||||
11 | #include "internal/cryptlib.h" | - | ||||||||||||||||||||||||
12 | #include <openssl/e_os2.h> | - | ||||||||||||||||||||||||
13 | #include <openssl/buffer.h> | - | ||||||||||||||||||||||||
14 | #include <openssl/ui.h> | - | ||||||||||||||||||||||||
15 | #include <openssl/err.h> | - | ||||||||||||||||||||||||
16 | #include "ui_locl.h" | - | ||||||||||||||||||||||||
17 | - | |||||||||||||||||||||||||
18 | UI *UI_new(void) | - | ||||||||||||||||||||||||
19 | { | - | ||||||||||||||||||||||||
20 | return UI_new_method(NULL); never executed: return UI_new_method( ((void *)0) ); | 0 | ||||||||||||||||||||||||
21 | } | - | ||||||||||||||||||||||||
22 | - | |||||||||||||||||||||||||
23 | UI *UI_new_method(const UI_METHOD *method) | - | ||||||||||||||||||||||||
24 | { | - | ||||||||||||||||||||||||
25 | UI *ret = OPENSSL_zalloc(sizeof(*ret)); | - | ||||||||||||||||||||||||
26 | - | |||||||||||||||||||||||||
27 | if (ret == NULL) {
| 0-5 | ||||||||||||||||||||||||
28 | UIerr(UI_F_UI_NEW_METHOD, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
29 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
30 | } | - | ||||||||||||||||||||||||
31 | - | |||||||||||||||||||||||||
32 | ret->lock = CRYPTO_THREAD_lock_new(); | - | ||||||||||||||||||||||||
33 | if (ret->lock == NULL) {
| 0-5 | ||||||||||||||||||||||||
34 | UIerr(UI_F_UI_NEW_METHOD, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
35 | OPENSSL_free(ret); | - | ||||||||||||||||||||||||
36 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
37 | } | - | ||||||||||||||||||||||||
38 | - | |||||||||||||||||||||||||
39 | if (method == NULL)
| 0-5 | ||||||||||||||||||||||||
40 | method = UI_get_default_method(); never executed: method = UI_get_default_method(); | 0 | ||||||||||||||||||||||||
41 | if (method == NULL)
| 0-5 | ||||||||||||||||||||||||
42 | method = UI_null(); never executed: method = UI_null(); | 0 | ||||||||||||||||||||||||
43 | ret->meth = method; | - | ||||||||||||||||||||||||
44 | - | |||||||||||||||||||||||||
45 | if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_UI, ret, &ret->ex_data)) {
| 0-5 | ||||||||||||||||||||||||
46 | OPENSSL_free(ret); | - | ||||||||||||||||||||||||
47 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
48 | } | - | ||||||||||||||||||||||||
49 | return ret; executed 5 times by 1 test: return ret; Executed by:
| 5 | ||||||||||||||||||||||||
50 | } | - | ||||||||||||||||||||||||
51 | - | |||||||||||||||||||||||||
52 | static void free_string(UI_STRING *uis) | - | ||||||||||||||||||||||||
53 | { | - | ||||||||||||||||||||||||
54 | if (uis->flags & OUT_STRING_FREEABLE) {
| 0-5 | ||||||||||||||||||||||||
55 | OPENSSL_free((char *)uis->out_string); | - | ||||||||||||||||||||||||
56 | switch (uis->type) { | - | ||||||||||||||||||||||||
57 | case UIT_BOOLEAN: never executed: case UIT_BOOLEAN: | 0 | ||||||||||||||||||||||||
58 | OPENSSL_free((char *)uis->_.boolean_data.action_desc); | - | ||||||||||||||||||||||||
59 | OPENSSL_free((char *)uis->_.boolean_data.ok_chars); | - | ||||||||||||||||||||||||
60 | OPENSSL_free((char *)uis->_.boolean_data.cancel_chars); | - | ||||||||||||||||||||||||
61 | break; never executed: break; | 0 | ||||||||||||||||||||||||
62 | case UIT_NONE: never executed: case UIT_NONE: | 0 | ||||||||||||||||||||||||
63 | case UIT_PROMPT: never executed: case UIT_PROMPT: | 0 | ||||||||||||||||||||||||
64 | case UIT_VERIFY: never executed: case UIT_VERIFY: | 0 | ||||||||||||||||||||||||
65 | case UIT_ERROR: never executed: case UIT_ERROR: | 0 | ||||||||||||||||||||||||
66 | case UIT_INFO: never executed: case UIT_INFO: | 0 | ||||||||||||||||||||||||
67 | break; never executed: break; | 0 | ||||||||||||||||||||||||
68 | } | - | ||||||||||||||||||||||||
69 | } never executed: end of block | 0 | ||||||||||||||||||||||||
70 | OPENSSL_free(uis); | - | ||||||||||||||||||||||||
71 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||||||||||||||
72 | - | |||||||||||||||||||||||||
73 | void UI_free(UI *ui) | - | ||||||||||||||||||||||||
74 | { | - | ||||||||||||||||||||||||
75 | if (ui == NULL)
| 0-5 | ||||||||||||||||||||||||
76 | return; never executed: return; | 0 | ||||||||||||||||||||||||
77 | if ((ui->flags & UI_FLAG_DUPL_DATA) != 0) {
| 0-5 | ||||||||||||||||||||||||
78 | ui->meth->ui_destroy_data(ui, ui->user_data); | - | ||||||||||||||||||||||||
79 | } never executed: end of block | 0 | ||||||||||||||||||||||||
80 | sk_UI_STRING_pop_free(ui->strings, free_string); | - | ||||||||||||||||||||||||
81 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_UI, ui, &ui->ex_data); | - | ||||||||||||||||||||||||
82 | CRYPTO_THREAD_lock_free(ui->lock); | - | ||||||||||||||||||||||||
83 | OPENSSL_free(ui); | - | ||||||||||||||||||||||||
84 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||||||||||||||
85 | - | |||||||||||||||||||||||||
86 | static int allocate_string_stack(UI *ui) | - | ||||||||||||||||||||||||
87 | { | - | ||||||||||||||||||||||||
88 | if (ui->strings == NULL) {
| 0-5 | ||||||||||||||||||||||||
89 | ui->strings = sk_UI_STRING_new_null(); | - | ||||||||||||||||||||||||
90 | if (ui->strings == NULL) {
| 0-5 | ||||||||||||||||||||||||
91 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
92 | } | - | ||||||||||||||||||||||||
93 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||||||||||||||
94 | return 0; executed 5 times by 1 test: return 0; Executed by:
| 5 | ||||||||||||||||||||||||
95 | } | - | ||||||||||||||||||||||||
96 | - | |||||||||||||||||||||||||
97 | static UI_STRING *general_allocate_prompt(UI *ui, const char *prompt, | - | ||||||||||||||||||||||||
98 | int prompt_freeable, | - | ||||||||||||||||||||||||
99 | enum UI_string_types type, | - | ||||||||||||||||||||||||
100 | int input_flags, char *result_buf) | - | ||||||||||||||||||||||||
101 | { | - | ||||||||||||||||||||||||
102 | UI_STRING *ret = NULL; | - | ||||||||||||||||||||||||
103 | - | |||||||||||||||||||||||||
104 | if (prompt == NULL) {
| 0-5 | ||||||||||||||||||||||||
105 | UIerr(UI_F_GENERAL_ALLOCATE_PROMPT, ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
106 | } else if ((type == UIT_PROMPT || type == UIT_VERIFY never executed: end of block
| 0-5 | ||||||||||||||||||||||||
107 | || type == UIT_BOOLEAN) && result_buf == NULL) {
| 0-5 | ||||||||||||||||||||||||
108 | UIerr(UI_F_GENERAL_ALLOCATE_PROMPT, UI_R_NO_RESULT_BUFFER); | - | ||||||||||||||||||||||||
109 | } else if ((ret = OPENSSL_malloc(sizeof(*ret))) != NULL) { never executed: end of block
| 0-5 | ||||||||||||||||||||||||
110 | ret->out_string = prompt; | - | ||||||||||||||||||||||||
111 | ret->flags = prompt_freeable ? OUT_STRING_FREEABLE : 0;
| 0-5 | ||||||||||||||||||||||||
112 | ret->input_flags = input_flags; | - | ||||||||||||||||||||||||
113 | ret->type = type; | - | ||||||||||||||||||||||||
114 | ret->result_buf = result_buf; | - | ||||||||||||||||||||||||
115 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||||||||||||||
116 | return ret; executed 5 times by 1 test: return ret; Executed by:
| 5 | ||||||||||||||||||||||||
117 | } | - | ||||||||||||||||||||||||
118 | - | |||||||||||||||||||||||||
119 | static int general_allocate_string(UI *ui, const char *prompt, | - | ||||||||||||||||||||||||
120 | int prompt_freeable, | - | ||||||||||||||||||||||||
121 | enum UI_string_types type, int input_flags, | - | ||||||||||||||||||||||||
122 | char *result_buf, int minsize, int maxsize, | - | ||||||||||||||||||||||||
123 | const char *test_buf) | - | ||||||||||||||||||||||||
124 | { | - | ||||||||||||||||||||||||
125 | int ret = -1; | - | ||||||||||||||||||||||||
126 | UI_STRING *s = general_allocate_prompt(ui, prompt, prompt_freeable, | - | ||||||||||||||||||||||||
127 | type, input_flags, result_buf); | - | ||||||||||||||||||||||||
128 | - | |||||||||||||||||||||||||
129 | if (s != NULL) {
| 0-5 | ||||||||||||||||||||||||
130 | if (allocate_string_stack(ui) >= 0) {
| 0-5 | ||||||||||||||||||||||||
131 | s->_.string_data.result_minsize = minsize; | - | ||||||||||||||||||||||||
132 | s->_.string_data.result_maxsize = maxsize; | - | ||||||||||||||||||||||||
133 | s->_.string_data.test_buf = test_buf; | - | ||||||||||||||||||||||||
134 | ret = sk_UI_STRING_push(ui->strings, s); | - | ||||||||||||||||||||||||
135 | /* sk_push() returns 0 on error. Let's adapt that */ | - | ||||||||||||||||||||||||
136 | if (ret <= 0) {
| 0-5 | ||||||||||||||||||||||||
137 | ret--; | - | ||||||||||||||||||||||||
138 | free_string(s); | - | ||||||||||||||||||||||||
139 | } never executed: end of block | 0 | ||||||||||||||||||||||||
140 | } else executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||||||||||||||
141 | free_string(s); never executed: free_string(s); | 0 | ||||||||||||||||||||||||
142 | } | - | ||||||||||||||||||||||||
143 | return ret; executed 5 times by 1 test: return ret; Executed by:
| 5 | ||||||||||||||||||||||||
144 | } | - | ||||||||||||||||||||||||
145 | - | |||||||||||||||||||||||||
146 | static int general_allocate_boolean(UI *ui, | - | ||||||||||||||||||||||||
147 | const char *prompt, | - | ||||||||||||||||||||||||
148 | const char *action_desc, | - | ||||||||||||||||||||||||
149 | const char *ok_chars, | - | ||||||||||||||||||||||||
150 | const char *cancel_chars, | - | ||||||||||||||||||||||||
151 | int prompt_freeable, | - | ||||||||||||||||||||||||
152 | enum UI_string_types type, | - | ||||||||||||||||||||||||
153 | int input_flags, char *result_buf) | - | ||||||||||||||||||||||||
154 | { | - | ||||||||||||||||||||||||
155 | int ret = -1; | - | ||||||||||||||||||||||||
156 | UI_STRING *s; | - | ||||||||||||||||||||||||
157 | const char *p; | - | ||||||||||||||||||||||||
158 | - | |||||||||||||||||||||||||
159 | if (ok_chars == NULL) {
| 0 | ||||||||||||||||||||||||
160 | UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN, ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
161 | } else if (cancel_chars == NULL) { never executed: end of block
| 0 | ||||||||||||||||||||||||
162 | UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN, ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
163 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
164 | for (p = ok_chars; *p != '\0'; p++) {
| 0 | ||||||||||||||||||||||||
165 | if (strchr(cancel_chars, *p) != NULL) {
| 0 | ||||||||||||||||||||||||
166 | UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN, | - | ||||||||||||||||||||||||
167 | UI_R_COMMON_OK_AND_CANCEL_CHARACTERS); | - | ||||||||||||||||||||||||
168 | } never executed: end of block | 0 | ||||||||||||||||||||||||
169 | } never executed: end of block | 0 | ||||||||||||||||||||||||
170 | - | |||||||||||||||||||||||||
171 | s = general_allocate_prompt(ui, prompt, prompt_freeable, | - | ||||||||||||||||||||||||
172 | type, input_flags, result_buf); | - | ||||||||||||||||||||||||
173 | - | |||||||||||||||||||||||||
174 | if (s != NULL) {
| 0 | ||||||||||||||||||||||||
175 | if (allocate_string_stack(ui) >= 0) {
| 0 | ||||||||||||||||||||||||
176 | s->_.boolean_data.action_desc = action_desc; | - | ||||||||||||||||||||||||
177 | s->_.boolean_data.ok_chars = ok_chars; | - | ||||||||||||||||||||||||
178 | s->_.boolean_data.cancel_chars = cancel_chars; | - | ||||||||||||||||||||||||
179 | ret = sk_UI_STRING_push(ui->strings, s); | - | ||||||||||||||||||||||||
180 | /* | - | ||||||||||||||||||||||||
181 | * sk_push() returns 0 on error. Let's adapt that | - | ||||||||||||||||||||||||
182 | */ | - | ||||||||||||||||||||||||
183 | if (ret <= 0) {
| 0 | ||||||||||||||||||||||||
184 | ret--; | - | ||||||||||||||||||||||||
185 | free_string(s); | - | ||||||||||||||||||||||||
186 | } never executed: end of block | 0 | ||||||||||||||||||||||||
187 | } else never executed: end of block | 0 | ||||||||||||||||||||||||
188 | free_string(s); never executed: free_string(s); | 0 | ||||||||||||||||||||||||
189 | } | - | ||||||||||||||||||||||||
190 | } never executed: end of block | 0 | ||||||||||||||||||||||||
191 | return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||
192 | } | - | ||||||||||||||||||||||||
193 | - | |||||||||||||||||||||||||
194 | /* | - | ||||||||||||||||||||||||
195 | * Returns the index to the place in the stack or -1 for error. Uses a | - | ||||||||||||||||||||||||
196 | * direct reference to the prompt. | - | ||||||||||||||||||||||||
197 | */ | - | ||||||||||||||||||||||||
198 | int UI_add_input_string(UI *ui, const char *prompt, int flags, | - | ||||||||||||||||||||||||
199 | char *result_buf, int minsize, int maxsize) | - | ||||||||||||||||||||||||
200 | { | - | ||||||||||||||||||||||||
201 | return general_allocate_string(ui, prompt, 0, executed 5 times by 1 test: return general_allocate_string(ui, prompt, 0, UIT_PROMPT, flags, result_buf, minsize, maxsize, ((void *)0) ); Executed by:
| 5 | ||||||||||||||||||||||||
202 | UIT_PROMPT, flags, result_buf, minsize, executed 5 times by 1 test: return general_allocate_string(ui, prompt, 0, UIT_PROMPT, flags, result_buf, minsize, maxsize, ((void *)0) ); Executed by:
| 5 | ||||||||||||||||||||||||
203 | maxsize, NULL); executed 5 times by 1 test: return general_allocate_string(ui, prompt, 0, UIT_PROMPT, flags, result_buf, minsize, maxsize, ((void *)0) ); Executed by:
| 5 | ||||||||||||||||||||||||
204 | } | - | ||||||||||||||||||||||||
205 | - | |||||||||||||||||||||||||
206 | /* Same as UI_add_input_string(), excepts it takes a copy of the prompt */ | - | ||||||||||||||||||||||||
207 | int UI_dup_input_string(UI *ui, const char *prompt, int flags, | - | ||||||||||||||||||||||||
208 | char *result_buf, int minsize, int maxsize) | - | ||||||||||||||||||||||||
209 | { | - | ||||||||||||||||||||||||
210 | char *prompt_copy = NULL; | - | ||||||||||||||||||||||||
211 | - | |||||||||||||||||||||||||
212 | if (prompt != NULL) {
| 0 | ||||||||||||||||||||||||
213 | prompt_copy = OPENSSL_strdup(prompt); | - | ||||||||||||||||||||||||
214 | if (prompt_copy == NULL) {
| 0 | ||||||||||||||||||||||||
215 | UIerr(UI_F_UI_DUP_INPUT_STRING, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
216 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
217 | } | - | ||||||||||||||||||||||||
218 | } never executed: end of block | 0 | ||||||||||||||||||||||||
219 | - | |||||||||||||||||||||||||
220 | return general_allocate_string(ui, prompt_copy, 1, never executed: return general_allocate_string(ui, prompt_copy, 1, UIT_PROMPT, flags, result_buf, minsize, maxsize, ((void *)0) ); | 0 | ||||||||||||||||||||||||
221 | UIT_PROMPT, flags, result_buf, minsize, never executed: return general_allocate_string(ui, prompt_copy, 1, UIT_PROMPT, flags, result_buf, minsize, maxsize, ((void *)0) ); | 0 | ||||||||||||||||||||||||
222 | maxsize, NULL); never executed: return general_allocate_string(ui, prompt_copy, 1, UIT_PROMPT, flags, result_buf, minsize, maxsize, ((void *)0) ); | 0 | ||||||||||||||||||||||||
223 | } | - | ||||||||||||||||||||||||
224 | - | |||||||||||||||||||||||||
225 | int UI_add_verify_string(UI *ui, const char *prompt, int flags, | - | ||||||||||||||||||||||||
226 | char *result_buf, int minsize, int maxsize, | - | ||||||||||||||||||||||||
227 | const char *test_buf) | - | ||||||||||||||||||||||||
228 | { | - | ||||||||||||||||||||||||
229 | return general_allocate_string(ui, prompt, 0, never executed: return general_allocate_string(ui, prompt, 0, UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf); | 0 | ||||||||||||||||||||||||
230 | UIT_VERIFY, flags, result_buf, minsize, never executed: return general_allocate_string(ui, prompt, 0, UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf); | 0 | ||||||||||||||||||||||||
231 | maxsize, test_buf); never executed: return general_allocate_string(ui, prompt, 0, UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf); | 0 | ||||||||||||||||||||||||
232 | } | - | ||||||||||||||||||||||||
233 | - | |||||||||||||||||||||||||
234 | int UI_dup_verify_string(UI *ui, const char *prompt, int flags, | - | ||||||||||||||||||||||||
235 | char *result_buf, int minsize, int maxsize, | - | ||||||||||||||||||||||||
236 | const char *test_buf) | - | ||||||||||||||||||||||||
237 | { | - | ||||||||||||||||||||||||
238 | char *prompt_copy = NULL; | - | ||||||||||||||||||||||||
239 | - | |||||||||||||||||||||||||
240 | if (prompt != NULL) {
| 0 | ||||||||||||||||||||||||
241 | prompt_copy = OPENSSL_strdup(prompt); | - | ||||||||||||||||||||||||
242 | if (prompt_copy == NULL) {
| 0 | ||||||||||||||||||||||||
243 | UIerr(UI_F_UI_DUP_VERIFY_STRING, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
244 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
245 | } | - | ||||||||||||||||||||||||
246 | } never executed: end of block | 0 | ||||||||||||||||||||||||
247 | - | |||||||||||||||||||||||||
248 | return general_allocate_string(ui, prompt_copy, 1, never executed: return general_allocate_string(ui, prompt_copy, 1, UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf); | 0 | ||||||||||||||||||||||||
249 | UIT_VERIFY, flags, result_buf, minsize, never executed: return general_allocate_string(ui, prompt_copy, 1, UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf); | 0 | ||||||||||||||||||||||||
250 | maxsize, test_buf); never executed: return general_allocate_string(ui, prompt_copy, 1, UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf); | 0 | ||||||||||||||||||||||||
251 | } | - | ||||||||||||||||||||||||
252 | - | |||||||||||||||||||||||||
253 | int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc, | - | ||||||||||||||||||||||||
254 | const char *ok_chars, const char *cancel_chars, | - | ||||||||||||||||||||||||
255 | int flags, char *result_buf) | - | ||||||||||||||||||||||||
256 | { | - | ||||||||||||||||||||||||
257 | return general_allocate_boolean(ui, prompt, action_desc, never executed: return general_allocate_boolean(ui, prompt, action_desc, ok_chars, cancel_chars, 0, UIT_BOOLEAN, flags, result_buf); | 0 | ||||||||||||||||||||||||
258 | ok_chars, cancel_chars, 0, UIT_BOOLEAN, never executed: return general_allocate_boolean(ui, prompt, action_desc, ok_chars, cancel_chars, 0, UIT_BOOLEAN, flags, result_buf); | 0 | ||||||||||||||||||||||||
259 | flags, result_buf); never executed: return general_allocate_boolean(ui, prompt, action_desc, ok_chars, cancel_chars, 0, UIT_BOOLEAN, flags, result_buf); | 0 | ||||||||||||||||||||||||
260 | } | - | ||||||||||||||||||||||||
261 | - | |||||||||||||||||||||||||
262 | int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc, | - | ||||||||||||||||||||||||
263 | const char *ok_chars, const char *cancel_chars, | - | ||||||||||||||||||||||||
264 | int flags, char *result_buf) | - | ||||||||||||||||||||||||
265 | { | - | ||||||||||||||||||||||||
266 | char *prompt_copy = NULL; | - | ||||||||||||||||||||||||
267 | char *action_desc_copy = NULL; | - | ||||||||||||||||||||||||
268 | char *ok_chars_copy = NULL; | - | ||||||||||||||||||||||||
269 | char *cancel_chars_copy = NULL; | - | ||||||||||||||||||||||||
270 | - | |||||||||||||||||||||||||
271 | if (prompt != NULL) {
| 0 | ||||||||||||||||||||||||
272 | prompt_copy = OPENSSL_strdup(prompt); | - | ||||||||||||||||||||||||
273 | if (prompt_copy == NULL) {
| 0 | ||||||||||||||||||||||||
274 | UIerr(UI_F_UI_DUP_INPUT_BOOLEAN, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
275 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
276 | } | - | ||||||||||||||||||||||||
277 | } never executed: end of block | 0 | ||||||||||||||||||||||||
278 | - | |||||||||||||||||||||||||
279 | if (action_desc != NULL) {
| 0 | ||||||||||||||||||||||||
280 | action_desc_copy = OPENSSL_strdup(action_desc); | - | ||||||||||||||||||||||||
281 | if (action_desc_copy == NULL) {
| 0 | ||||||||||||||||||||||||
282 | UIerr(UI_F_UI_DUP_INPUT_BOOLEAN, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
283 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
284 | } | - | ||||||||||||||||||||||||
285 | } never executed: end of block | 0 | ||||||||||||||||||||||||
286 | - | |||||||||||||||||||||||||
287 | if (ok_chars != NULL) {
| 0 | ||||||||||||||||||||||||
288 | ok_chars_copy = OPENSSL_strdup(ok_chars); | - | ||||||||||||||||||||||||
289 | if (ok_chars_copy == NULL) {
| 0 | ||||||||||||||||||||||||
290 | UIerr(UI_F_UI_DUP_INPUT_BOOLEAN, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
291 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
292 | } | - | ||||||||||||||||||||||||
293 | } never executed: end of block | 0 | ||||||||||||||||||||||||
294 | - | |||||||||||||||||||||||||
295 | if (cancel_chars != NULL) {
| 0 | ||||||||||||||||||||||||
296 | cancel_chars_copy = OPENSSL_strdup(cancel_chars); | - | ||||||||||||||||||||||||
297 | if (cancel_chars_copy == NULL) {
| 0 | ||||||||||||||||||||||||
298 | UIerr(UI_F_UI_DUP_INPUT_BOOLEAN, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
299 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
300 | } | - | ||||||||||||||||||||||||
301 | } never executed: end of block | 0 | ||||||||||||||||||||||||
302 | - | |||||||||||||||||||||||||
303 | return general_allocate_boolean(ui, prompt_copy, action_desc_copy, never executed: return general_allocate_boolean(ui, prompt_copy, action_desc_copy, ok_chars_copy, cancel_chars_copy, 1, UIT_BOOLEAN, flags, result_buf); | 0 | ||||||||||||||||||||||||
304 | ok_chars_copy, cancel_chars_copy, 1, never executed: return general_allocate_boolean(ui, prompt_copy, action_desc_copy, ok_chars_copy, cancel_chars_copy, 1, UIT_BOOLEAN, flags, result_buf); | 0 | ||||||||||||||||||||||||
305 | UIT_BOOLEAN, flags, result_buf); never executed: return general_allocate_boolean(ui, prompt_copy, action_desc_copy, ok_chars_copy, cancel_chars_copy, 1, UIT_BOOLEAN, flags, result_buf); | 0 | ||||||||||||||||||||||||
306 | err: | - | ||||||||||||||||||||||||
307 | OPENSSL_free(prompt_copy); | - | ||||||||||||||||||||||||
308 | OPENSSL_free(action_desc_copy); | - | ||||||||||||||||||||||||
309 | OPENSSL_free(ok_chars_copy); | - | ||||||||||||||||||||||||
310 | OPENSSL_free(cancel_chars_copy); | - | ||||||||||||||||||||||||
311 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
312 | } | - | ||||||||||||||||||||||||
313 | - | |||||||||||||||||||||||||
314 | int UI_add_info_string(UI *ui, const char *text) | - | ||||||||||||||||||||||||
315 | { | - | ||||||||||||||||||||||||
316 | return general_allocate_string(ui, text, 0, UIT_INFO, 0, NULL, 0, 0, never executed: return general_allocate_string(ui, text, 0, UIT_INFO, 0, ((void *)0) , 0, 0, ((void *)0) ); | 0 | ||||||||||||||||||||||||
317 | NULL); never executed: return general_allocate_string(ui, text, 0, UIT_INFO, 0, ((void *)0) , 0, 0, ((void *)0) ); | 0 | ||||||||||||||||||||||||
318 | } | - | ||||||||||||||||||||||||
319 | - | |||||||||||||||||||||||||
320 | int UI_dup_info_string(UI *ui, const char *text) | - | ||||||||||||||||||||||||
321 | { | - | ||||||||||||||||||||||||
322 | char *text_copy = NULL; | - | ||||||||||||||||||||||||
323 | - | |||||||||||||||||||||||||
324 | if (text != NULL) {
| 0 | ||||||||||||||||||||||||
325 | text_copy = OPENSSL_strdup(text); | - | ||||||||||||||||||||||||
326 | if (text_copy == NULL) {
| 0 | ||||||||||||||||||||||||
327 | UIerr(UI_F_UI_DUP_INFO_STRING, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
328 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
329 | } | - | ||||||||||||||||||||||||
330 | } never executed: end of block | 0 | ||||||||||||||||||||||||
331 | - | |||||||||||||||||||||||||
332 | return general_allocate_string(ui, text_copy, 1, UIT_INFO, 0, NULL, never executed: return general_allocate_string(ui, text_copy, 1, UIT_INFO, 0, ((void *)0) , 0, 0, ((void *)0) ); | 0 | ||||||||||||||||||||||||
333 | 0, 0, NULL); never executed: return general_allocate_string(ui, text_copy, 1, UIT_INFO, 0, ((void *)0) , 0, 0, ((void *)0) ); | 0 | ||||||||||||||||||||||||
334 | } | - | ||||||||||||||||||||||||
335 | - | |||||||||||||||||||||||||
336 | int UI_add_error_string(UI *ui, const char *text) | - | ||||||||||||||||||||||||
337 | { | - | ||||||||||||||||||||||||
338 | return general_allocate_string(ui, text, 0, UIT_ERROR, 0, NULL, 0, 0, never executed: return general_allocate_string(ui, text, 0, UIT_ERROR, 0, ((void *)0) , 0, 0, ((void *)0) ); | 0 | ||||||||||||||||||||||||
339 | NULL); never executed: return general_allocate_string(ui, text, 0, UIT_ERROR, 0, ((void *)0) , 0, 0, ((void *)0) ); | 0 | ||||||||||||||||||||||||
340 | } | - | ||||||||||||||||||||||||
341 | - | |||||||||||||||||||||||||
342 | int UI_dup_error_string(UI *ui, const char *text) | - | ||||||||||||||||||||||||
343 | { | - | ||||||||||||||||||||||||
344 | char *text_copy = NULL; | - | ||||||||||||||||||||||||
345 | - | |||||||||||||||||||||||||
346 | if (text != NULL) {
| 0 | ||||||||||||||||||||||||
347 | text_copy = OPENSSL_strdup(text); | - | ||||||||||||||||||||||||
348 | if (text_copy == NULL) {
| 0 | ||||||||||||||||||||||||
349 | UIerr(UI_F_UI_DUP_ERROR_STRING, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
350 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
351 | } | - | ||||||||||||||||||||||||
352 | } never executed: end of block | 0 | ||||||||||||||||||||||||
353 | return general_allocate_string(ui, text_copy, 1, UIT_ERROR, 0, NULL, never executed: return general_allocate_string(ui, text_copy, 1, UIT_ERROR, 0, ((void *)0) , 0, 0, ((void *)0) ); | 0 | ||||||||||||||||||||||||
354 | 0, 0, NULL); never executed: return general_allocate_string(ui, text_copy, 1, UIT_ERROR, 0, ((void *)0) , 0, 0, ((void *)0) ); | 0 | ||||||||||||||||||||||||
355 | } | - | ||||||||||||||||||||||||
356 | - | |||||||||||||||||||||||||
357 | char *UI_construct_prompt(UI *ui, const char *object_desc, | - | ||||||||||||||||||||||||
358 | const char *object_name) | - | ||||||||||||||||||||||||
359 | { | - | ||||||||||||||||||||||||
360 | char *prompt = NULL; | - | ||||||||||||||||||||||||
361 | - | |||||||||||||||||||||||||
362 | if (ui->meth->ui_construct_prompt != NULL)
| 0-4 | ||||||||||||||||||||||||
363 | prompt = ui->meth->ui_construct_prompt(ui, object_desc, object_name); never executed: prompt = ui->meth->ui_construct_prompt(ui, object_desc, object_name); | 0 | ||||||||||||||||||||||||
364 | else { | - | ||||||||||||||||||||||||
365 | char prompt1[] = "Enter "; | - | ||||||||||||||||||||||||
366 | char prompt2[] = " for "; | - | ||||||||||||||||||||||||
367 | char prompt3[] = ":"; | - | ||||||||||||||||||||||||
368 | int len = 0; | - | ||||||||||||||||||||||||
369 | - | |||||||||||||||||||||||||
370 | if (object_desc == NULL)
| 0-4 | ||||||||||||||||||||||||
371 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
372 | len = sizeof(prompt1) - 1 + strlen(object_desc); | - | ||||||||||||||||||||||||
373 | if (object_name != NULL)
| 0-4 | ||||||||||||||||||||||||
374 | len += sizeof(prompt2) - 1 + strlen(object_name); executed 4 times by 1 test: len += sizeof(prompt2) - 1 + strlen(object_name); Executed by:
| 4 | ||||||||||||||||||||||||
375 | len += sizeof(prompt3) - 1; | - | ||||||||||||||||||||||||
376 | - | |||||||||||||||||||||||||
377 | if ((prompt = OPENSSL_malloc(len + 1)) == NULL) {
| 0-4 | ||||||||||||||||||||||||
378 | UIerr(UI_F_UI_CONSTRUCT_PROMPT, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
379 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
380 | } | - | ||||||||||||||||||||||||
381 | OPENSSL_strlcpy(prompt, prompt1, len + 1); | - | ||||||||||||||||||||||||
382 | OPENSSL_strlcat(prompt, object_desc, len + 1); | - | ||||||||||||||||||||||||
383 | if (object_name != NULL) {
| 0-4 | ||||||||||||||||||||||||
384 | OPENSSL_strlcat(prompt, prompt2, len + 1); | - | ||||||||||||||||||||||||
385 | OPENSSL_strlcat(prompt, object_name, len + 1); | - | ||||||||||||||||||||||||
386 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
387 | OPENSSL_strlcat(prompt, prompt3, len + 1); | - | ||||||||||||||||||||||||
388 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
389 | return prompt; executed 4 times by 1 test: return prompt; Executed by:
| 4 | ||||||||||||||||||||||||
390 | } | - | ||||||||||||||||||||||||
391 | - | |||||||||||||||||||||||||
392 | void *UI_add_user_data(UI *ui, void *user_data) | - | ||||||||||||||||||||||||
393 | { | - | ||||||||||||||||||||||||
394 | void *old_data = ui->user_data; | - | ||||||||||||||||||||||||
395 | - | |||||||||||||||||||||||||
396 | if ((ui->flags & UI_FLAG_DUPL_DATA) != 0) {
| 0-5 | ||||||||||||||||||||||||
397 | ui->meth->ui_destroy_data(ui, old_data); | - | ||||||||||||||||||||||||
398 | old_data = NULL; | - | ||||||||||||||||||||||||
399 | } never executed: end of block | 0 | ||||||||||||||||||||||||
400 | ui->user_data = user_data; | - | ||||||||||||||||||||||||
401 | ui->flags &= ~UI_FLAG_DUPL_DATA; | - | ||||||||||||||||||||||||
402 | return old_data; executed 5 times by 1 test: return old_data; Executed by:
| 5 | ||||||||||||||||||||||||
403 | } | - | ||||||||||||||||||||||||
404 | - | |||||||||||||||||||||||||
405 | int UI_dup_user_data(UI *ui, void *user_data) | - | ||||||||||||||||||||||||
406 | { | - | ||||||||||||||||||||||||
407 | void *duplicate = NULL; | - | ||||||||||||||||||||||||
408 | - | |||||||||||||||||||||||||
409 | if (ui->meth->ui_duplicate_data == NULL
| 0 | ||||||||||||||||||||||||
410 | || ui->meth->ui_destroy_data == NULL) {
| 0 | ||||||||||||||||||||||||
411 | UIerr(UI_F_UI_DUP_USER_DATA, UI_R_USER_DATA_DUPLICATION_UNSUPPORTED); | - | ||||||||||||||||||||||||
412 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
413 | } | - | ||||||||||||||||||||||||
414 | - | |||||||||||||||||||||||||
415 | duplicate = ui->meth->ui_duplicate_data(ui, user_data); | - | ||||||||||||||||||||||||
416 | if (duplicate == NULL) {
| 0 | ||||||||||||||||||||||||
417 | UIerr(UI_F_UI_DUP_USER_DATA, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
418 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
419 | } | - | ||||||||||||||||||||||||
420 | - | |||||||||||||||||||||||||
421 | (void)UI_add_user_data(ui, duplicate); | - | ||||||||||||||||||||||||
422 | ui->flags |= UI_FLAG_DUPL_DATA; | - | ||||||||||||||||||||||||
423 | - | |||||||||||||||||||||||||
424 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
425 | } | - | ||||||||||||||||||||||||
426 | - | |||||||||||||||||||||||||
427 | void *UI_get0_user_data(UI *ui) | - | ||||||||||||||||||||||||
428 | { | - | ||||||||||||||||||||||||
429 | return ui->user_data; executed 17 times by 1 test: return ui->user_data; Executed by:
| 17 | ||||||||||||||||||||||||
430 | } | - | ||||||||||||||||||||||||
431 | - | |||||||||||||||||||||||||
432 | const char *UI_get0_result(UI *ui, int i) | - | ||||||||||||||||||||||||
433 | { | - | ||||||||||||||||||||||||
434 | if (i < 0) {
| 0 | ||||||||||||||||||||||||
435 | UIerr(UI_F_UI_GET0_RESULT, UI_R_INDEX_TOO_SMALL); | - | ||||||||||||||||||||||||
436 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
437 | } | - | ||||||||||||||||||||||||
438 | if (i >= sk_UI_STRING_num(ui->strings)) {
| 0 | ||||||||||||||||||||||||
439 | UIerr(UI_F_UI_GET0_RESULT, UI_R_INDEX_TOO_LARGE); | - | ||||||||||||||||||||||||
440 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
441 | } | - | ||||||||||||||||||||||||
442 | return UI_get0_result_string(sk_UI_STRING_value(ui->strings, i)); never executed: return UI_get0_result_string(sk_UI_STRING_value(ui->strings, i)); | 0 | ||||||||||||||||||||||||
443 | } | - | ||||||||||||||||||||||||
444 | - | |||||||||||||||||||||||||
445 | int UI_get_result_length(UI *ui, int i) | - | ||||||||||||||||||||||||
446 | { | - | ||||||||||||||||||||||||
447 | if (i < 0) {
| 0 | ||||||||||||||||||||||||
448 | UIerr(UI_F_UI_GET_RESULT_LENGTH, UI_R_INDEX_TOO_SMALL); | - | ||||||||||||||||||||||||
449 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
450 | } | - | ||||||||||||||||||||||||
451 | if (i >= sk_UI_STRING_num(ui->strings)) {
| 0 | ||||||||||||||||||||||||
452 | UIerr(UI_F_UI_GET_RESULT_LENGTH, UI_R_INDEX_TOO_LARGE); | - | ||||||||||||||||||||||||
453 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
454 | } | - | ||||||||||||||||||||||||
455 | return UI_get_result_string_length(sk_UI_STRING_value(ui->strings, i)); never executed: return UI_get_result_string_length(sk_UI_STRING_value(ui->strings, i)); | 0 | ||||||||||||||||||||||||
456 | } | - | ||||||||||||||||||||||||
457 | - | |||||||||||||||||||||||||
458 | static int print_error(const char *str, size_t len, UI *ui) | - | ||||||||||||||||||||||||
459 | { | - | ||||||||||||||||||||||||
460 | UI_STRING uis; | - | ||||||||||||||||||||||||
461 | - | |||||||||||||||||||||||||
462 | memset(&uis, 0, sizeof(uis)); | - | ||||||||||||||||||||||||
463 | uis.type = UIT_ERROR; | - | ||||||||||||||||||||||||
464 | uis.out_string = str; | - | ||||||||||||||||||||||||
465 | - | |||||||||||||||||||||||||
466 | if (ui->meth->ui_write_string != NULL
| 0 | ||||||||||||||||||||||||
467 | && ui->meth->ui_write_string(ui, &uis) <= 0)
| 0 | ||||||||||||||||||||||||
468 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
469 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
470 | } | - | ||||||||||||||||||||||||
471 | - | |||||||||||||||||||||||||
472 | int UI_process(UI *ui) | - | ||||||||||||||||||||||||
473 | { | - | ||||||||||||||||||||||||
474 | int i, ok = 0; | - | ||||||||||||||||||||||||
475 | const char *state = "processing"; | - | ||||||||||||||||||||||||
476 | - | |||||||||||||||||||||||||
477 | if (ui->meth->ui_open_session != NULL
| 0-5 | ||||||||||||||||||||||||
478 | && ui->meth->ui_open_session(ui) <= 0) {
| 0-5 | ||||||||||||||||||||||||
479 | state = "opening session"; | - | ||||||||||||||||||||||||
480 | ok = -1; | - | ||||||||||||||||||||||||
481 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
482 | } | - | ||||||||||||||||||||||||
483 | - | |||||||||||||||||||||||||
484 | if (ui->flags & UI_FLAG_PRINT_ERRORS)
| 1-4 | ||||||||||||||||||||||||
485 | ERR_print_errors_cb((int (*)(const char *, size_t, void *)) executed 4 times by 1 test: ERR_print_errors_cb((int (*)(const char *, size_t, void *)) print_error, (void *)ui); Executed by:
| 4 | ||||||||||||||||||||||||
486 | print_error, (void *)ui); executed 4 times by 1 test: ERR_print_errors_cb((int (*)(const char *, size_t, void *)) print_error, (void *)ui); Executed by:
| 4 | ||||||||||||||||||||||||
487 | - | |||||||||||||||||||||||||
488 | for (i = 0; i < sk_UI_STRING_num(ui->strings); i++) {
| 5 | ||||||||||||||||||||||||
489 | if (ui->meth->ui_write_string != NULL
| 0-5 | ||||||||||||||||||||||||
490 | && (ui->meth->ui_write_string(ui,
| 0-5 | ||||||||||||||||||||||||
491 | sk_UI_STRING_value(ui->strings, i))
| 0-5 | ||||||||||||||||||||||||
492 | <= 0))
| 0-5 | ||||||||||||||||||||||||
493 | { | - | ||||||||||||||||||||||||
494 | state = "writing strings"; | - | ||||||||||||||||||||||||
495 | ok = -1; | - | ||||||||||||||||||||||||
496 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
497 | } | - | ||||||||||||||||||||||||
498 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||||||||||||||
499 | - | |||||||||||||||||||||||||
500 | if (ui->meth->ui_flush != NULL)
| 0-5 | ||||||||||||||||||||||||
501 | switch (ui->meth->ui_flush(ui)) { | - | ||||||||||||||||||||||||
502 | case -1: /* Interrupt/Cancel/something... */ never executed: case -1: | 0 | ||||||||||||||||||||||||
503 | ok = -2; | - | ||||||||||||||||||||||||
504 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
505 | case 0: /* Errors */ never executed: case 0: | 0 | ||||||||||||||||||||||||
506 | state = "flushing"; | - | ||||||||||||||||||||||||
507 | ok = -1; | - | ||||||||||||||||||||||||
508 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
509 | default: /* Success */ never executed: default: | 0 | ||||||||||||||||||||||||
510 | ok = 0; | - | ||||||||||||||||||||||||
511 | break; never executed: break; | 0 | ||||||||||||||||||||||||
512 | } | - | ||||||||||||||||||||||||
513 | - | |||||||||||||||||||||||||
514 | for (i = 0; i < sk_UI_STRING_num(ui->strings); i++) {
| 5 | ||||||||||||||||||||||||
515 | if (ui->meth->ui_read_string != NULL) {
| 0-5 | ||||||||||||||||||||||||
516 | switch (ui->meth->ui_read_string(ui, | - | ||||||||||||||||||||||||
517 | sk_UI_STRING_value(ui->strings, | - | ||||||||||||||||||||||||
518 | i))) { | - | ||||||||||||||||||||||||
519 | case -1: /* Interrupt/Cancel/something... */ never executed: case -1: | 0 | ||||||||||||||||||||||||
520 | ok = -2; | - | ||||||||||||||||||||||||
521 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
522 | case 0: /* Errors */ never executed: case 0: | 0 | ||||||||||||||||||||||||
523 | state = "reading strings"; | - | ||||||||||||||||||||||||
524 | ok = -1; | - | ||||||||||||||||||||||||
525 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
526 | default: /* Success */ executed 5 times by 1 test: default: Executed by:
| 5 | ||||||||||||||||||||||||
527 | ok = 0; | - | ||||||||||||||||||||||||
528 | break; executed 5 times by 1 test: break; Executed by:
| 5 | ||||||||||||||||||||||||
529 | } | - | ||||||||||||||||||||||||
530 | } | - | ||||||||||||||||||||||||
531 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||||||||||||||
532 | - | |||||||||||||||||||||||||
533 | state = NULL; | - | ||||||||||||||||||||||||
534 | err: code before this statement executed 5 times by 1 test: err: Executed by:
| 5 | ||||||||||||||||||||||||
535 | if (ui->meth->ui_close_session != NULL
| 0-5 | ||||||||||||||||||||||||
536 | && ui->meth->ui_close_session(ui) <= 0) {
| 0-5 | ||||||||||||||||||||||||
537 | if (state == NULL)
| 0 | ||||||||||||||||||||||||
538 | state = "closing session"; never executed: state = "closing session"; | 0 | ||||||||||||||||||||||||
539 | ok = -1; | - | ||||||||||||||||||||||||
540 | } never executed: end of block | 0 | ||||||||||||||||||||||||
541 | - | |||||||||||||||||||||||||
542 | if (ok == -1) {
| 0-5 | ||||||||||||||||||||||||
543 | UIerr(UI_F_UI_PROCESS, UI_R_PROCESSING_ERROR); | - | ||||||||||||||||||||||||
544 | ERR_add_error_data(2, "while ", state); | - | ||||||||||||||||||||||||
545 | } never executed: end of block | 0 | ||||||||||||||||||||||||
546 | return ok; executed 5 times by 1 test: return ok; Executed by:
| 5 | ||||||||||||||||||||||||
547 | } | - | ||||||||||||||||||||||||
548 | - | |||||||||||||||||||||||||
549 | int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f) (void)) | - | ||||||||||||||||||||||||
550 | { | - | ||||||||||||||||||||||||
551 | if (ui == NULL) {
| 0-4 | ||||||||||||||||||||||||
552 | UIerr(UI_F_UI_CTRL, ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
553 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
554 | } | - | ||||||||||||||||||||||||
555 | switch (cmd) { | - | ||||||||||||||||||||||||
556 | case UI_CTRL_PRINT_ERRORS: executed 4 times by 1 test: case 1: Executed by:
| 4 | ||||||||||||||||||||||||
557 | { | - | ||||||||||||||||||||||||
558 | int save_flag = ! !(ui->flags & UI_FLAG_PRINT_ERRORS); | - | ||||||||||||||||||||||||
559 | if (i)
| 0-4 | ||||||||||||||||||||||||
560 | ui->flags |= UI_FLAG_PRINT_ERRORS; executed 4 times by 1 test: ui->flags |= 0x0100; Executed by:
| 4 | ||||||||||||||||||||||||
561 | else | - | ||||||||||||||||||||||||
562 | ui->flags &= ~UI_FLAG_PRINT_ERRORS; never executed: ui->flags &= ~0x0100; | 0 | ||||||||||||||||||||||||
563 | return save_flag; executed 4 times by 1 test: return save_flag; Executed by:
| 4 | ||||||||||||||||||||||||
564 | } | - | ||||||||||||||||||||||||
565 | case UI_CTRL_IS_REDOABLE: never executed: case 2: | 0 | ||||||||||||||||||||||||
566 | return ! !(ui->flags & UI_FLAG_REDOABLE); never executed: return ! !(ui->flags & 0x0001); | 0 | ||||||||||||||||||||||||
567 | default: never executed: default: | 0 | ||||||||||||||||||||||||
568 | break; never executed: break; | 0 | ||||||||||||||||||||||||
569 | } | - | ||||||||||||||||||||||||
570 | UIerr(UI_F_UI_CTRL, UI_R_UNKNOWN_CONTROL_COMMAND); | - | ||||||||||||||||||||||||
571 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
572 | } | - | ||||||||||||||||||||||||
573 | - | |||||||||||||||||||||||||
574 | int UI_set_ex_data(UI *r, int idx, void *arg) | - | ||||||||||||||||||||||||
575 | { | - | ||||||||||||||||||||||||
576 | return CRYPTO_set_ex_data(&r->ex_data, idx, arg); never executed: return CRYPTO_set_ex_data(&r->ex_data, idx, arg); | 0 | ||||||||||||||||||||||||
577 | } | - | ||||||||||||||||||||||||
578 | - | |||||||||||||||||||||||||
579 | void *UI_get_ex_data(UI *r, int idx) | - | ||||||||||||||||||||||||
580 | { | - | ||||||||||||||||||||||||
581 | return CRYPTO_get_ex_data(&r->ex_data, idx); never executed: return CRYPTO_get_ex_data(&r->ex_data, idx); | 0 | ||||||||||||||||||||||||
582 | } | - | ||||||||||||||||||||||||
583 | - | |||||||||||||||||||||||||
584 | const UI_METHOD *UI_get_method(UI *ui) | - | ||||||||||||||||||||||||
585 | { | - | ||||||||||||||||||||||||
586 | return ui->meth; executed 1 time by 1 test: return ui->meth; Executed by:
| 1 | ||||||||||||||||||||||||
587 | } | - | ||||||||||||||||||||||||
588 | - | |||||||||||||||||||||||||
589 | const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth) | - | ||||||||||||||||||||||||
590 | { | - | ||||||||||||||||||||||||
591 | ui->meth = meth; | - | ||||||||||||||||||||||||
592 | return ui->meth; never executed: return ui->meth; | 0 | ||||||||||||||||||||||||
593 | } | - | ||||||||||||||||||||||||
594 | - | |||||||||||||||||||||||||
595 | UI_METHOD *UI_create_method(const char *name) | - | ||||||||||||||||||||||||
596 | { | - | ||||||||||||||||||||||||
597 | UI_METHOD *ui_method = NULL; | - | ||||||||||||||||||||||||
598 | - | |||||||||||||||||||||||||
599 | if ((ui_method = OPENSSL_zalloc(sizeof(*ui_method))) == NULL
| 0-1790 | ||||||||||||||||||||||||
600 | || (ui_method->name = OPENSSL_strdup(name)) == NULL
| 0-1790 | ||||||||||||||||||||||||
601 | || !CRYPTO_new_ex_data(CRYPTO_EX_INDEX_UI_METHOD, ui_method,
| 0-1790 | ||||||||||||||||||||||||
602 | &ui_method->ex_data)) {
| 0-1790 | ||||||||||||||||||||||||
603 | if (ui_method)
| 0 | ||||||||||||||||||||||||
604 | OPENSSL_free(ui_method->name); never executed: CRYPTO_free(ui_method->name, __FILE__, 604); | 0 | ||||||||||||||||||||||||
605 | OPENSSL_free(ui_method); | - | ||||||||||||||||||||||||
606 | UIerr(UI_F_UI_CREATE_METHOD, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
607 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
608 | } | - | ||||||||||||||||||||||||
609 | return ui_method; executed 1790 times by 1 test: return ui_method; Executed by:
| 1790 | ||||||||||||||||||||||||
610 | } | - | ||||||||||||||||||||||||
611 | - | |||||||||||||||||||||||||
612 | /* | - | ||||||||||||||||||||||||
613 | * BIG FSCKING WARNING!!!! If you use this on a statically allocated method | - | ||||||||||||||||||||||||
614 | * (that is, it hasn't been allocated using UI_create_method(), you deserve | - | ||||||||||||||||||||||||
615 | * anything Murphy can throw at you and more! You have been warned. | - | ||||||||||||||||||||||||
616 | */ | - | ||||||||||||||||||||||||
617 | void UI_destroy_method(UI_METHOD *ui_method) | - | ||||||||||||||||||||||||
618 | { | - | ||||||||||||||||||||||||
619 | if (ui_method == NULL)
| 0-1790 | ||||||||||||||||||||||||
620 | return; never executed: return; | 0 | ||||||||||||||||||||||||
621 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_UI_METHOD, ui_method, | - | ||||||||||||||||||||||||
622 | &ui_method->ex_data); | - | ||||||||||||||||||||||||
623 | OPENSSL_free(ui_method->name); | - | ||||||||||||||||||||||||
624 | ui_method->name = NULL; | - | ||||||||||||||||||||||||
625 | OPENSSL_free(ui_method); | - | ||||||||||||||||||||||||
626 | } executed 1790 times by 1 test: end of block Executed by:
| 1790 | ||||||||||||||||||||||||
627 | - | |||||||||||||||||||||||||
628 | int UI_method_set_opener(UI_METHOD *method, int (*opener) (UI *ui)) | - | ||||||||||||||||||||||||
629 | { | - | ||||||||||||||||||||||||
630 | if (method != NULL) {
| 0-1790 | ||||||||||||||||||||||||
631 | method->ui_open_session = opener; | - | ||||||||||||||||||||||||
632 | return 0; executed 1790 times by 1 test: return 0; Executed by:
| 1790 | ||||||||||||||||||||||||
633 | } | - | ||||||||||||||||||||||||
634 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
635 | } | - | ||||||||||||||||||||||||
636 | - | |||||||||||||||||||||||||
637 | int UI_method_set_writer(UI_METHOD *method, | - | ||||||||||||||||||||||||
638 | int (*writer) (UI *ui, UI_STRING *uis)) | - | ||||||||||||||||||||||||
639 | { | - | ||||||||||||||||||||||||
640 | if (method != NULL) {
| 0-1790 | ||||||||||||||||||||||||
641 | method->ui_write_string = writer; | - | ||||||||||||||||||||||||
642 | return 0; executed 1790 times by 1 test: return 0; Executed by:
| 1790 | ||||||||||||||||||||||||
643 | } | - | ||||||||||||||||||||||||
644 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
645 | } | - | ||||||||||||||||||||||||
646 | - | |||||||||||||||||||||||||
647 | int UI_method_set_flusher(UI_METHOD *method, int (*flusher) (UI *ui)) | - | ||||||||||||||||||||||||
648 | { | - | ||||||||||||||||||||||||
649 | if (method != NULL) {
| 0 | ||||||||||||||||||||||||
650 | method->ui_flush = flusher; | - | ||||||||||||||||||||||||
651 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
652 | } | - | ||||||||||||||||||||||||
653 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
654 | } | - | ||||||||||||||||||||||||
655 | - | |||||||||||||||||||||||||
656 | int UI_method_set_reader(UI_METHOD *method, | - | ||||||||||||||||||||||||
657 | int (*reader) (UI *ui, UI_STRING *uis)) | - | ||||||||||||||||||||||||
658 | { | - | ||||||||||||||||||||||||
659 | if (method != NULL) {
| 0-1790 | ||||||||||||||||||||||||
660 | method->ui_read_string = reader; | - | ||||||||||||||||||||||||
661 | return 0; executed 1790 times by 1 test: return 0; Executed by:
| 1790 | ||||||||||||||||||||||||
662 | } | - | ||||||||||||||||||||||||
663 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
664 | } | - | ||||||||||||||||||||||||
665 | - | |||||||||||||||||||||||||
666 | int UI_method_set_closer(UI_METHOD *method, int (*closer) (UI *ui)) | - | ||||||||||||||||||||||||
667 | { | - | ||||||||||||||||||||||||
668 | if (method != NULL) {
| 0-1790 | ||||||||||||||||||||||||
669 | method->ui_close_session = closer; | - | ||||||||||||||||||||||||
670 | return 0; executed 1790 times by 1 test: return 0; Executed by:
| 1790 | ||||||||||||||||||||||||
671 | } | - | ||||||||||||||||||||||||
672 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
673 | } | - | ||||||||||||||||||||||||
674 | - | |||||||||||||||||||||||||
675 | int UI_method_set_data_duplicator(UI_METHOD *method, | - | ||||||||||||||||||||||||
676 | void *(*duplicator) (UI *ui, void *ui_data), | - | ||||||||||||||||||||||||
677 | void (*destructor)(UI *ui, void *ui_data)) | - | ||||||||||||||||||||||||
678 | { | - | ||||||||||||||||||||||||
679 | if (method != NULL) {
| 0 | ||||||||||||||||||||||||
680 | method->ui_duplicate_data = duplicator; | - | ||||||||||||||||||||||||
681 | method->ui_destroy_data = destructor; | - | ||||||||||||||||||||||||
682 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
683 | } | - | ||||||||||||||||||||||||
684 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
685 | } | - | ||||||||||||||||||||||||
686 | - | |||||||||||||||||||||||||
687 | int UI_method_set_prompt_constructor(UI_METHOD *method, | - | ||||||||||||||||||||||||
688 | char *(*prompt_constructor) (UI *ui, | - | ||||||||||||||||||||||||
689 | const char | - | ||||||||||||||||||||||||
690 | *object_desc, | - | ||||||||||||||||||||||||
691 | const char | - | ||||||||||||||||||||||||
692 | *object_name)) | - | ||||||||||||||||||||||||
693 | { | - | ||||||||||||||||||||||||
694 | if (method != NULL) {
| 0 | ||||||||||||||||||||||||
695 | method->ui_construct_prompt = prompt_constructor; | - | ||||||||||||||||||||||||
696 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
697 | } | - | ||||||||||||||||||||||||
698 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
699 | } | - | ||||||||||||||||||||||||
700 | - | |||||||||||||||||||||||||
701 | int UI_method_set_ex_data(UI_METHOD *method, int idx, void *data) | - | ||||||||||||||||||||||||
702 | { | - | ||||||||||||||||||||||||
703 | return CRYPTO_set_ex_data(&method->ex_data, idx, data); executed 1 time by 1 test: return CRYPTO_set_ex_data(&method->ex_data, idx, data); Executed by:
| 1 | ||||||||||||||||||||||||
704 | } | - | ||||||||||||||||||||||||
705 | - | |||||||||||||||||||||||||
706 | int (*UI_method_get_opener(const UI_METHOD *method)) (UI *) | - | ||||||||||||||||||||||||
707 | { | - | ||||||||||||||||||||||||
708 | if (method != NULL)
| 0-4 | ||||||||||||||||||||||||
709 | return method->ui_open_session; executed 4 times by 1 test: return method->ui_open_session; Executed by:
| 4 | ||||||||||||||||||||||||
710 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
711 | } | - | ||||||||||||||||||||||||
712 | - | |||||||||||||||||||||||||
713 | int (*UI_method_get_writer(const UI_METHOD *method)) (UI *, UI_STRING *) | - | ||||||||||||||||||||||||
714 | { | - | ||||||||||||||||||||||||
715 | if (method != NULL)
| 0 | ||||||||||||||||||||||||
716 | return method->ui_write_string; never executed: return method->ui_write_string; | 0 | ||||||||||||||||||||||||
717 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
718 | } | - | ||||||||||||||||||||||||
719 | - | |||||||||||||||||||||||||
720 | int (*UI_method_get_flusher(const UI_METHOD *method)) (UI *) | - | ||||||||||||||||||||||||
721 | { | - | ||||||||||||||||||||||||
722 | if (method != NULL)
| 0 | ||||||||||||||||||||||||
723 | return method->ui_flush; never executed: return method->ui_flush; | 0 | ||||||||||||||||||||||||
724 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
725 | } | - | ||||||||||||||||||||||||
726 | - | |||||||||||||||||||||||||
727 | int (*UI_method_get_reader(const UI_METHOD *method)) (UI *, UI_STRING *) | - | ||||||||||||||||||||||||
728 | { | - | ||||||||||||||||||||||||
729 | if (method != NULL)
| 0 | ||||||||||||||||||||||||
730 | return method->ui_read_string; never executed: return method->ui_read_string; | 0 | ||||||||||||||||||||||||
731 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
732 | } | - | ||||||||||||||||||||||||
733 | - | |||||||||||||||||||||||||
734 | int (*UI_method_get_closer(const UI_METHOD *method)) (UI *) | - | ||||||||||||||||||||||||
735 | { | - | ||||||||||||||||||||||||
736 | if (method != NULL)
| 0-4 | ||||||||||||||||||||||||
737 | return method->ui_close_session; executed 4 times by 1 test: return method->ui_close_session; Executed by:
| 4 | ||||||||||||||||||||||||
738 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
739 | } | - | ||||||||||||||||||||||||
740 | - | |||||||||||||||||||||||||
741 | char *(*UI_method_get_prompt_constructor(const UI_METHOD *method)) | - | ||||||||||||||||||||||||
742 | (UI *, const char *, const char *) | - | ||||||||||||||||||||||||
743 | { | - | ||||||||||||||||||||||||
744 | if (method != NULL)
| 0 | ||||||||||||||||||||||||
745 | return method->ui_construct_prompt; never executed: return method->ui_construct_prompt; | 0 | ||||||||||||||||||||||||
746 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
747 | } | - | ||||||||||||||||||||||||
748 | - | |||||||||||||||||||||||||
749 | void *(*UI_method_get_data_duplicator(const UI_METHOD *method)) (UI *, void *) | - | ||||||||||||||||||||||||
750 | { | - | ||||||||||||||||||||||||
751 | if (method != NULL)
| 0 | ||||||||||||||||||||||||
752 | return method->ui_duplicate_data; never executed: return method->ui_duplicate_data; | 0 | ||||||||||||||||||||||||
753 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
754 | } | - | ||||||||||||||||||||||||
755 | - | |||||||||||||||||||||||||
756 | void (*UI_method_get_data_destructor(const UI_METHOD *method)) (UI *, void *) | - | ||||||||||||||||||||||||
757 | { | - | ||||||||||||||||||||||||
758 | if (method != NULL)
| 0 | ||||||||||||||||||||||||
759 | return method->ui_destroy_data; never executed: return method->ui_destroy_data; | 0 | ||||||||||||||||||||||||
760 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
761 | } | - | ||||||||||||||||||||||||
762 | - | |||||||||||||||||||||||||
763 | const void *UI_method_get_ex_data(const UI_METHOD *method, int idx) | - | ||||||||||||||||||||||||
764 | { | - | ||||||||||||||||||||||||
765 | return CRYPTO_get_ex_data(&method->ex_data, idx); executed 1 time by 1 test: return CRYPTO_get_ex_data(&method->ex_data, idx); Executed by:
| 1 | ||||||||||||||||||||||||
766 | } | - | ||||||||||||||||||||||||
767 | - | |||||||||||||||||||||||||
768 | enum UI_string_types UI_get_string_type(UI_STRING *uis) | - | ||||||||||||||||||||||||
769 | { | - | ||||||||||||||||||||||||
770 | return uis->type; executed 9 times by 1 test: return uis->type; Executed by:
| 9 | ||||||||||||||||||||||||
771 | } | - | ||||||||||||||||||||||||
772 | - | |||||||||||||||||||||||||
773 | int UI_get_input_flags(UI_STRING *uis) | - | ||||||||||||||||||||||||
774 | { | - | ||||||||||||||||||||||||
775 | return uis->input_flags; executed 8 times by 1 test: return uis->input_flags; Executed by:
| 8 | ||||||||||||||||||||||||
776 | } | - | ||||||||||||||||||||||||
777 | - | |||||||||||||||||||||||||
778 | const char *UI_get0_output_string(UI_STRING *uis) | - | ||||||||||||||||||||||||
779 | { | - | ||||||||||||||||||||||||
780 | return uis->out_string; never executed: return uis->out_string; | 0 | ||||||||||||||||||||||||
781 | } | - | ||||||||||||||||||||||||
782 | - | |||||||||||||||||||||||||
783 | const char *UI_get0_action_string(UI_STRING *uis) | - | ||||||||||||||||||||||||
784 | { | - | ||||||||||||||||||||||||
785 | switch (uis->type) { | - | ||||||||||||||||||||||||
786 | case UIT_BOOLEAN: never executed: case UIT_BOOLEAN: | 0 | ||||||||||||||||||||||||
787 | return uis->_.boolean_data.action_desc; never executed: return uis->_.boolean_data.action_desc; | 0 | ||||||||||||||||||||||||
788 | case UIT_PROMPT: never executed: case UIT_PROMPT: | 0 | ||||||||||||||||||||||||
789 | case UIT_NONE: never executed: case UIT_NONE: | 0 | ||||||||||||||||||||||||
790 | case UIT_VERIFY: never executed: case UIT_VERIFY: | 0 | ||||||||||||||||||||||||
791 | case UIT_INFO: never executed: case UIT_INFO: | 0 | ||||||||||||||||||||||||
792 | case UIT_ERROR: never executed: case UIT_ERROR: | 0 | ||||||||||||||||||||||||
793 | break; never executed: break; | 0 | ||||||||||||||||||||||||
794 | } | - | ||||||||||||||||||||||||
795 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
796 | } | - | ||||||||||||||||||||||||
797 | - | |||||||||||||||||||||||||
798 | const char *UI_get0_result_string(UI_STRING *uis) | - | ||||||||||||||||||||||||
799 | { | - | ||||||||||||||||||||||||
800 | switch (uis->type) { | - | ||||||||||||||||||||||||
801 | case UIT_PROMPT: never executed: case UIT_PROMPT: | 0 | ||||||||||||||||||||||||
802 | case UIT_VERIFY: never executed: case UIT_VERIFY: | 0 | ||||||||||||||||||||||||
803 | return uis->result_buf; never executed: return uis->result_buf; | 0 | ||||||||||||||||||||||||
804 | case UIT_NONE: never executed: case UIT_NONE: | 0 | ||||||||||||||||||||||||
805 | case UIT_BOOLEAN: never executed: case UIT_BOOLEAN: | 0 | ||||||||||||||||||||||||
806 | case UIT_INFO: never executed: case UIT_INFO: | 0 | ||||||||||||||||||||||||
807 | case UIT_ERROR: never executed: case UIT_ERROR: | 0 | ||||||||||||||||||||||||
808 | break; never executed: break; | 0 | ||||||||||||||||||||||||
809 | } | - | ||||||||||||||||||||||||
810 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
811 | } | - | ||||||||||||||||||||||||
812 | - | |||||||||||||||||||||||||
813 | int UI_get_result_string_length(UI_STRING *uis) | - | ||||||||||||||||||||||||
814 | { | - | ||||||||||||||||||||||||
815 | switch (uis->type) { | - | ||||||||||||||||||||||||
816 | case UIT_PROMPT: never executed: case UIT_PROMPT: | 0 | ||||||||||||||||||||||||
817 | case UIT_VERIFY: never executed: case UIT_VERIFY: | 0 | ||||||||||||||||||||||||
818 | return uis->result_len; never executed: return uis->result_len; | 0 | ||||||||||||||||||||||||
819 | case UIT_NONE: never executed: case UIT_NONE: | 0 | ||||||||||||||||||||||||
820 | case UIT_BOOLEAN: never executed: case UIT_BOOLEAN: | 0 | ||||||||||||||||||||||||
821 | case UIT_INFO: never executed: case UIT_INFO: | 0 | ||||||||||||||||||||||||
822 | case UIT_ERROR: never executed: case UIT_ERROR: | 0 | ||||||||||||||||||||||||
823 | break; never executed: break; | 0 | ||||||||||||||||||||||||
824 | } | - | ||||||||||||||||||||||||
825 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
826 | } | - | ||||||||||||||||||||||||
827 | - | |||||||||||||||||||||||||
828 | const char *UI_get0_test_string(UI_STRING *uis) | - | ||||||||||||||||||||||||
829 | { | - | ||||||||||||||||||||||||
830 | switch (uis->type) { | - | ||||||||||||||||||||||||
831 | case UIT_VERIFY: never executed: case UIT_VERIFY: | 0 | ||||||||||||||||||||||||
832 | return uis->_.string_data.test_buf; never executed: return uis->_.string_data.test_buf; | 0 | ||||||||||||||||||||||||
833 | case UIT_NONE: never executed: case UIT_NONE: | 0 | ||||||||||||||||||||||||
834 | case UIT_BOOLEAN: never executed: case UIT_BOOLEAN: | 0 | ||||||||||||||||||||||||
835 | case UIT_INFO: never executed: case UIT_INFO: | 0 | ||||||||||||||||||||||||
836 | case UIT_ERROR: never executed: case UIT_ERROR: | 0 | ||||||||||||||||||||||||
837 | case UIT_PROMPT: never executed: case UIT_PROMPT: | 0 | ||||||||||||||||||||||||
838 | break; never executed: break; | 0 | ||||||||||||||||||||||||
839 | } | - | ||||||||||||||||||||||||
840 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
841 | } | - | ||||||||||||||||||||||||
842 | - | |||||||||||||||||||||||||
843 | int UI_get_result_minsize(UI_STRING *uis) | - | ||||||||||||||||||||||||
844 | { | - | ||||||||||||||||||||||||
845 | switch (uis->type) { | - | ||||||||||||||||||||||||
846 | case UIT_PROMPT: never executed: case UIT_PROMPT: | 0 | ||||||||||||||||||||||||
847 | case UIT_VERIFY: never executed: case UIT_VERIFY: | 0 | ||||||||||||||||||||||||
848 | return uis->_.string_data.result_minsize; never executed: return uis->_.string_data.result_minsize; | 0 | ||||||||||||||||||||||||
849 | case UIT_NONE: never executed: case UIT_NONE: | 0 | ||||||||||||||||||||||||
850 | case UIT_INFO: never executed: case UIT_INFO: | 0 | ||||||||||||||||||||||||
851 | case UIT_ERROR: never executed: case UIT_ERROR: | 0 | ||||||||||||||||||||||||
852 | case UIT_BOOLEAN: never executed: case UIT_BOOLEAN: | 0 | ||||||||||||||||||||||||
853 | break; never executed: break; | 0 | ||||||||||||||||||||||||
854 | } | - | ||||||||||||||||||||||||
855 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
856 | } | - | ||||||||||||||||||||||||
857 | - | |||||||||||||||||||||||||
858 | int UI_get_result_maxsize(UI_STRING *uis) | - | ||||||||||||||||||||||||
859 | { | - | ||||||||||||||||||||||||
860 | switch (uis->type) { | - | ||||||||||||||||||||||||
861 | case UIT_PROMPT: executed 1 time by 1 test: case UIT_PROMPT: Executed by:
| 1 | ||||||||||||||||||||||||
862 | case UIT_VERIFY: never executed: case UIT_VERIFY: | 0 | ||||||||||||||||||||||||
863 | return uis->_.string_data.result_maxsize; executed 1 time by 1 test: return uis->_.string_data.result_maxsize; Executed by:
| 1 | ||||||||||||||||||||||||
864 | case UIT_NONE: never executed: case UIT_NONE: | 0 | ||||||||||||||||||||||||
865 | case UIT_INFO: never executed: case UIT_INFO: | 0 | ||||||||||||||||||||||||
866 | case UIT_ERROR: never executed: case UIT_ERROR: | 0 | ||||||||||||||||||||||||
867 | case UIT_BOOLEAN: never executed: case UIT_BOOLEAN: | 0 | ||||||||||||||||||||||||
868 | break; never executed: break; | 0 | ||||||||||||||||||||||||
869 | } | - | ||||||||||||||||||||||||
870 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
871 | } | - | ||||||||||||||||||||||||
872 | - | |||||||||||||||||||||||||
873 | int UI_set_result(UI *ui, UI_STRING *uis, const char *result) | - | ||||||||||||||||||||||||
874 | { | - | ||||||||||||||||||||||||
875 | #if 0 | - | ||||||||||||||||||||||||
876 | /* | - | ||||||||||||||||||||||||
877 | * This is placed here solely to preserve UI_F_UI_SET_RESULT | - | ||||||||||||||||||||||||
878 | * To be removed for OpenSSL 1.2.0 | - | ||||||||||||||||||||||||
879 | */ | - | ||||||||||||||||||||||||
880 | UIerr(UI_F_UI_SET_RESULT, ERR_R_DISABLED); | - | ||||||||||||||||||||||||
881 | #endif | - | ||||||||||||||||||||||||
882 | return UI_set_result_ex(ui, uis, result, strlen(result)); executed 4 times by 1 test: return UI_set_result_ex(ui, uis, result, strlen(result)); Executed by:
| 4 | ||||||||||||||||||||||||
883 | } | - | ||||||||||||||||||||||||
884 | - | |||||||||||||||||||||||||
885 | int UI_set_result_ex(UI *ui, UI_STRING *uis, const char *result, int len) | - | ||||||||||||||||||||||||
886 | { | - | ||||||||||||||||||||||||
887 | ui->flags &= ~UI_FLAG_REDOABLE; | - | ||||||||||||||||||||||||
888 | - | |||||||||||||||||||||||||
889 | switch (uis->type) { | - | ||||||||||||||||||||||||
890 | case UIT_PROMPT: executed 5 times by 1 test: case UIT_PROMPT: Executed by:
| 5 | ||||||||||||||||||||||||
891 | case UIT_VERIFY: never executed: case UIT_VERIFY: | 0 | ||||||||||||||||||||||||
892 | { | - | ||||||||||||||||||||||||
893 | char number1[DECIMAL_SIZE(uis->_.string_data.result_minsize) + 1]; | - | ||||||||||||||||||||||||
894 | char number2[DECIMAL_SIZE(uis->_.string_data.result_maxsize) + 1]; | - | ||||||||||||||||||||||||
895 | - | |||||||||||||||||||||||||
896 | BIO_snprintf(number1, sizeof(number1), "%d", | - | ||||||||||||||||||||||||
897 | uis->_.string_data.result_minsize); | - | ||||||||||||||||||||||||
898 | BIO_snprintf(number2, sizeof(number2), "%d", | - | ||||||||||||||||||||||||
899 | uis->_.string_data.result_maxsize); | - | ||||||||||||||||||||||||
900 | - | |||||||||||||||||||||||||
901 | if (len < uis->_.string_data.result_minsize) {
| 0-5 | ||||||||||||||||||||||||
902 | ui->flags |= UI_FLAG_REDOABLE; | - | ||||||||||||||||||||||||
903 | UIerr(UI_F_UI_SET_RESULT_EX, UI_R_RESULT_TOO_SMALL); | - | ||||||||||||||||||||||||
904 | ERR_add_error_data(5, "You must type in ", | - | ||||||||||||||||||||||||
905 | number1, " to ", number2, " characters"); | - | ||||||||||||||||||||||||
906 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
907 | } | - | ||||||||||||||||||||||||
908 | if (len > uis->_.string_data.result_maxsize) {
| 0-5 | ||||||||||||||||||||||||
909 | ui->flags |= UI_FLAG_REDOABLE; | - | ||||||||||||||||||||||||
910 | UIerr(UI_F_UI_SET_RESULT_EX, UI_R_RESULT_TOO_LARGE); | - | ||||||||||||||||||||||||
911 | ERR_add_error_data(5, "You must type in ", | - | ||||||||||||||||||||||||
912 | number1, " to ", number2, " characters"); | - | ||||||||||||||||||||||||
913 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
914 | } | - | ||||||||||||||||||||||||
915 | } | - | ||||||||||||||||||||||||
916 | - | |||||||||||||||||||||||||
917 | if (uis->result_buf == NULL) {
| 0-5 | ||||||||||||||||||||||||
918 | UIerr(UI_F_UI_SET_RESULT_EX, UI_R_NO_RESULT_BUFFER); | - | ||||||||||||||||||||||||
919 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
920 | } | - | ||||||||||||||||||||||||
921 | - | |||||||||||||||||||||||||
922 | memcpy(uis->result_buf, result, len); | - | ||||||||||||||||||||||||
923 | if (len <= uis->_.string_data.result_maxsize)
| 0-5 | ||||||||||||||||||||||||
924 | uis->result_buf[len] = '\0'; executed 5 times by 1 test: uis->result_buf[len] = '\0'; Executed by:
| 5 | ||||||||||||||||||||||||
925 | uis->result_len = len; | - | ||||||||||||||||||||||||
926 | break; executed 5 times by 1 test: break; Executed by:
| 5 | ||||||||||||||||||||||||
927 | case UIT_BOOLEAN: never executed: case UIT_BOOLEAN: | 0 | ||||||||||||||||||||||||
928 | { | - | ||||||||||||||||||||||||
929 | const char *p; | - | ||||||||||||||||||||||||
930 | - | |||||||||||||||||||||||||
931 | if (uis->result_buf == NULL) {
| 0 | ||||||||||||||||||||||||
932 | UIerr(UI_F_UI_SET_RESULT_EX, UI_R_NO_RESULT_BUFFER); | - | ||||||||||||||||||||||||
933 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
934 | } | - | ||||||||||||||||||||||||
935 | - | |||||||||||||||||||||||||
936 | uis->result_buf[0] = '\0'; | - | ||||||||||||||||||||||||
937 | for (p = result; *p; p++) {
| 0 | ||||||||||||||||||||||||
938 | if (strchr(uis->_.boolean_data.ok_chars, *p)) {
| 0 | ||||||||||||||||||||||||
939 | uis->result_buf[0] = uis->_.boolean_data.ok_chars[0]; | - | ||||||||||||||||||||||||
940 | break; never executed: break; | 0 | ||||||||||||||||||||||||
941 | } | - | ||||||||||||||||||||||||
942 | if (strchr(uis->_.boolean_data.cancel_chars, *p)) {
| 0 | ||||||||||||||||||||||||
943 | uis->result_buf[0] = uis->_.boolean_data.cancel_chars[0]; | - | ||||||||||||||||||||||||
944 | break; never executed: break; | 0 | ||||||||||||||||||||||||
945 | } | - | ||||||||||||||||||||||||
946 | } never executed: end of block | 0 | ||||||||||||||||||||||||
947 | } | - | ||||||||||||||||||||||||
948 | case UIT_NONE: code before this statement never executed: case UIT_NONE: never executed: case UIT_NONE: | 0 | ||||||||||||||||||||||||
949 | case UIT_INFO: never executed: case UIT_INFO: | 0 | ||||||||||||||||||||||||
950 | case UIT_ERROR: never executed: case UIT_ERROR: | 0 | ||||||||||||||||||||||||
951 | break; never executed: break; | 0 | ||||||||||||||||||||||||
952 | } | - | ||||||||||||||||||||||||
953 | return 0; executed 5 times by 1 test: return 0; Executed by:
| 5 | ||||||||||||||||||||||||
954 | } | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |