/src/openssl30/crypto/bio/bio_print.c
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | /* | 
| 2 |  |  * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved. | 
| 3 |  |  * | 
| 4 |  |  * Licensed under the Apache License 2.0 (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 <string.h> | 
| 12 |  | #include "internal/cryptlib.h" | 
| 13 |  | #include "crypto/ctype.h" | 
| 14 |  | #include "internal/numbers.h" | 
| 15 |  | #include <openssl/bio.h> | 
| 16 |  | #include <openssl/configuration.h> | 
| 17 |  |  | 
| 18 |  | /* | 
| 19 |  |  * Copyright Patrick Powell 1995 | 
| 20 |  |  * This code is based on code written by Patrick Powell <papowell@astart.com> | 
| 21 |  |  * It may be used for any purpose as long as this notice remains intact | 
| 22 |  |  * on all source code distributions. | 
| 23 |  |  */ | 
| 24 |  |  | 
| 25 |  | #ifdef HAVE_LONG_DOUBLE | 
| 26 |  | # define LDOUBLE long double | 
| 27 |  | #else | 
| 28 | 297M | # define LDOUBLE double | 
| 29 |  | #endif | 
| 30 |  |  | 
| 31 |  | static int fmtstr(char **, char **, size_t *, size_t *, | 
| 32 |  |                   const char *, int, int, int); | 
| 33 |  | static int fmtint(char **, char **, size_t *, size_t *, | 
| 34 |  |                   int64_t, int, int, int, int); | 
| 35 |  | #ifndef OPENSSL_SYS_UEFI | 
| 36 |  | static int fmtfp(char **, char **, size_t *, size_t *, | 
| 37 |  |                  LDOUBLE, int, int, int, int); | 
| 38 |  | #endif | 
| 39 |  | static int doapr_outch(char **, char **, size_t *, size_t *, int); | 
| 40 |  | static int _dopr(char **sbuffer, char **buffer, | 
| 41 |  |                  size_t *maxlen, size_t *retlen, int *truncated, | 
| 42 |  |                  const char *format, va_list args); | 
| 43 |  |  | 
| 44 |  | /* format read states */ | 
| 45 | 1.63G | #define DP_S_DEFAULT    0 | 
| 46 | 1.32G | #define DP_S_FLAGS      1 | 
| 47 | 1.36G | #define DP_S_MIN        2 | 
| 48 | 1.07G | #define DP_S_DOT        3 | 
| 49 | 179k | #define DP_S_MAX        4 | 
| 50 | 1.07G | #define DP_S_MOD        5 | 
| 51 | 1.07G | #define DP_S_CONV       6 | 
| 52 | 5.20G | #define DP_S_DONE       7 | 
| 53 |  |  | 
| 54 |  | /* format flags - Bits */ | 
| 55 |  | /* left-aligned padding */ | 
| 56 | 438M | #define DP_F_MINUS      (1 << 0) | 
| 57 |  | /* print an explicit '+' for a value with positive sign */ | 
| 58 | 58.7M | #define DP_F_PLUS       (1 << 1) | 
| 59 |  | /* print an explicit ' ' for a value with positive sign */ | 
| 60 | 58.7M | #define DP_F_SPACE      (1 << 2) | 
| 61 |  | /* print 0/0x prefix for octal/hex and decimal point for floating point */ | 
| 62 | 281M | #define DP_F_NUM        (1 << 3) | 
| 63 |  | /* print leading zeroes */ | 
| 64 | 498M | #define DP_F_ZERO       (1 << 4) | 
| 65 |  | /* print HEX in UPPPERcase */ | 
| 66 | 360M | #define DP_F_UP         (1 << 5) | 
| 67 |  | /* treat value as unsigned */ | 
| 68 | 503M | #define DP_F_UNSIGNED   (1 << 6) | 
| 69 |  |  | 
| 70 |  | /* conversion flags */ | 
| 71 | 0 | #define DP_C_SHORT      1 | 
| 72 | 96.7M | #define DP_C_LONG       2 | 
| 73 | 0 | #define DP_C_LDOUBLE    3 | 
| 74 | 7.26k | #define DP_C_LLONG      4 | 
| 75 | 0 | #define DP_C_SIZE       5 | 
| 76 |  |  | 
| 77 |  | /* Floating point formats */ | 
| 78 | 0 | #define F_FORMAT        0 | 
| 79 | 0 | #define E_FORMAT        1 | 
| 80 | 0 | #define G_FORMAT        2 | 
| 81 |  |  | 
| 82 |  | /* some handy macros */ | 
| 83 | 288M | #define char_to_int(p) (p - '0') | 
| 84 | 498M | #define OSSL_MAX(p,q) ((p >= q) ? p : q) | 
| 85 |  |  | 
| 86 |  | static int | 
| 87 |  | _dopr(char **sbuffer, | 
| 88 |  |       char **buffer, | 
| 89 |  |       size_t *maxlen, | 
| 90 |  |       size_t *retlen, int *truncated, const char *format, va_list args) | 
| 91 | 297M | { | 
| 92 | 297M |     char ch; | 
| 93 | 297M |     int64_t value; | 
| 94 | 297M | #ifndef OPENSSL_SYS_UEFI | 
| 95 | 297M |     LDOUBLE fvalue; | 
| 96 | 297M | #endif | 
| 97 | 297M |     char *strvalue; | 
| 98 | 297M |     int min; | 
| 99 | 297M |     int max; | 
| 100 | 297M |     int state; | 
| 101 | 297M |     int flags; | 
| 102 | 297M |     int cflags; | 
| 103 | 297M |     size_t currlen; | 
| 104 |  |  | 
| 105 | 297M |     state = DP_S_DEFAULT; | 
| 106 | 297M |     flags = currlen = cflags = min = 0; | 
| 107 | 297M |     max = -1; | 
| 108 | 297M |     ch = *format++; | 
| 109 |  |  | 
| 110 | 4.61G |     while (state != DP_S_DONE) { | 
| 111 | 4.31G |         if (ch == '\0' || (buffer == NULL && currlen >= *maxlen)) | 
| 112 | 297M |             state = DP_S_DONE; | 
| 113 |  |  | 
| 114 | 4.31G |         switch (state) { | 
| 115 | 798M |         case DP_S_DEFAULT: | 
| 116 | 798M |             if (ch == '%') | 
| 117 | 537M |                 state = DP_S_FLAGS; | 
| 118 | 261M |             else | 
| 119 | 261M |                 if (!doapr_outch(sbuffer, buffer, &currlen, maxlen, ch)) | 
| 120 | 0 |                     return 0; | 
| 121 | 798M |             ch = *format++; | 
| 122 | 798M |             break; | 
| 123 | 783M |         case DP_S_FLAGS: | 
| 124 | 783M |             switch (ch) { | 
| 125 | 29.4M |             case '-': | 
| 126 | 29.4M |                 flags |= DP_F_MINUS; | 
| 127 | 29.4M |                 ch = *format++; | 
| 128 | 29.4M |                 break; | 
| 129 | 0 |             case '+': | 
| 130 | 0 |                 flags |= DP_F_PLUS; | 
| 131 | 0 |                 ch = *format++; | 
| 132 | 0 |                 break; | 
| 133 | 0 |             case ' ': | 
| 134 | 0 |                 flags |= DP_F_SPACE; | 
| 135 | 0 |                 ch = *format++; | 
| 136 | 0 |                 break; | 
| 137 | 0 |             case '#': | 
| 138 | 0 |                 flags |= DP_F_NUM; | 
| 139 | 0 |                 ch = *format++; | 
| 140 | 0 |                 break; | 
| 141 | 216M |             case '0': | 
| 142 | 216M |                 flags |= DP_F_ZERO; | 
| 143 | 216M |                 ch = *format++; | 
| 144 | 216M |                 break; | 
| 145 | 537M |             default: | 
| 146 | 537M |                 state = DP_S_MIN; | 
| 147 | 537M |                 break; | 
| 148 | 783M |             } | 
| 149 | 783M |             break; | 
| 150 | 825M |         case DP_S_MIN: | 
| 151 | 825M |             if (ossl_isdigit(ch)) { | 
| 152 | 288M |                 min = 10 * min + char_to_int(ch); | 
| 153 | 288M |                 ch = *format++; | 
| 154 | 537M |             } else if (ch == '*') { | 
| 155 | 24.5M |                 min = va_arg(args, int); | 
| 156 | 24.5M |                 ch = *format++; | 
| 157 | 24.5M |                 state = DP_S_DOT; | 
| 158 | 24.5M |             } else | 
| 159 | 512M |                 state = DP_S_DOT; | 
| 160 | 825M |             break; | 
| 161 | 537M |         case DP_S_DOT: | 
| 162 | 537M |             if (ch == '.') { | 
| 163 | 62.0k |                 state = DP_S_MAX; | 
| 164 | 62.0k |                 ch = *format++; | 
| 165 | 62.0k |             } else | 
| 166 | 537M |                 state = DP_S_MOD; | 
| 167 | 537M |             break; | 
| 168 | 117k |         case DP_S_MAX: | 
| 169 | 117k |             if (ossl_isdigit(ch)) { | 
| 170 | 55.4k |                 if (max < 0) | 
| 171 | 27.7k |                     max = 0; | 
| 172 | 55.4k |                 max = 10 * max + char_to_int(ch); | 
| 173 | 55.4k |                 ch = *format++; | 
| 174 | 62.0k |             } else if (ch == '*') { | 
| 175 | 34.3k |                 max = va_arg(args, int); | 
| 176 | 34.3k |                 ch = *format++; | 
| 177 | 34.3k |                 state = DP_S_MOD; | 
| 178 | 34.3k |             } else | 
| 179 | 27.7k |                 state = DP_S_MOD; | 
| 180 | 117k |             break; | 
| 181 | 537M |         case DP_S_MOD: | 
| 182 | 537M |             switch (ch) { | 
| 183 | 0 |             case 'h': | 
| 184 | 0 |                 cflags = DP_C_SHORT; | 
| 185 | 0 |                 ch = *format++; | 
| 186 | 0 |                 break; | 
| 187 | 48.3M |             case 'l': | 
| 188 | 48.3M |                 if (*format == 'l') { | 
| 189 | 1.21k |                     cflags = DP_C_LLONG; | 
| 190 | 1.21k |                     format++; | 
| 191 | 1.21k |                 } else | 
| 192 | 48.3M |                     cflags = DP_C_LONG; | 
| 193 | 48.3M |                 ch = *format++; | 
| 194 | 48.3M |                 break; | 
| 195 | 0 |             case 'q': | 
| 196 | 2.41k |             case 'j': | 
| 197 | 2.41k |                 cflags = DP_C_LLONG; | 
| 198 | 2.41k |                 ch = *format++; | 
| 199 | 2.41k |                 break; | 
| 200 | 0 |             case 'L': | 
| 201 | 0 |                 cflags = DP_C_LDOUBLE; | 
| 202 | 0 |                 ch = *format++; | 
| 203 | 0 |                 break; | 
| 204 | 0 |             case 'z': | 
| 205 | 0 |                 cflags = DP_C_SIZE; | 
| 206 | 0 |                 ch = *format++; | 
| 207 | 0 |                 break; | 
| 208 | 488M |             default: | 
| 209 | 488M |                 break; | 
| 210 | 537M |             } | 
| 211 | 537M |             state = DP_S_CONV; | 
| 212 | 537M |             break; | 
| 213 | 537M |         case DP_S_CONV: | 
| 214 | 537M |             switch (ch) { | 
| 215 | 58.7M |             case 'd': | 
| 216 | 58.7M |             case 'i': | 
| 217 | 58.7M |                 switch (cflags) { | 
| 218 | 0 |                 case DP_C_SHORT: | 
| 219 | 0 |                     value = (short int)va_arg(args, int); | 
| 220 | 0 |                     break; | 
| 221 | 42.2M |                 case DP_C_LONG: | 
| 222 | 42.2M |                     value = va_arg(args, long int); | 
| 223 | 42.2M |                     break; | 
| 224 | 2.64k |                 case DP_C_LLONG: | 
| 225 | 2.64k |                     value = va_arg(args, int64_t); | 
| 226 | 2.64k |                     break; | 
| 227 | 0 |                 case DP_C_SIZE: | 
| 228 | 0 |                     value = va_arg(args, ossl_ssize_t); | 
| 229 | 0 |                     break; | 
| 230 | 16.4M |                 default: | 
| 231 | 16.4M |                     value = va_arg(args, int); | 
| 232 | 16.4M |                     break; | 
| 233 | 58.7M |                 } | 
| 234 | 58.7M |                 if (!fmtint(sbuffer, buffer, &currlen, maxlen, value, 10, min, | 
| 235 | 58.7M |                             max, flags)) | 
| 236 | 0 |                     return 0; | 
| 237 | 58.7M |                 break; | 
| 238 | 78.9M |             case 'X': | 
| 239 | 78.9M |                 flags |= DP_F_UP; | 
| 240 |  |                 /* FALLTHROUGH */ | 
| 241 | 216M |             case 'x': | 
| 242 | 216M |             case 'o': | 
| 243 | 222M |             case 'u': | 
| 244 | 222M |                 flags |= DP_F_UNSIGNED; | 
| 245 | 222M |                 switch (cflags) { | 
| 246 | 0 |                 case DP_C_SHORT: | 
| 247 | 0 |                     value = (unsigned short int)va_arg(args, unsigned int); | 
| 248 | 0 |                     break; | 
| 249 | 6.13M |                 case DP_C_LONG: | 
| 250 | 6.13M |                     value = va_arg(args, unsigned long int); | 
| 251 | 6.13M |                     break; | 
| 252 | 982 |                 case DP_C_LLONG: | 
| 253 | 982 |                     value = va_arg(args, uint64_t); | 
| 254 | 982 |                     break; | 
| 255 | 0 |                 case DP_C_SIZE: | 
| 256 | 0 |                     value = va_arg(args, size_t); | 
| 257 | 0 |                     break; | 
| 258 | 216M |                 default: | 
| 259 | 216M |                     value = va_arg(args, unsigned int); | 
| 260 | 216M |                     break; | 
| 261 | 222M |                 } | 
| 262 | 222M |                 if (!fmtint(sbuffer, buffer, &currlen, maxlen, value, | 
| 263 | 222M |                             ch == 'o' ? 8 : (ch == 'u' ? 10 : 16), | 
| 264 | 222M |                             min, max, flags)) | 
| 265 | 0 |                     return 0; | 
| 266 | 222M |                 break; | 
| 267 | 222M | #ifndef OPENSSL_SYS_UEFI | 
| 268 | 222M |             case 'f': | 
| 269 | 0 |                 if (cflags == DP_C_LDOUBLE) | 
| 270 | 0 |                     fvalue = va_arg(args, LDOUBLE); | 
| 271 | 0 |                 else | 
| 272 | 0 |                     fvalue = va_arg(args, double); | 
| 273 | 0 |                 if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max, | 
| 274 | 0 |                            flags, F_FORMAT)) | 
| 275 | 0 |                     return 0; | 
| 276 | 0 |                 break; | 
| 277 | 0 |             case 'E': | 
| 278 | 0 |                 flags |= DP_F_UP; | 
| 279 |  |                 /* fall thru */ | 
| 280 | 0 |             case 'e': | 
| 281 | 0 |                 if (cflags == DP_C_LDOUBLE) | 
| 282 | 0 |                     fvalue = va_arg(args, LDOUBLE); | 
| 283 | 0 |                 else | 
| 284 | 0 |                     fvalue = va_arg(args, double); | 
| 285 | 0 |                 if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max, | 
| 286 | 0 |                            flags, E_FORMAT)) | 
| 287 | 0 |                     return 0; | 
| 288 | 0 |                 break; | 
| 289 | 0 |             case 'G': | 
| 290 | 0 |                 flags |= DP_F_UP; | 
| 291 |  |                 /* fall thru */ | 
| 292 | 0 |             case 'g': | 
| 293 | 0 |                 if (cflags == DP_C_LDOUBLE) | 
| 294 | 0 |                     fvalue = va_arg(args, LDOUBLE); | 
| 295 | 0 |                 else | 
| 296 | 0 |                     fvalue = va_arg(args, double); | 
| 297 | 0 |                 if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max, | 
| 298 | 0 |                            flags, G_FORMAT)) | 
| 299 | 0 |                     return 0; | 
| 300 | 0 |                 break; | 
| 301 |  | #else | 
| 302 |  |             case 'f': | 
| 303 |  |             case 'E': | 
| 304 |  |             case 'e': | 
| 305 |  |             case 'G': | 
| 306 |  |             case 'g': | 
| 307 |  |                 /* not implemented for UEFI */ | 
| 308 |  |                 ERR_raise(ERR_LIB_BIO, ERR_R_UNSUPPORTED); | 
| 309 |  |                 return 0; | 
| 310 |  | #endif | 
| 311 | 127M |             case 'c': | 
| 312 | 127M |                 if (!doapr_outch(sbuffer, buffer, &currlen, maxlen, | 
| 313 | 127M |                                  va_arg(args, int))) | 
| 314 | 0 |                     return 0; | 
| 315 | 127M |                 break; | 
| 316 | 128M |             case 's': | 
| 317 | 128M |                 strvalue = va_arg(args, char *); | 
| 318 | 128M |                 if (max < 0) { | 
| 319 | 128M |                     if (buffer) | 
| 320 | 104M |                         max = INT_MAX; | 
| 321 | 23.1M |                     else | 
| 322 | 23.1M |                         max = *maxlen; | 
| 323 | 128M |                 } | 
| 324 | 128M |                 if (!fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue, | 
| 325 | 128M |                             flags, min, max)) | 
| 326 | 0 |                     return 0; | 
| 327 | 128M |                 break; | 
| 328 | 128M |             case 'p': | 
| 329 | 0 |                 value = (size_t)va_arg(args, void *); | 
| 330 | 0 |                 if (!fmtint(sbuffer, buffer, &currlen, maxlen, | 
| 331 | 0 |                             value, 16, min, max, flags | DP_F_NUM)) | 
| 332 | 0 |                     return 0; | 
| 333 | 0 |                 break; | 
| 334 | 0 |             case 'n': | 
| 335 | 0 |                 { | 
| 336 | 0 |                     int *num; | 
| 337 | 0 |                     num = va_arg(args, int *); | 
| 338 | 0 |                     *num = currlen; | 
| 339 | 0 |                 } | 
| 340 | 0 |                 break; | 
| 341 | 0 |             case '%': | 
| 342 | 0 |                 if (!doapr_outch(sbuffer, buffer, &currlen, maxlen, ch)) | 
| 343 | 0 |                     return 0; | 
| 344 | 0 |                 break; | 
| 345 | 0 |             case 'w': | 
| 346 |  |                 /* not supported yet, treat as next char */ | 
| 347 | 0 |                 format++; | 
| 348 | 0 |                 break; | 
| 349 | 0 |             default: | 
| 350 |  |                 /* unknown, skip */ | 
| 351 | 0 |                 break; | 
| 352 | 537M |             } | 
| 353 | 537M |             ch = *format++; | 
| 354 | 537M |             state = DP_S_DEFAULT; | 
| 355 | 537M |             flags = cflags = min = 0; | 
| 356 | 537M |             max = -1; | 
| 357 | 537M |             break; | 
| 358 | 297M |         case DP_S_DONE: | 
| 359 | 297M |             break; | 
| 360 | 0 |         default: | 
| 361 | 0 |             break; | 
| 362 | 4.31G |         } | 
| 363 | 4.31G |     } | 
| 364 |  |     /* | 
| 365 |  |      * We have to truncate if there is no dynamic buffer and we have filled the | 
| 366 |  |      * static buffer. | 
| 367 |  |      */ | 
| 368 | 297M |     if (buffer == NULL) { | 
| 369 | 113M |         *truncated = (currlen > *maxlen - 1); | 
| 370 | 113M |         if (*truncated) | 
| 371 | 7.76k |             currlen = *maxlen - 1; | 
| 372 | 113M |     } | 
| 373 | 297M |     if (!doapr_outch(sbuffer, buffer, &currlen, maxlen, '\0')) | 
| 374 | 0 |         return 0; | 
| 375 | 297M |     *retlen = currlen - 1; | 
| 376 | 297M |     return 1; | 
| 377 | 297M | } | 
| 378 |  |  | 
| 379 |  | static int | 
| 380 |  | fmtstr(char **sbuffer, | 
| 381 |  |        char **buffer, | 
| 382 |  |        size_t *currlen, | 
| 383 |  |        size_t *maxlen, const char *value, int flags, int min, int max) | 
| 384 | 128M | { | 
| 385 | 128M |     int padlen; | 
| 386 | 128M |     size_t strln; | 
| 387 | 128M |     int cnt = 0; | 
| 388 |  |  | 
| 389 | 128M |     if (value == 0) | 
| 390 | 17.4k |         value = "<NULL>"; | 
| 391 |  |  | 
| 392 | 128M |     strln = OPENSSL_strnlen(value, max < 0 ? SIZE_MAX : (size_t)max); | 
| 393 |  |  | 
| 394 | 128M |     padlen = min - strln; | 
| 395 | 128M |     if (min < 0 || padlen < 0) | 
| 396 | 86.1M |         padlen = 0; | 
| 397 | 128M |     if (max >= 0) { | 
| 398 |  |         /* | 
| 399 |  |          * Calculate the maximum output including padding. | 
| 400 |  |          * Make sure max doesn't overflow into negativity | 
| 401 |  |          */ | 
| 402 | 128M |         if (max < INT_MAX - padlen) | 
| 403 | 23.1M |             max += padlen; | 
| 404 | 104M |         else | 
| 405 | 104M |             max = INT_MAX; | 
| 406 | 128M |     } | 
| 407 | 128M |     if (flags & DP_F_MINUS) | 
| 408 | 14.7M |         padlen = -padlen; | 
| 409 |  |  | 
| 410 | 270M |     while ((padlen > 0) && (max < 0 || cnt < max)) { | 
| 411 | 142M |         if (!doapr_outch(sbuffer, buffer, currlen, maxlen, ' ')) | 
| 412 | 0 |             return 0; | 
| 413 | 142M |         --padlen; | 
| 414 | 142M |         ++cnt; | 
| 415 | 142M |     } | 
| 416 | 447M |     while (strln > 0 && (max < 0 || cnt < max)) { | 
| 417 | 319M |         if (!doapr_outch(sbuffer, buffer, currlen, maxlen, *value++)) | 
| 418 | 0 |             return 0; | 
| 419 | 319M |         --strln; | 
| 420 | 319M |         ++cnt; | 
| 421 | 319M |     } | 
| 422 | 311M |     while ((padlen < 0) && (max < 0 || cnt < max)) { | 
| 423 | 182M |         if (!doapr_outch(sbuffer, buffer, currlen, maxlen, ' ')) | 
| 424 | 0 |             return 0; | 
| 425 | 182M |         ++padlen; | 
| 426 | 182M |         ++cnt; | 
| 427 | 182M |     } | 
| 428 | 128M |     return 1; | 
| 429 | 128M | } | 
| 430 |  |  | 
| 431 |  | static int | 
| 432 |  | fmtint(char **sbuffer, | 
| 433 |  |        char **buffer, | 
| 434 |  |        size_t *currlen, | 
| 435 |  |        size_t *maxlen, int64_t value, int base, int min, int max, int flags) | 
| 436 | 281M | { | 
| 437 | 281M |     int signvalue = 0; | 
| 438 | 281M |     const char *prefix = ""; | 
| 439 | 281M |     uint64_t uvalue; | 
| 440 | 281M |     char convert[DECIMAL_SIZE(value) + 3]; | 
| 441 | 281M |     int place = 0; | 
| 442 | 281M |     int spadlen = 0; | 
| 443 | 281M |     int zpadlen = 0; | 
| 444 | 281M |     int caps = 0; | 
| 445 |  |  | 
| 446 | 281M |     if (max < 0) | 
| 447 | 281M |         max = 0; | 
| 448 | 281M |     uvalue = value; | 
| 449 | 281M |     if (!(flags & DP_F_UNSIGNED)) { | 
| 450 | 58.7M |         if (value < 0) { | 
| 451 | 6.60k |             signvalue = '-'; | 
| 452 | 6.60k |             uvalue = 0 - (uint64_t)value; | 
| 453 | 58.7M |         } else if (flags & DP_F_PLUS) | 
| 454 | 0 |             signvalue = '+'; | 
| 455 | 58.7M |         else if (flags & DP_F_SPACE) | 
| 456 | 0 |             signvalue = ' '; | 
| 457 | 58.7M |     } | 
| 458 | 281M |     if (flags & DP_F_NUM) { | 
| 459 | 0 |         if (base == 8) | 
| 460 | 0 |             prefix = "0"; | 
| 461 | 0 |         if (base == 16) | 
| 462 | 0 |             prefix = "0x"; | 
| 463 | 0 |     } | 
| 464 | 281M |     if (flags & DP_F_UP) | 
| 465 | 78.9M |         caps = 1; | 
| 466 | 508M |     do { | 
| 467 | 508M |         convert[place++] = (caps ? "0123456789ABCDEF" : "0123456789abcdef") | 
| 468 | 508M |             [uvalue % (unsigned)base]; | 
| 469 | 508M |         uvalue = (uvalue / (unsigned)base); | 
| 470 | 508M |     } while (uvalue && (place < (int)sizeof(convert))); | 
| 471 | 281M |     if (place == sizeof(convert)) | 
| 472 | 0 |         place--; | 
| 473 | 281M |     convert[place] = 0; | 
| 474 |  |  | 
| 475 | 281M |     zpadlen = max - place; | 
| 476 | 281M |     spadlen = | 
| 477 | 281M |         min - OSSL_MAX(max, place) - (signvalue ? 1 : 0) - strlen(prefix); | 
| 478 | 281M |     if (zpadlen < 0) | 
| 479 | 281M |         zpadlen = 0; | 
| 480 | 281M |     if (spadlen < 0) | 
| 481 | 31.2M |         spadlen = 0; | 
| 482 | 281M |     if (flags & DP_F_ZERO) { | 
| 483 | 216M |         zpadlen = OSSL_MAX(zpadlen, spadlen); | 
| 484 | 216M |         spadlen = 0; | 
| 485 | 216M |     } | 
| 486 | 281M |     if (flags & DP_F_MINUS) | 
| 487 | 14.7M |         spadlen = -spadlen; | 
| 488 |  |  | 
| 489 |  |     /* spaces */ | 
| 490 | 328M |     while (spadlen > 0) { | 
| 491 | 47.1M |         if (!doapr_outch(sbuffer, buffer, currlen, maxlen, ' ')) | 
| 492 | 0 |             return 0; | 
| 493 | 47.1M |         --spadlen; | 
| 494 | 47.1M |     } | 
| 495 |  |  | 
| 496 |  |     /* sign */ | 
| 497 | 281M |     if (signvalue) | 
| 498 | 6.60k |         if (!doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue)) | 
| 499 | 0 |             return 0; | 
| 500 |  |  | 
| 501 |  |     /* prefix */ | 
| 502 | 281M |     while (*prefix) { | 
| 503 | 0 |         if (!doapr_outch(sbuffer, buffer, currlen, maxlen, *prefix)) | 
| 504 | 0 |             return 0; | 
| 505 | 0 |         prefix++; | 
| 506 | 0 |     } | 
| 507 |  |  | 
| 508 |  |     /* zeros */ | 
| 509 | 281M |     if (zpadlen > 0) { | 
| 510 | 143M |         while (zpadlen > 0) { | 
| 511 | 71.8M |             if (!doapr_outch(sbuffer, buffer, currlen, maxlen, '0')) | 
| 512 | 0 |                 return 0; | 
| 513 | 71.8M |             --zpadlen; | 
| 514 | 71.8M |         } | 
| 515 | 71.5M |     } | 
| 516 |  |     /* digits */ | 
| 517 | 789M |     while (place > 0) { | 
| 518 | 508M |         if (!doapr_outch(sbuffer, buffer, currlen, maxlen, convert[--place])) | 
| 519 | 0 |             return 0; | 
| 520 | 508M |     } | 
| 521 |  |  | 
| 522 |  |     /* left justified spaces */ | 
| 523 | 295M |     while (spadlen < 0) { | 
| 524 | 14.1M |         if (!doapr_outch(sbuffer, buffer, currlen, maxlen, ' ')) | 
| 525 | 0 |             return 0; | 
| 526 | 14.1M |         ++spadlen; | 
| 527 | 14.1M |     } | 
| 528 | 281M |     return 1; | 
| 529 | 281M | } | 
| 530 |  |  | 
| 531 |  | #ifndef OPENSSL_SYS_UEFI | 
| 532 |  |  | 
| 533 |  | static LDOUBLE abs_val(LDOUBLE value) | 
| 534 | 0 | { | 
| 535 | 0 |     LDOUBLE result = value; | 
| 536 | 0 |     if (value < 0) | 
| 537 | 0 |         result = -value; | 
| 538 | 0 |     return result; | 
| 539 | 0 | } | 
| 540 |  |  | 
| 541 |  | static LDOUBLE pow_10(int in_exp) | 
| 542 | 0 | { | 
| 543 | 0 |     LDOUBLE result = 1; | 
| 544 | 0 |     while (in_exp) { | 
| 545 | 0 |         result *= 10; | 
| 546 | 0 |         in_exp--; | 
| 547 | 0 |     } | 
| 548 | 0 |     return result; | 
| 549 | 0 | } | 
| 550 |  |  | 
| 551 |  | static long roundv(LDOUBLE value) | 
| 552 | 0 | { | 
| 553 | 0 |     long intpart; | 
| 554 | 0 |     intpart = (long)value; | 
| 555 | 0 |     value = value - intpart; | 
| 556 | 0 |     if (value >= 0.5) | 
| 557 | 0 |         intpart++; | 
| 558 | 0 |     return intpart; | 
| 559 | 0 | } | 
| 560 |  |  | 
| 561 |  | static int | 
| 562 |  | fmtfp(char **sbuffer, | 
| 563 |  |       char **buffer, | 
| 564 |  |       size_t *currlen, | 
| 565 |  |       size_t *maxlen, LDOUBLE fvalue, int min, int max, int flags, int style) | 
| 566 | 0 | { | 
| 567 | 0 |     int signvalue = 0; | 
| 568 | 0 |     LDOUBLE ufvalue; | 
| 569 | 0 |     LDOUBLE tmpvalue; | 
| 570 | 0 |     char iconvert[20]; | 
| 571 | 0 |     char fconvert[20]; | 
| 572 | 0 |     char econvert[20]; | 
| 573 | 0 |     int iplace = 0; | 
| 574 | 0 |     int fplace = 0; | 
| 575 | 0 |     int eplace = 0; | 
| 576 | 0 |     int padlen = 0; | 
| 577 | 0 |     int zpadlen = 0; | 
| 578 | 0 |     long exp = 0; | 
| 579 | 0 |     unsigned long intpart; | 
| 580 | 0 |     unsigned long fracpart; | 
| 581 | 0 |     unsigned long max10; | 
| 582 | 0 |     int realstyle; | 
| 583 |  | 
 | 
| 584 | 0 |     if (max < 0) | 
| 585 | 0 |         max = 6; | 
| 586 |  | 
 | 
| 587 | 0 |     if (fvalue < 0) | 
| 588 | 0 |         signvalue = '-'; | 
| 589 | 0 |     else if (flags & DP_F_PLUS) | 
| 590 | 0 |         signvalue = '+'; | 
| 591 | 0 |     else if (flags & DP_F_SPACE) | 
| 592 | 0 |         signvalue = ' '; | 
| 593 |  |  | 
| 594 |  |     /* | 
| 595 |  |      * G_FORMAT sometimes prints like E_FORMAT and sometimes like F_FORMAT | 
| 596 |  |      * depending on the number to be printed. Work out which one it is and use | 
| 597 |  |      * that from here on. | 
| 598 |  |      */ | 
| 599 | 0 |     if (style == G_FORMAT) { | 
| 600 | 0 |         if (fvalue == 0.0) { | 
| 601 | 0 |             realstyle = F_FORMAT; | 
| 602 | 0 |         } else if (fvalue < 0.0001) { | 
| 603 | 0 |             realstyle = E_FORMAT; | 
| 604 | 0 |         } else if ((max == 0 && fvalue >= 10) | 
| 605 | 0 |                     || (max > 0 && fvalue >= pow_10(max))) { | 
| 606 | 0 |             realstyle = E_FORMAT; | 
| 607 | 0 |         } else { | 
| 608 | 0 |             realstyle = F_FORMAT; | 
| 609 | 0 |         } | 
| 610 | 0 |     } else { | 
| 611 | 0 |         realstyle = style; | 
| 612 | 0 |     } | 
| 613 |  | 
 | 
| 614 | 0 |     if (style != F_FORMAT) { | 
| 615 | 0 |         tmpvalue = fvalue; | 
| 616 |  |         /* Calculate the exponent */ | 
| 617 | 0 |         if (fvalue != 0.0) { | 
| 618 | 0 |             while (tmpvalue < 1) { | 
| 619 | 0 |                 tmpvalue *= 10; | 
| 620 | 0 |                 exp--; | 
| 621 | 0 |             } | 
| 622 | 0 |             while (tmpvalue > 10) { | 
| 623 | 0 |                 tmpvalue /= 10; | 
| 624 | 0 |                 exp++; | 
| 625 | 0 |             } | 
| 626 | 0 |         } | 
| 627 | 0 |         if (style == G_FORMAT) { | 
| 628 |  |             /* | 
| 629 |  |              * In G_FORMAT the "precision" represents significant digits. We | 
| 630 |  |              * always have at least 1 significant digit. | 
| 631 |  |              */ | 
| 632 | 0 |             if (max == 0) | 
| 633 | 0 |                 max = 1; | 
| 634 |  |             /* Now convert significant digits to decimal places */ | 
| 635 | 0 |             if (realstyle == F_FORMAT) { | 
| 636 | 0 |                 max -= (exp + 1); | 
| 637 | 0 |                 if (max < 0) { | 
| 638 |  |                     /* | 
| 639 |  |                      * Should not happen. If we're in F_FORMAT then exp < max? | 
| 640 |  |                      */ | 
| 641 | 0 |                     (void)doapr_outch(sbuffer, buffer, currlen, maxlen, '\0'); | 
| 642 | 0 |                     return 0; | 
| 643 | 0 |                 } | 
| 644 | 0 |             } else { | 
| 645 |  |                 /* | 
| 646 |  |                  * In E_FORMAT there is always one significant digit in front | 
| 647 |  |                  * of the decimal point, so: | 
| 648 |  |                  * significant digits == 1 + decimal places | 
| 649 |  |                  */ | 
| 650 | 0 |                 max--; | 
| 651 | 0 |             } | 
| 652 | 0 |         } | 
| 653 | 0 |         if (realstyle == E_FORMAT) | 
| 654 | 0 |             fvalue = tmpvalue; | 
| 655 | 0 |     } | 
| 656 | 0 |     ufvalue = abs_val(fvalue); | 
| 657 |  |     /* | 
| 658 |  |      * By subtracting 65535 (2^16-1) we cancel the low order 15 bits | 
| 659 |  |      * of ULONG_MAX to avoid using imprecise floating point values. | 
| 660 |  |      */ | 
| 661 | 0 |     if (ufvalue >= (double)(ULONG_MAX - 65535) + 65536.0) { | 
| 662 |  |         /* Number too big */ | 
| 663 | 0 |         (void)doapr_outch(sbuffer, buffer, currlen, maxlen, '\0'); | 
| 664 | 0 |         return 0; | 
| 665 | 0 |     } | 
| 666 | 0 |     intpart = (unsigned long)ufvalue; | 
| 667 |  |  | 
| 668 |  |     /* | 
| 669 |  |      * sorry, we only support 9 digits past the decimal because of our | 
| 670 |  |      * conversion method | 
| 671 |  |      */ | 
| 672 | 0 |     if (max > 9) | 
| 673 | 0 |         max = 9; | 
| 674 |  |  | 
| 675 |  |     /* | 
| 676 |  |      * we "cheat" by converting the fractional part to integer by multiplying | 
| 677 |  |      * by a factor of 10 | 
| 678 |  |      */ | 
| 679 | 0 |     max10 = roundv(pow_10(max)); | 
| 680 | 0 |     fracpart = roundv(pow_10(max) * (ufvalue - intpart)); | 
| 681 |  | 
 | 
| 682 | 0 |     if (fracpart >= max10) { | 
| 683 | 0 |         intpart++; | 
| 684 | 0 |         fracpart -= max10; | 
| 685 | 0 |     } | 
| 686 |  |  | 
| 687 |  |     /* convert integer part */ | 
| 688 | 0 |     do { | 
| 689 | 0 |         iconvert[iplace++] = "0123456789"[intpart % 10]; | 
| 690 | 0 |         intpart = (intpart / 10); | 
| 691 | 0 |     } while (intpart && (iplace < (int)sizeof(iconvert))); | 
| 692 | 0 |     if (iplace == sizeof(iconvert)) | 
| 693 | 0 |         iplace--; | 
| 694 | 0 |     iconvert[iplace] = 0; | 
| 695 |  |  | 
| 696 |  |     /* convert fractional part */ | 
| 697 | 0 |     while (fplace < max) { | 
| 698 | 0 |         if (style == G_FORMAT && fplace == 0 && (fracpart % 10) == 0) { | 
| 699 |  |             /* We strip trailing zeros in G_FORMAT */ | 
| 700 | 0 |             max--; | 
| 701 | 0 |             fracpart = fracpart / 10; | 
| 702 | 0 |             if (fplace < max) | 
| 703 | 0 |                 continue; | 
| 704 | 0 |             break; | 
| 705 | 0 |         } | 
| 706 | 0 |         fconvert[fplace++] = "0123456789"[fracpart % 10]; | 
| 707 | 0 |         fracpart = (fracpart / 10); | 
| 708 | 0 |     } | 
| 709 |  | 
 | 
| 710 | 0 |     if (fplace == sizeof(fconvert)) | 
| 711 | 0 |         fplace--; | 
| 712 | 0 |     fconvert[fplace] = 0; | 
| 713 |  |  | 
| 714 |  |     /* convert exponent part */ | 
| 715 | 0 |     if (realstyle == E_FORMAT) { | 
| 716 | 0 |         int tmpexp; | 
| 717 | 0 |         if (exp < 0) | 
| 718 | 0 |             tmpexp = -exp; | 
| 719 | 0 |         else | 
| 720 | 0 |             tmpexp = exp; | 
| 721 |  | 
 | 
| 722 | 0 |         do { | 
| 723 | 0 |             econvert[eplace++] = "0123456789"[tmpexp % 10]; | 
| 724 | 0 |             tmpexp = (tmpexp / 10); | 
| 725 | 0 |         } while (tmpexp > 0 && eplace < (int)sizeof(econvert)); | 
| 726 |  |         /* Exponent is huge!! Too big to print */ | 
| 727 | 0 |         if (tmpexp > 0) { | 
| 728 | 0 |             (void)doapr_outch(sbuffer, buffer, currlen, maxlen, '\0'); | 
| 729 | 0 |             return 0; | 
| 730 | 0 |         } | 
| 731 |  |         /* Add a leading 0 for single digit exponents */ | 
| 732 | 0 |         if (eplace == 1) | 
| 733 | 0 |             econvert[eplace++] = '0'; | 
| 734 | 0 |     } | 
| 735 |  |  | 
| 736 |  |     /* | 
| 737 |  |      * -1 for decimal point (if we have one, i.e. max > 0), | 
| 738 |  |      * another -1 if we are printing a sign | 
| 739 |  |      */ | 
| 740 | 0 |     padlen = min - iplace - max - (max > 0 ? 1 : 0) - ((signvalue) ? 1 : 0); | 
| 741 |  |     /* Take some off for exponent prefix "+e" and exponent */ | 
| 742 | 0 |     if (realstyle == E_FORMAT) | 
| 743 | 0 |         padlen -= 2 + eplace; | 
| 744 | 0 |     zpadlen = max - fplace; | 
| 745 | 0 |     if (zpadlen < 0) | 
| 746 | 0 |         zpadlen = 0; | 
| 747 | 0 |     if (padlen < 0) | 
| 748 | 0 |         padlen = 0; | 
| 749 | 0 |     if (flags & DP_F_MINUS) | 
| 750 | 0 |         padlen = -padlen; | 
| 751 |  | 
 | 
| 752 | 0 |     if ((flags & DP_F_ZERO) && (padlen > 0)) { | 
| 753 | 0 |         if (signvalue) { | 
| 754 | 0 |             if (!doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue)) | 
| 755 | 0 |                 return 0; | 
| 756 | 0 |             --padlen; | 
| 757 | 0 |             signvalue = 0; | 
| 758 | 0 |         } | 
| 759 | 0 |         while (padlen > 0) { | 
| 760 | 0 |             if (!doapr_outch(sbuffer, buffer, currlen, maxlen, '0')) | 
| 761 | 0 |                 return 0; | 
| 762 | 0 |             --padlen; | 
| 763 | 0 |         } | 
| 764 | 0 |     } | 
| 765 | 0 |     while (padlen > 0) { | 
| 766 | 0 |         if (!doapr_outch(sbuffer, buffer, currlen, maxlen, ' ')) | 
| 767 | 0 |             return 0; | 
| 768 | 0 |         --padlen; | 
| 769 | 0 |     } | 
| 770 | 0 |     if (signvalue && !doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue)) | 
| 771 | 0 |         return 0; | 
| 772 |  |  | 
| 773 | 0 |     while (iplace > 0) { | 
| 774 | 0 |         if (!doapr_outch(sbuffer, buffer, currlen, maxlen, iconvert[--iplace])) | 
| 775 | 0 |             return 0; | 
| 776 | 0 |     } | 
| 777 |  |  | 
| 778 |  |     /* | 
| 779 |  |      * Decimal point. This should probably use locale to find the correct | 
| 780 |  |      * char to print out. | 
| 781 |  |      */ | 
| 782 | 0 |     if (max > 0 || (flags & DP_F_NUM)) { | 
| 783 | 0 |         if (!doapr_outch(sbuffer, buffer, currlen, maxlen, '.')) | 
| 784 | 0 |             return 0; | 
| 785 |  |  | 
| 786 | 0 |         while (fplace > 0) { | 
| 787 | 0 |             if (!doapr_outch(sbuffer, buffer, currlen, maxlen, | 
| 788 | 0 |                              fconvert[--fplace])) | 
| 789 | 0 |                 return 0; | 
| 790 | 0 |         } | 
| 791 | 0 |     } | 
| 792 | 0 |     while (zpadlen > 0) { | 
| 793 | 0 |         if (!doapr_outch(sbuffer, buffer, currlen, maxlen, '0')) | 
| 794 | 0 |             return 0; | 
| 795 | 0 |         --zpadlen; | 
| 796 | 0 |     } | 
| 797 | 0 |     if (realstyle == E_FORMAT) { | 
| 798 | 0 |         char ech; | 
| 799 |  | 
 | 
| 800 | 0 |         if ((flags & DP_F_UP) == 0) | 
| 801 | 0 |             ech = 'e'; | 
| 802 | 0 |         else | 
| 803 | 0 |             ech = 'E'; | 
| 804 | 0 |         if (!doapr_outch(sbuffer, buffer, currlen, maxlen, ech)) | 
| 805 | 0 |                 return 0; | 
| 806 | 0 |         if (exp < 0) { | 
| 807 | 0 |             if (!doapr_outch(sbuffer, buffer, currlen, maxlen, '-')) | 
| 808 | 0 |                     return 0; | 
| 809 | 0 |         } else { | 
| 810 | 0 |             if (!doapr_outch(sbuffer, buffer, currlen, maxlen, '+')) | 
| 811 | 0 |                     return 0; | 
| 812 | 0 |         } | 
| 813 | 0 |         while (eplace > 0) { | 
| 814 | 0 |             if (!doapr_outch(sbuffer, buffer, currlen, maxlen, | 
| 815 | 0 |                              econvert[--eplace])) | 
| 816 | 0 |                 return 0; | 
| 817 | 0 |         } | 
| 818 | 0 |     } | 
| 819 |  |  | 
| 820 | 0 |     while (padlen < 0) { | 
| 821 | 0 |         if (!doapr_outch(sbuffer, buffer, currlen, maxlen, ' ')) | 
| 822 | 0 |             return 0; | 
| 823 | 0 |         ++padlen; | 
| 824 | 0 |     } | 
| 825 | 0 |     return 1; | 
| 826 | 0 | } | 
| 827 |  |  | 
| 828 |  | #endif /* OPENSSL_SYS_UEFI */ | 
| 829 |  |  | 
| 830 | 44.4k | #define BUFFER_INC  1024 | 
| 831 |  |  | 
| 832 |  | static int | 
| 833 |  | doapr_outch(char **sbuffer, | 
| 834 |  |             char **buffer, size_t *currlen, size_t *maxlen, int c) | 
| 835 | 1.97G | { | 
| 836 |  |     /* If we haven't at least one buffer, someone has done a big booboo */ | 
| 837 | 1.97G |     if (!ossl_assert(*sbuffer != NULL || buffer != NULL)) | 
| 838 | 0 |         return 0; | 
| 839 |  |  | 
| 840 |  |     /* |currlen| must always be <= |*maxlen| */ | 
| 841 | 1.97G |     if (!ossl_assert(*currlen <= *maxlen)) | 
| 842 | 0 |         return 0; | 
| 843 |  |  | 
| 844 | 1.97G |     if (buffer && *currlen == *maxlen) { | 
| 845 | 22.2k |         if (*maxlen > INT_MAX - BUFFER_INC) | 
| 846 | 0 |             return 0; | 
| 847 |  |  | 
| 848 | 22.2k |         *maxlen += BUFFER_INC; | 
| 849 | 22.2k |         if (*buffer == NULL) { | 
| 850 | 596 |             if ((*buffer = OPENSSL_malloc(*maxlen)) == NULL) { | 
| 851 | 0 |                 ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE); | 
| 852 | 0 |                 return 0; | 
| 853 | 0 |             } | 
| 854 | 596 |             if (*currlen > 0) { | 
| 855 | 596 |                 if (!ossl_assert(*sbuffer != NULL)) | 
| 856 | 0 |                     return 0; | 
| 857 | 596 |                 memcpy(*buffer, *sbuffer, *currlen); | 
| 858 | 596 |             } | 
| 859 | 596 |             *sbuffer = NULL; | 
| 860 | 21.6k |         } else { | 
| 861 | 21.6k |             char *tmpbuf; | 
| 862 |  |  | 
| 863 | 21.6k |             tmpbuf = OPENSSL_realloc(*buffer, *maxlen); | 
| 864 | 21.6k |             if (tmpbuf == NULL) { | 
| 865 | 0 |                 ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE); | 
| 866 | 0 |                 return 0; | 
| 867 | 0 |             } | 
| 868 | 21.6k |             *buffer = tmpbuf; | 
| 869 | 21.6k |         } | 
| 870 | 22.2k |     } | 
| 871 |  |  | 
| 872 | 1.97G |     if (*currlen < *maxlen) { | 
| 873 | 1.97G |         if (*sbuffer) | 
| 874 | 1.94G |             (*sbuffer)[(*currlen)++] = (char)c; | 
| 875 | 22.2M |         else | 
| 876 | 22.2M |             (*buffer)[(*currlen)++] = (char)c; | 
| 877 | 1.97G |     } | 
| 878 |  |  | 
| 879 | 1.97G |     return 1; | 
| 880 | 1.97G | } | 
| 881 |  |  | 
| 882 |  | /***************************************************************************/ | 
| 883 |  |  | 
| 884 |  | int BIO_printf(BIO *bio, const char *format, ...) | 
| 885 | 258M | { | 
| 886 | 258M |     va_list args; | 
| 887 | 258M |     int ret; | 
| 888 |  |  | 
| 889 | 258M |     va_start(args, format); | 
| 890 |  |  | 
| 891 | 258M |     ret = BIO_vprintf(bio, format, args); | 
| 892 |  |  | 
| 893 | 258M |     va_end(args); | 
| 894 | 258M |     return ret; | 
| 895 | 258M | } | 
| 896 |  |  | 
| 897 |  | int BIO_vprintf(BIO *bio, const char *format, va_list args) | 
| 898 | 258M | { | 
| 899 | 258M |     int ret; | 
| 900 | 258M |     size_t retlen; | 
| 901 | 258M |     char hugebuf[1024 * 2];     /* Was previously 10k, which is unreasonable | 
| 902 |  |                                  * in small-stack environments, like threads | 
| 903 |  |                                  * or DOS programs. */ | 
| 904 | 258M |     char *hugebufp = hugebuf; | 
| 905 | 258M |     size_t hugebufsize = sizeof(hugebuf); | 
| 906 | 258M |     char *dynbuf = NULL; | 
| 907 | 258M |     int ignored; | 
| 908 |  |  | 
| 909 | 258M |     dynbuf = NULL; | 
| 910 | 258M |     if (!_dopr(&hugebufp, &dynbuf, &hugebufsize, &retlen, &ignored, format, | 
| 911 | 258M |                 args)) { | 
| 912 | 0 |         OPENSSL_free(dynbuf); | 
| 913 | 0 |         return -1; | 
| 914 | 0 |     } | 
| 915 | 258M |     if (dynbuf) { | 
| 916 | 908 |         ret = BIO_write(bio, dynbuf, (int)retlen); | 
| 917 | 908 |         OPENSSL_free(dynbuf); | 
| 918 | 258M |     } else { | 
| 919 | 258M |         ret = BIO_write(bio, hugebuf, (int)retlen); | 
| 920 | 258M |     } | 
| 921 | 258M |     return ret; | 
| 922 | 258M | } | 
| 923 |  |  | 
| 924 |  | /* | 
| 925 |  |  * As snprintf is not available everywhere, we provide our own | 
| 926 |  |  * implementation. This function has nothing to do with BIOs, but it's | 
| 927 |  |  * closely related to BIO_printf, and we need *some* name prefix ... (XXX the | 
| 928 |  |  * function should be renamed, but to what?) | 
| 929 |  |  */ | 
| 930 |  | int BIO_snprintf(char *buf, size_t n, const char *format, ...) | 
| 931 | 152M | { | 
| 932 | 152M |     va_list args; | 
| 933 | 152M |     int ret; | 
| 934 |  |  | 
| 935 | 152M |     va_start(args, format); | 
| 936 |  |  | 
| 937 | 152M |     ret = BIO_vsnprintf(buf, n, format, args); | 
| 938 |  |  | 
| 939 | 152M |     va_end(args); | 
| 940 | 152M |     return ret; | 
| 941 | 152M | } | 
| 942 |  |  | 
| 943 |  | int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args) | 
| 944 | 113M | { | 
| 945 | 113M |     size_t retlen; | 
| 946 | 113M |     int truncated; | 
| 947 |  |  | 
| 948 | 113M |     if (!_dopr(&buf, NULL, &n, &retlen, &truncated, format, args)) | 
| 949 | 0 |         return -1; | 
| 950 |  |  | 
| 951 | 113M |     if (truncated) | 
| 952 |  |         /* | 
| 953 |  |          * In case of truncation, return -1 like traditional snprintf. | 
| 954 |  |          * (Current drafts for ISO/IEC 9899 say snprintf should return the | 
| 955 |  |          * number of characters that would have been written, had the buffer | 
| 956 |  |          * been large enough.) | 
| 957 |  |          */ | 
| 958 | 7.76k |         return -1; | 
| 959 | 113M |     return (retlen <= INT_MAX) ? (int)retlen : -1; | 
| 960 | 113M | } |