OpenCoverage

f_int.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/asn1/f_int.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 1995-2017 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 <stdio.h>-
11#include "internal/ctype.h"-
12#include "internal/cryptlib.h"-
13#include <openssl/buffer.h>-
14#include <openssl/asn1.h>-
15-
16int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a)-
17{-
18 int i, n = 0;-
19 static const char *h = "0123456789ABCDEF";-
20 char buf[2];-
21-
22 if (a == NULL)
a == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 8492 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-8492
23 return 0;
never executed: return 0;
0
24-
25 if (a->type & V_ASN1_NEG) {
a->type & 0x100Description
TRUEevaluated 1125 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 7367 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1125-7367
26 if (BIO_write(bp, "-", 1) != 1)
BIO_write(bp, "-", 1) != 1Description
TRUEnever evaluated
FALSEevaluated 1125 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1125
27 goto err;
never executed: goto err;
0
28 n = 1;-
29 }
executed 1125 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1125
30-
31 if (a->length == 0) {
a->length == 0Description
TRUEnever evaluated
FALSEevaluated 8492 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-8492
32 if (BIO_write(bp, "00", 2) != 2)
BIO_write(bp, "00", 2) != 2Description
TRUEnever evaluated
FALSEnever evaluated
0
33 goto err;
never executed: goto err;
0
34 n += 2;-
35 } else {
never executed: end of block
0
36 for (i = 0; i < a->length; i++) {
i < a->lengthDescription
TRUEevaluated 35784 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 8492 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
8492-35784
37 if ((i != 0) && (i % 35 == 0)) {
(i != 0)Description
TRUEevaluated 27292 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 8492 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(i % 35 == 0)Description
TRUEevaluated 213 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 27079 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
213-27292
38 if (BIO_write(bp, "\\\n", 2) != 2)
BIO_write(bp, "\\\n", 2) != 2Description
TRUEnever evaluated
FALSEevaluated 213 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-213
39 goto err;
never executed: goto err;
0
40 n += 2;-
41 }
executed 213 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
213
42 buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f];-
43 buf[1] = h[((unsigned char)a->data[i]) & 0x0f];-
44 if (BIO_write(bp, buf, 2) != 2)
BIO_write(bp, buf, 2) != 2Description
TRUEnever evaluated
FALSEevaluated 35784 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-35784
45 goto err;
never executed: goto err;
0
46 n += 2;-
47 }
executed 35784 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
35784
48 }
executed 8492 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
8492
49 return n;
executed 8492 times by 1 test: return n;
Executed by:
  • libcrypto.so.1.1
8492
50 err:-
51 return -1;
never executed: return -1;
0
52}-
53-
54int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)-
55{-
56 int i, j, k, m, n, again, bufsize;-
57 unsigned char *s = NULL, *sp;-
58 unsigned char *bufp;-
59 int num = 0, slen = 0, first = 1;-
60-
61 bs->type = V_ASN1_INTEGER;-
62-
63 bufsize = BIO_gets(bp, buf, size);-
64 for (;;) {-
65 if (bufsize < 1)
bufsize < 1Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
66 goto err;
never executed: goto err;
0
67 i = bufsize;-
68 if (buf[i - 1] == '\n')
buf[i - 1] == '\n'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-2
69 buf[--i] = '\0';
executed 2 times by 1 test: buf[--i] = '\0';
Executed by:
  • libcrypto.so.1.1
2
70 if (i == 0)
i == 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
71 goto err;
never executed: goto err;
0
72 if (buf[i - 1] == '\r')
buf[i - 1] == '\r'Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
73 buf[--i] = '\0';
never executed: buf[--i] = '\0';
0
74 if (i == 0)
i == 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
75 goto err;
never executed: goto err;
0
76 again = (buf[i - 1] == '\\');-
77-
78 for (j = 0; j < i; j++) {
j < iDescription
TRUEevaluated 80 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2-80
79 if (!ossl_isxdigit(buf[j]))
!(ossl_ctype_c...uf[j]), 0x10))Description
TRUEnever evaluated
FALSEevaluated 80 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-80
80 {-
81 i = j;-
82 break;
never executed: break;
0
83 }-
84 }
executed 80 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
80
85 buf[i] = '\0';-
86 /*-
87 * We have now cleared all the crap off the end of the line-
88 */-
89 if (i < 2)
i < 2Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
90 goto err;
never executed: goto err;
0
91-
92 bufp = (unsigned char *)buf;-
93 if (first) {
firstDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-2
94 first = 0;-
95 if ((bufp[0] == '0') && (bufp[1] == '0')) {
(bufp[0] == '0')Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
(bufp[1] == '0')Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
96 bufp += 2;-
97 i -= 2;-
98 }
never executed: end of block
0
99 }
executed 2 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2
100 k = 0;-
101 i -= again;-
102 if (i % 2 != 0) {
i % 2 != 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
103 ASN1err(ASN1_F_A2I_ASN1_INTEGER, ASN1_R_ODD_NUMBER_OF_CHARS);-
104 OPENSSL_free(s);-
105 return 0;
never executed: return 0;
0
106 }-
107 i /= 2;-
108 if (num + i > slen) {
num + i > slenDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-2
109 sp = OPENSSL_clear_realloc(s, slen, num + i * 2);-
110 if (sp == NULL) {
sp == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
111 ASN1err(ASN1_F_A2I_ASN1_INTEGER, ERR_R_MALLOC_FAILURE);-
112 OPENSSL_free(s);-
113 return 0;
never executed: return 0;
0
114 }-
115 s = sp;-
116 slen = num + i * 2;-
117 }
executed 2 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2
118 for (j = 0; j < i; j++, k += 2) {
j < iDescription
TRUEevaluated 40 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2-40
119 for (n = 0; n < 2; n++) {
n < 2Description
TRUEevaluated 80 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 40 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
40-80
120 m = OPENSSL_hexchar2int(bufp[k + n]);-
121 if (m < 0) {
m < 0Description
TRUEnever evaluated
FALSEevaluated 80 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-80
122 ASN1err(ASN1_F_A2I_ASN1_INTEGER,-
123 ASN1_R_NON_HEX_CHARACTERS);-
124 goto err;
never executed: goto err;
0
125 }-
126 s[num + j] <<= 4;-
127 s[num + j] |= m;-
128 }
executed 80 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
80
129 }
executed 40 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
40
130 num += i;-
131 if (again)
againDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
132 bufsize = BIO_gets(bp, buf, size);
never executed: bufsize = BIO_gets(bp, buf, size);
0
133 else-
134 break;
executed 2 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
2
135 }-
136 bs->length = num;-
137 bs->data = s;-
138 return 1;
executed 2 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
2
139 err:-
140 ASN1err(ASN1_F_A2I_ASN1_INTEGER, ASN1_R_SHORT_LINE);-
141 OPENSSL_free(s);-
142 return 0;
never executed: return 0;
0
143}-
144-
145int i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a)-
146{-
147 return i2a_ASN1_INTEGER(bp, a);
never executed: return i2a_ASN1_INTEGER(bp, a);
0
148}-
149-
150int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size)-
151{-
152 int rv = a2i_ASN1_INTEGER(bp, bs, buf, size);-
153 if (rv == 1)
rv == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
154 bs->type = V_ASN1_INTEGER | (bs->type & V_ASN1_NEG);
never executed: bs->type = 2 | (bs->type & 0x100);
0
155 return rv;
never executed: return rv;
0
156}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2