OpenCoverage

ui_util.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/ui/ui_util.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 2002-2016 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/thread_once.h"-
12#include "ui_locl.h"-
13-
14#ifndef BUFSIZ-
15#define BUFSIZ 256-
16#endif-
17-
18int UI_UTIL_read_pw_string(char *buf, int length, const char *prompt,-
19 int verify)-
20{-
21 char buff[BUFSIZ];-
22 int ret;-
23-
24 ret =-
25 UI_UTIL_read_pw(buf, buff, (length > BUFSIZ) ? BUFSIZ : length,-
26 prompt, verify);-
27 OPENSSL_cleanse(buff, BUFSIZ);-
28 return ret;
never executed: return ret;
0
29}-
30-
31int UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt,-
32 int verify)-
33{-
34 int ok = 0;-
35 UI *ui;-
36-
37 if (size < 1)
size < 1Description
TRUEnever evaluated
FALSEnever evaluated
0
38 return -1;
never executed: return -1;
0
39-
40 ui = UI_new();-
41 if (ui != NULL) {
ui != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
42 ok = UI_add_input_string(ui, prompt, 0, buf, 0, size - 1);-
43 if (ok >= 0 && verify)
ok >= 0Description
TRUEnever evaluated
FALSEnever evaluated
verifyDescription
TRUEnever evaluated
FALSEnever evaluated
0
44 ok = UI_add_verify_string(ui, prompt, 0, buff, 0, size - 1, buf);
never executed: ok = UI_add_verify_string(ui, prompt, 0, buff, 0, size - 1, buf);
0
45 if (ok >= 0)
ok >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
46 ok = UI_process(ui);
never executed: ok = UI_process(ui);
0
47 UI_free(ui);-
48 }
never executed: end of block
0
49 if (ok > 0)
ok > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
50 ok = 0;
never executed: ok = 0;
0
51 return ok;
never executed: return ok;
0
52}-
53-
54/*-
55 * Wrapper around pem_password_cb, a method to help older APIs use newer-
56 * ones.-
57 */-
58struct pem_password_cb_data {-
59 pem_password_cb *cb;-
60 int rwflag;-
61};-
62-
63static void ui_new_method_data(void *parent, void *ptr, CRYPTO_EX_DATA *ad,-
64 int idx, long argl, void *argp)-
65{-
66 /*-
67 * Do nothing, the data is allocated externally and assigned later with-
68 * CRYPTO_set_ex_data()-
69 */-
70}-
71-
72static int ui_dup_method_data(CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from,-
73 void *from_d, int idx, long argl, void *argp)-
74{-
75 void **pptr = (void **)from_d;-
76 if (*pptr != NULL)
*pptr != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
77 *pptr = OPENSSL_memdup(*pptr, sizeof(struct pem_password_cb_data));
never executed: *pptr = CRYPTO_memdup((*pptr), sizeof(struct pem_password_cb_data), __FILE__, 77);
0
78 return 1;
never executed: return 1;
0
79}-
80-
81static void ui_free_method_data(void *parent, void *ptr, CRYPTO_EX_DATA *ad,-
82 int idx, long argl, void *argp)-
83{-
84 OPENSSL_free(ptr);-
85}
executed 2 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2
86-
87static CRYPTO_ONCE get_index_once = CRYPTO_ONCE_STATIC_INIT;-
88static int ui_method_data_index = -1;-
89DEFINE_RUN_ONCE_STATIC(ui_method_data_index_init)
executed 1 time by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1
90{-
91 ui_method_data_index = CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_UI_METHOD,-
92 0, NULL, ui_new_method_data,-
93 ui_dup_method_data,-
94 ui_free_method_data);-
95 return 1;
executed 1 time by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1
96}-
97-
98static int ui_open(UI *ui)-
99{-
100 return 1;
executed 1 time by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1
101}-
102static int ui_read(UI *ui, UI_STRING *uis)-
103{-
104 switch (UI_get_string_type(uis)) {-
105 case UIT_PROMPT:
executed 1 time by 1 test: case UIT_PROMPT:
Executed by:
  • libcrypto.so.1.1
1
106 {-
107 char result[PEM_BUFSIZE + 1];-
108 const struct pem_password_cb_data *data =-
109 UI_method_get_ex_data(UI_get_method(ui), ui_method_data_index);-
110 int maxsize = UI_get_result_maxsize(uis);-
111 int len = data->cb(result,-
112 maxsize > PEM_BUFSIZE ? PEM_BUFSIZE : maxsize,-
113 data->rwflag, UI_get0_user_data(ui));-
114-
115 if (len >= 0)
len >= 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-1
116 result[len] = '\0';
executed 1 time by 1 test: result[len] = '\0';
Executed by:
  • libcrypto.so.1.1
1
117 if (len <= 0)
len <= 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
118 return len;
never executed: return len;
0
119 if (UI_set_result_ex(ui, uis, result, len) >= 0)
UI_set_result_...ult, len) >= 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-1
120 return 1;
executed 1 time by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1
121 return 0;
never executed: return 0;
0
122 }-
123 case UIT_VERIFY:
never executed: case UIT_VERIFY:
0
124 case UIT_NONE:
never executed: case UIT_NONE:
0
125 case UIT_BOOLEAN:
never executed: case UIT_BOOLEAN:
0
126 case UIT_INFO:
never executed: case UIT_INFO:
0
127 case UIT_ERROR:
never executed: case UIT_ERROR:
0
128 break;
never executed: break;
0
129 }-
130 return 1;
never executed: return 1;
0
131}-
132static int ui_write(UI *ui, UI_STRING *uis)-
133{-
134 return 1;
executed 1 time by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1
135}-
136static int ui_close(UI *ui)-
137{-
138 return 1;
executed 1 time by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1
139}-
140-
141UI_METHOD *UI_UTIL_wrap_read_pem_callback(pem_password_cb *cb, int rwflag)-
142{-
143 struct pem_password_cb_data *data = NULL;-
144 UI_METHOD *ui_method = NULL;-
145-
146 if ((data = OPENSSL_zalloc(sizeof(*data))) == NULL
(data = CRYPTO...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
147 || (ui_method = UI_create_method("PEM password callback wrapper")) == NULL
(ui_method = U...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
148 || UI_method_set_opener(ui_method, ui_open) < 0
UI_method_set_..., ui_open) < 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
149 || UI_method_set_reader(ui_method, ui_read) < 0
UI_method_set_..., ui_read) < 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
150 || UI_method_set_writer(ui_method, ui_write) < 0
UI_method_set_... ui_write) < 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
151 || UI_method_set_closer(ui_method, ui_close) < 0
UI_method_set_... ui_close) < 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
152 || !RUN_ONCE(&get_index_once, ui_method_data_index_init)
CRYPTO_THREAD_...ex_init_ossl_)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
!(CRYPTO_THREA...ossl_ret_ : 0)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
153 || UI_method_set_ex_data(ui_method, ui_method_data_index, data) < 0) {
UI_method_set_...dex, data) < 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
154 UI_destroy_method(ui_method);-
155 OPENSSL_free(data);-
156 return NULL;
never executed: return ((void *)0) ;
0
157 }-
158 data->rwflag = rwflag;-
159 data->cb = cb;-
160-
161 return ui_method;
executed 1 time by 1 test: return ui_method;
Executed by:
  • libcrypto.so.1.1
1
162}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2