LLVMFuzzerTestOneInput: 22| 933|int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size){ 23| 933| char *fuzz_der = (char *)malloc(size+1); ------------------ | | 137| 933|#define malloc p9malloc ------------------ 24| 933| if (fuzz_der == NULL){ ------------------ | Branch (24:6): [True: 0, False: 933] ------------------ 25| 0| return 0; 26| 0| } 27| 933| memcpy(fuzz_der, data, size); 28| 933| fuzz_der[size] = '\0'; 29| 933| asn1dump(fuzz_der, size); 30| | 31| 933| free(fuzz_der); ------------------ | | 140| 933|#define free p9free ------------------ 32| 933| return 0; 33| 933|} dofmt: 13| 30.9k|{ 14| 30.9k| Rune rune, *rt, *rs; 15| 30.9k| int r; 16| 30.9k| char *t, *s; 17| 30.9k| int n, nfmt; 18| | 19| 30.9k| nfmt = f->nfmt; 20| 50.6k| for(;;){ 21| 50.6k| if(f->runes){ ------------------ | Branch (21:6): [True: 0, False: 50.6k] ------------------ 22| 0| rt = (Rune*)f->to; 23| 0| rs = (Rune*)f->stop; 24| 0| while((r = *(uchar*)fmt) && r != '%'){ ------------------ | Branch (24:10): [True: 0, False: 0] | Branch (24:32): [True: 0, False: 0] ------------------ 25| 0| if(r < Runeself) ------------------ | Branch (25:8): [True: 0, False: 0] ------------------ 26| 0| fmt++; 27| 0| else{ 28| 0| fmt += chartorune(&rune, fmt); 29| 0| r = rune; 30| 0| } 31| 0| FMTRCHAR(f, rt, rs, r); ------------------ | | 68| 0| do{\ | | 69| 0| if(t + 1 > (Rune*)s){\ | | ------------------ | | | Branch (69:5): [True: 0, False: 0] | | ------------------ | | 70| 0| t = (Rune*)__fmtflush(f, t, sizeof(Rune));\ | | 71| 0| if(t != nil)\ | | ------------------ | | | | 34| 0|#define nil 0 | | ------------------ | | | Branch (71:6): [True: 0, False: 0] | | ------------------ | | 72| 0| s = (Rune*)f->stop;\ | | 73| 0| else\ | | 74| 0| return -1;\ | | 75| 0| }\ | | 76| 0| *t++ = c;\ | | 77| 0| }while(0) | | ------------------ | | | Branch (77:9): [Folded, False: 0] | | ------------------ ------------------ 32| 0| } 33| 0| fmt++; 34| 0| f->nfmt += rt - (Rune *)f->to; 35| 0| f->to = rt; 36| 0| if(!r) ------------------ | Branch (36:7): [True: 0, False: 0] ------------------ 37| 0| return f->nfmt - nfmt; 38| 0| f->stop = rs; 39| 50.6k| }else{ 40| 50.6k| t = (char*)f->to; 41| 50.6k| s = (char*)f->stop; 42| 154k| while((r = *(uchar*)fmt) && r != '%'){ ------------------ | Branch (42:10): [True: 123k, False: 30.9k] | Branch (42:32): [True: 103k, False: 19.6k] ------------------ 43| 103k| if(r < Runeself){ ------------------ | Branch (43:8): [True: 103k, False: 0] ------------------ 44| 103k| FMTCHAR(f, t, s, r); ------------------ | | 56| 103k| do{\ | | 57| 103k| if(t + 1 > (char*)s){\ | | ------------------ | | | Branch (57:5): [True: 14, False: 103k] | | ------------------ | | 58| 14| t = (char*)__fmtflush(f, t, 1);\ | | 59| 14| if(t != nil)\ | | ------------------ | | | | 34| 28|#define nil 0 | | ------------------ | | | Branch (59:6): [True: 14, False: 0] | | ------------------ | | 60| 14| s = (char*)f->stop;\ | | 61| 14| else\ | | 62| 14| return -1;\ | | 63| 14| }\ | | 64| 103k| *t++ = c;\ | | 65| 103k| }while(0) | | ------------------ | | | Branch (65:9): [Folded, False: 103k] | | ------------------ ------------------ 45| 103k| fmt++; 46| 103k| }else{ 47| 0| n = chartorune(&rune, fmt); 48| 0| if(t + n > s){ ------------------ | Branch (48:9): [True: 0, False: 0] ------------------ 49| 0| t = (char*)__fmtflush(f, t, n); 50| 0| if(t != nil) ------------------ | | 34| 0|#define nil 0 ------------------ | Branch (50:10): [True: 0, False: 0] ------------------ 51| 0| s = (char*)f->stop; 52| 0| else 53| 0| return -1; 54| 0| } 55| 0| while(n--) ------------------ | Branch (55:12): [True: 0, False: 0] ------------------ 56| 0| *t++ = *fmt++; 57| 0| } 58| 103k| } 59| 50.6k| fmt++; 60| 50.6k| f->nfmt += t - (char *)f->to; 61| 50.6k| f->to = t; 62| 50.6k| if(!r) ------------------ | Branch (62:7): [True: 30.9k, False: 19.6k] ------------------ 63| 30.9k| return f->nfmt - nfmt; 64| 19.6k| f->stop = s; 65| 19.6k| } 66| | 67| 19.6k| fmt = (char*)__fmtdispatch(f, fmt, 0); 68| 19.6k| if(fmt == nil) ------------------ | | 34| 19.6k|#define nil 0 ------------------ | Branch (68:6): [True: 0, False: 19.6k] ------------------ 69| 0| return -1; 70| 19.6k| } 71| 30.9k|} __fmtflush: 75| 4.94k|{ 76| 4.94k| if(f->runes) ------------------ | Branch (76:5): [True: 0, False: 4.94k] ------------------ 77| 0| f->nfmt += (Rune*)t - (Rune*)f->to; 78| 4.94k| else 79| 4.94k| f->nfmt += (char*)t - (char *)f->to; 80| 4.94k| f->to = t; 81| 4.94k| if(f->flush == 0 || (*f->flush)(f) == 0 || (char*)f->to + len > (char*)f->stop){ ------------------ | Branch (81:5): [True: 0, False: 4.94k] | Branch (81:22): [True: 0, False: 4.94k] | Branch (81:45): [True: 0, False: 4.94k] ------------------ 82| 0| f->stop = f->to; 83| 0| return nil; ------------------ | | 34| 0|#define nil 0 ------------------ 84| 0| } 85| 4.94k| return f->to; 86| 4.94k|} __fmtpad: 94| 19.6k|{ 95| 19.6k| char *t, *s; 96| 19.6k| int i; 97| | 98| 19.6k| t = (char*)f->to; 99| 19.6k| s = (char*)f->stop; 100| 19.6k| for(i = 0; i < n; i++) ------------------ | Branch (100:13): [True: 0, False: 19.6k] ------------------ 101| 0| FMTCHAR(f, t, s, ' '); ------------------ | | 56| 0| do{\ | | 57| 0| if(t + 1 > (char*)s){\ | | ------------------ | | | Branch (57:5): [True: 0, False: 0] | | ------------------ | | 58| 0| t = (char*)__fmtflush(f, t, 1);\ | | 59| 0| if(t != nil)\ | | ------------------ | | | | 34| 0|#define nil 0 | | ------------------ | | | Branch (59:6): [True: 0, False: 0] | | ------------------ | | 60| 0| s = (char*)f->stop;\ | | 61| 0| else\ | | 62| 0| return -1;\ | | 63| 0| }\ | | 64| 0| *t++ = c;\ | | 65| 0| }while(0) | | ------------------ | | | Branch (65:9): [Folded, False: 0] | | ------------------ ------------------ 102| 19.6k| f->nfmt += t - (char *)f->to; 103| 19.6k| f->to = t; 104| 19.6k| return 0; 105| 19.6k|} __fmtcpy: 124| 19.6k|{ 125| 19.6k| Rune *rt, *rs, r; 126| 19.6k| char *t, *s, *m, *me; 127| 19.6k| ulong fl; ------------------ | | 16| 19.6k|#define ulong _fmtulong ------------------ 128| 19.6k| int nc, w; 129| | 130| 19.6k| m = (char*)vm; 131| 19.6k| me = m + sz; 132| 19.6k| fl = f->flags; 133| 19.6k| w = 0; 134| 19.6k| if(fl & FmtWidth) ------------------ | Branch (134:5): [True: 2.26k, False: 17.3k] ------------------ 135| 2.26k| w = f->width; 136| 19.6k| if((fl & FmtPrec) && n > f->prec) ------------------ | Branch (136:5): [True: 0, False: 19.6k] | Branch (136:23): [True: 0, False: 0] ------------------ 137| 0| n = f->prec; 138| 19.6k| if(f->runes){ ------------------ | Branch (138:5): [True: 0, False: 19.6k] ------------------ 139| 0| if(!(fl & FmtLeft) && __rfmtpad(f, w - n) < 0) ------------------ | Branch (139:6): [True: 0, False: 0] | Branch (139:25): [True: 0, False: 0] ------------------ 140| 0| return -1; 141| 0| rt = (Rune*)f->to; 142| 0| rs = (Rune*)f->stop; 143| 0| for(nc = n; nc > 0; nc--){ ------------------ | Branch (143:15): [True: 0, False: 0] ------------------ 144| 0| r = *(uchar*)m; 145| 0| if(r < Runeself) ------------------ | Branch (145:7): [True: 0, False: 0] ------------------ 146| 0| m++; 147| 0| else if((me - m) >= UTFmax || fullrune(m, me-m)) ------------------ | Branch (147:12): [True: 0, False: 0] | Branch (147:34): [True: 0, False: 0] ------------------ 148| 0| m += chartorune(&r, m); 149| 0| else 150| 0| break; 151| 0| FMTRCHAR(f, rt, rs, r); ------------------ | | 68| 0| do{\ | | 69| 0| if(t + 1 > (Rune*)s){\ | | ------------------ | | | Branch (69:5): [True: 0, False: 0] | | ------------------ | | 70| 0| t = (Rune*)__fmtflush(f, t, sizeof(Rune));\ | | 71| 0| if(t != nil)\ | | ------------------ | | | | 34| 0|#define nil 0 | | ------------------ | | | Branch (71:6): [True: 0, False: 0] | | ------------------ | | 72| 0| s = (Rune*)f->stop;\ | | 73| 0| else\ | | 74| 0| return -1;\ | | 75| 0| }\ | | 76| 0| *t++ = c;\ | | 77| 0| }while(0) | | ------------------ | | | Branch (77:9): [Folded, False: 0] | | ------------------ ------------------ 152| 0| } 153| 0| f->nfmt += rt - (Rune *)f->to; 154| 0| f->to = rt; 155| 0| if(fl & FmtLeft && __rfmtpad(f, w - n) < 0) ------------------ | Branch (155:6): [True: 0, False: 0] | Branch (155:22): [True: 0, False: 0] ------------------ 156| 0| return -1; 157| 19.6k| }else{ 158| 19.6k| if(!(fl & FmtLeft) && __fmtpad(f, w - n) < 0) ------------------ | Branch (158:6): [True: 19.6k, False: 0] | Branch (158:25): [True: 0, False: 19.6k] ------------------ 159| 0| return -1; 160| 19.6k| t = (char*)f->to; 161| 19.6k| s = (char*)f->stop; 162| 708k| for(nc = n; nc > 0; nc--){ ------------------ | Branch (162:15): [True: 688k, False: 19.4k] ------------------ 163| 688k| r = *(uchar*)m; 164| 688k| if(r < Runeself) ------------------ | Branch (164:7): [True: 339k, False: 349k] ------------------ 165| 339k| m++; 166| 349k| else if((me - m) >= UTFmax || fullrune(m, me-m)) ------------------ | Branch (166:12): [True: 348k, False: 448] | Branch (166:34): [True: 241, False: 207] ------------------ 167| 348k| m += chartorune(&r, m); 168| 207| else 169| 207| break; 170| 688k| FMTRUNE(f, t, s, r); ------------------ | | 80| 688k| do{\ | | 81| 688k| Rune _rune;\ | | 82| 688k| int _runelen;\ | | 83| 688k| if(t + UTFmax > (char*)s && t + (_runelen = runelen(r)) > (char*)s){\ | | ------------------ | | | Branch (83:5): [True: 9.01k, False: 679k] | | | Branch (83:30): [True: 4.93k, False: 4.08k] | | ------------------ | | 84| 4.93k| t = (char*)__fmtflush(f, t, _runelen);\ | | 85| 4.93k| if(t != nil)\ | | ------------------ | | | | 34| 9.87k|#define nil 0 | | ------------------ | | | Branch (85:6): [True: 4.93k, False: 0] | | ------------------ | | 86| 4.93k| s = (char*)f->stop;\ | | 87| 4.93k| else\ | | 88| 4.93k| return -1;\ | | 89| 4.93k| }\ | | 90| 688k| if(r < Runeself)\ | | ------------------ | | | Branch (90:5): [True: 339k, False: 348k] | | ------------------ | | 91| 688k| *t++ = r;\ | | 92| 688k| else{\ | | 93| 348k| _rune = r;\ | | 94| 348k| t += runetochar(t, &_rune);\ | | 95| 348k| }\ | | 96| 688k| }while(0) | | ------------------ | | | Branch (96:9): [Folded, False: 688k] | | ------------------ ------------------ 171| 688k| } 172| 19.6k| f->nfmt += t - (char *)f->to; 173| 19.6k| f->to = t; 174| 19.6k| if(fl & FmtLeft && __fmtpad(f, w - n) < 0) ------------------ | Branch (174:6): [True: 0, False: 19.6k] | Branch (174:22): [True: 0, False: 0] ------------------ 175| 0| return -1; 176| 19.6k| } 177| 19.6k| return 0; 178| 19.6k|} fmtstrcpy: 247| 9.81k|{ 248| 9.81k| int i, j; 249| | 250| 9.81k| if(!s) ------------------ | Branch (250:5): [True: 0, False: 9.81k] ------------------ 251| 0| return __fmtcpy(f, "", 5, 5); 252| | /* if precision is specified, make sure we don't wander off the end */ 253| 9.81k| if(f->flags & FmtPrec){ ------------------ | Branch (253:5): [True: 0, False: 9.81k] ------------------ 254| 0|#ifdef PLAN9PORT 255| 0| Rune r; 256| 0| i = 0; 257| 0| for(j=0; jprec && s[i]; j++) ------------------ | Branch (257:12): [True: 0, False: 0] | Branch (257:25): [True: 0, False: 0] ------------------ 258| 0| i += chartorune(&r, s+i); 259| |#else 260| | /* ANSI requires precision in bytes, not Runes */ 261| | for(i=0; iprec; i++) 262| | if(s[i] == 0) 263| | break; 264| | j = utfnlen(s, i); /* won't print partial at end */ 265| |#endif 266| 0| return __fmtcpy(f, s, j, i); 267| 0| } 268| 9.81k| return __fmtcpy(f, s, utflen(s), strlen(s)); 269| 9.81k|} __strfmt: 274| 9.81k|{ 275| 9.81k| char *s; 276| | 277| | s = va_arg(f->args, char *); 278| 9.81k| return fmtstrcpy(f, s); 279| 9.81k|} __ifmt: 328| 9.83k|{ 329| 9.83k| char buf[140], *p, *conv; 330| | /* 140: for 64 bits of binary + 3-byte sep every 4 digits */ 331| 9.83k| uvlong vu; ------------------ | | 18| 9.83k|#define uvlong _fmtuvlong ------------------ 332| 9.83k| ulong u; ------------------ | | 16| 9.83k|#define ulong _fmtulong ------------------ 333| 9.83k| int neg, base, i, n, fl, w, isv; 334| 9.83k| int ndig, len, excess, bytelen; 335| 9.83k| char *grouping; 336| 9.83k| char *thousands; 337| | 338| 9.83k| neg = 0; 339| 9.83k| fl = f->flags; 340| 9.83k| isv = 0; 341| 9.83k| vu = 0; 342| 9.83k| u = 0; 343| |#ifndef PLAN9PORT 344| | /* 345| | * Unsigned verbs for ANSI C 346| | */ 347| | switch(f->r){ 348| | case 'o': 349| | case 'p': 350| | case 'u': 351| | case 'x': 352| | case 'X': 353| | fl |= FmtUnsigned; 354| | fl &= ~(FmtSign|FmtSpace); 355| | break; 356| | } 357| |#endif 358| 9.83k| if(f->r == 'p'){ ------------------ | Branch (358:5): [True: 0, False: 9.83k] ------------------ 359| 0| u = (ulong)va_arg(f->args, void*); 360| 0| f->r = 'x'; 361| 0| fl |= FmtUnsigned; 362| 9.83k| }else if(fl & FmtVLong){ ------------------ | Branch (362:11): [True: 0, False: 9.83k] ------------------ 363| 0| isv = 1; 364| 0| if(fl & FmtUnsigned) ------------------ | Branch (364:6): [True: 0, False: 0] ------------------ 365| 0| vu = va_arg(f->args, uvlong); 366| 0| else 367| 0| vu = va_arg(f->args, vlong); 368| 9.83k| }else if(fl & FmtLong){ ------------------ | Branch (368:11): [True: 0, False: 9.83k] ------------------ 369| 0| if(fl & FmtUnsigned) ------------------ | Branch (369:6): [True: 0, False: 0] ------------------ 370| 0| u = va_arg(f->args, ulong); 371| 0| else 372| 0| u = va_arg(f->args, long); 373| 9.83k| }else if(fl & FmtByte){ ------------------ | Branch (373:11): [True: 0, False: 9.83k] ------------------ 374| 0| if(fl & FmtUnsigned) ------------------ | Branch (374:6): [True: 0, False: 0] ------------------ 375| 0| u = (uchar)va_arg(f->args, int); 376| 0| else 377| 0| u = (char)va_arg(f->args, int); 378| 9.83k| }else if(fl & FmtShort){ ------------------ | Branch (378:11): [True: 0, False: 9.83k] ------------------ 379| 0| if(fl & FmtUnsigned) ------------------ | Branch (379:6): [True: 0, False: 0] ------------------ 380| 0| u = (ushort)va_arg(f->args, int); 381| 0| else 382| 0| u = (short)va_arg(f->args, int); 383| 9.83k| }else{ 384| 9.83k| if(fl & FmtUnsigned) ------------------ | Branch (384:6): [True: 0, False: 9.83k] ------------------ 385| 0| u = va_arg(f->args, uint); 386| 9.83k| else 387| 9.83k| u = va_arg(f->args, int); 388| 9.83k| } 389| 9.83k| conv = "0123456789abcdef"; 390| 9.83k| grouping = "\4"; /* for hex, octal etc. (undefined by spec but nice) */ 391| 9.83k| thousands = f->thousands; 392| 9.83k| switch(f->r){ 393| 7.57k| case 'd': ------------------ | Branch (393:2): [True: 7.57k, False: 2.26k] ------------------ 394| 7.57k| case 'i': ------------------ | Branch (394:2): [True: 0, False: 9.83k] ------------------ 395| 7.57k| case 'u': ------------------ | Branch (395:2): [True: 0, False: 9.83k] ------------------ 396| 7.57k| base = 10; 397| 7.57k| grouping = f->grouping; 398| 7.57k| break; 399| 0| case 'X': ------------------ | Branch (399:2): [True: 0, False: 9.83k] ------------------ 400| 0| conv = "0123456789ABCDEF"; 401| | /* fall through */ 402| 2.26k| case 'x': ------------------ | Branch (402:2): [True: 2.26k, False: 7.57k] ------------------ 403| 2.26k| base = 16; 404| 2.26k| thousands = ":"; 405| 2.26k| break; 406| 0| case 'b': ------------------ | Branch (406:2): [True: 0, False: 9.83k] ------------------ 407| 0| base = 2; 408| 0| thousands = ":"; 409| 0| break; 410| 0| case 'o': ------------------ | Branch (410:2): [True: 0, False: 9.83k] ------------------ 411| 0| base = 8; 412| 0| break; 413| 0| default: ------------------ | Branch (413:2): [True: 0, False: 9.83k] ------------------ 414| 0| return -1; 415| 9.83k| } 416| 9.83k| if(!(fl & FmtUnsigned)){ ------------------ | Branch (416:5): [True: 9.83k, False: 0] ------------------ 417| 9.83k| if(isv && (vlong)vu < 0){ ------------------ | Branch (417:6): [True: 0, False: 9.83k] | Branch (417:13): [True: 0, False: 0] ------------------ 418| 0| vu = -(vlong)vu; 419| 0| neg = 1; 420| 9.83k| }else if(!isv && (long)u < 0){ ------------------ | Branch (420:12): [True: 9.83k, False: 0] | Branch (420:20): [True: 128, False: 9.71k] ------------------ 421| 128| u = -(long)u; 422| 128| neg = 1; 423| 128| } 424| 9.83k| } 425| 9.83k| p = buf + sizeof buf - 1; 426| 9.83k| n = 0; /* in runes */ 427| 9.83k| excess = 0; /* number of bytes > number runes */ 428| 9.83k| ndig = 0; 429| 9.83k| len = utflen(thousands); 430| 9.83k| bytelen = strlen(thousands); 431| 9.83k| if(isv){ ------------------ | Branch (431:5): [True: 0, False: 9.83k] ------------------ 432| 0| while(vu){ ------------------ | Branch (432:9): [True: 0, False: 0] ------------------ 433| 0| i = vu % base; 434| 0| vu /= base; 435| 0| if((fl & FmtComma) && n % 4 == 3){ ------------------ | Branch (435:7): [True: 0, False: 0] | Branch (435:26): [True: 0, False: 0] ------------------ 436| 0| *p-- = ','; 437| 0| n++; 438| 0| } 439| 0| if((fl & FmtApost) && __needsep(&ndig, &grouping)){ ------------------ | Branch (439:7): [True: 0, False: 0] | Branch (439:26): [True: 0, False: 0] ------------------ 440| 0| n += len; 441| 0| excess += bytelen - len; 442| 0| p -= bytelen; 443| 0| memmove(p+1, thousands, bytelen); 444| 0| } 445| 0| *p-- = conv[i]; 446| 0| n++; 447| 0| } 448| 9.83k| }else{ 449| 26.0k| while(u){ ------------------ | Branch (449:9): [True: 16.2k, False: 9.83k] ------------------ 450| 16.2k| i = u % base; 451| 16.2k| u /= base; 452| 16.2k| if((fl & FmtComma) && n % 4 == 3){ ------------------ | Branch (452:7): [True: 0, False: 16.2k] | Branch (452:26): [True: 0, False: 0] ------------------ 453| 0| *p-- = ','; 454| 0| n++; 455| 0| } 456| 16.2k| if((fl & FmtApost) && __needsep(&ndig, &grouping)){ ------------------ | Branch (456:7): [True: 0, False: 16.2k] | Branch (456:26): [True: 0, False: 0] ------------------ 457| 0| n += len; 458| 0| excess += bytelen - len; 459| 0| p -= bytelen; 460| 0| memmove(p+1, thousands, bytelen); 461| 0| } 462| 16.2k| *p-- = conv[i]; 463| 16.2k| n++; 464| 16.2k| } 465| 9.83k| } 466| 9.83k| if(n == 0){ ------------------ | Branch (466:5): [True: 833, False: 9.00k] ------------------ 467| | /* 468| | * "The result of converting a zero value with 469| | * a precision of zero is no characters." - ANSI 470| | * 471| | * "For o conversion, # increases the precision, if and only if 472| | * necessary, to force the first digit of the result to be a zero 473| | * (if the value and precision are both 0, a single 0 is printed)." - ANSI 474| | */ 475| 833| if(!(fl & FmtPrec) || f->prec != 0 || (f->r == 'o' && (fl & FmtSharp))){ ------------------ | Branch (475:6): [True: 725, False: 108] | Branch (475:25): [True: 108, False: 0] | Branch (475:42): [True: 0, False: 0] | Branch (475:57): [True: 0, False: 0] ------------------ 476| 833| *p-- = '0'; 477| 833| n = 1; 478| 833| if(fl & FmtApost) ------------------ | Branch (478:7): [True: 0, False: 833] ------------------ 479| 0| __needsep(&ndig, &grouping); 480| 833| } 481| | 482| | /* 483| | * Zero values don't get 0x. 484| | */ 485| 833| if(f->r == 'x' || f->r == 'X') ------------------ | Branch (485:6): [True: 108, False: 725] | Branch (485:21): [True: 0, False: 725] ------------------ 486| 108| fl &= ~FmtSharp; 487| 833| } 488| 10.6k| for(w = f->prec; n < w && p > buf+3; n++){ ------------------ | Branch (488:19): [True: 851, False: 9.83k] | Branch (488:28): [True: 851, False: 0] ------------------ 489| 851| if((fl & FmtApost) && __needsep(&ndig, &grouping)){ ------------------ | Branch (489:6): [True: 0, False: 851] | Branch (489:25): [True: 0, False: 0] ------------------ 490| 0| n += len; 491| 0| excess += bytelen - len; 492| 0| p -= bytelen; 493| 0| memmove(p+1, thousands, bytelen); 494| 0| } 495| 851| *p-- = '0'; 496| 851| } 497| 9.83k| if(neg || (fl & (FmtSign|FmtSpace))) ------------------ | Branch (497:5): [True: 128, False: 9.71k] | Branch (497:12): [True: 0, False: 9.71k] ------------------ 498| 128| n++; 499| 9.83k| if(fl & FmtSharp){ ------------------ | Branch (499:5): [True: 0, False: 9.83k] ------------------ 500| 0| if(base == 16) ------------------ | Branch (500:6): [True: 0, False: 0] ------------------ 501| 0| n += 2; 502| 0| else if(base == 8){ ------------------ | Branch (502:11): [True: 0, False: 0] ------------------ 503| 0| if(p[1] == '0') ------------------ | Branch (503:7): [True: 0, False: 0] ------------------ 504| 0| fl &= ~FmtSharp; 505| 0| else 506| 0| n++; 507| 0| } 508| 0| } 509| 9.83k| if((fl & FmtZero) && !(fl & (FmtLeft|FmtPrec))){ ------------------ | Branch (509:5): [True: 0, False: 9.83k] | Branch (509:23): [True: 0, False: 0] ------------------ 510| 0| w = 0; 511| 0| if(fl & FmtWidth) ------------------ | Branch (511:6): [True: 0, False: 0] ------------------ 512| 0| w = f->width; 513| 0| for(; n < w && p > buf+3; n++){ ------------------ | Branch (513:9): [True: 0, False: 0] | Branch (513:18): [True: 0, False: 0] ------------------ 514| 0| if((fl & FmtApost) && __needsep(&ndig, &grouping)){ ------------------ | Branch (514:7): [True: 0, False: 0] | Branch (514:26): [True: 0, False: 0] ------------------ 515| 0| n += len; 516| 0| excess += bytelen - len; 517| 0| p -= bytelen; 518| 0| memmove(p+1, thousands, bytelen); 519| 0| } 520| 0| *p-- = '0'; 521| 0| } 522| 0| f->flags &= ~FmtWidth; 523| 0| } 524| 9.83k| if(fl & FmtSharp){ ------------------ | Branch (524:5): [True: 0, False: 9.83k] ------------------ 525| 0| if(base == 16) ------------------ | Branch (525:6): [True: 0, False: 0] ------------------ 526| 0| *p-- = f->r; 527| 0| if(base == 16 || base == 8) ------------------ | Branch (527:6): [True: 0, False: 0] | Branch (527:20): [True: 0, False: 0] ------------------ 528| 0| *p-- = '0'; 529| 0| } 530| 9.83k| if(neg) ------------------ | Branch (530:5): [True: 128, False: 9.71k] ------------------ 531| 128| *p-- = '-'; 532| 9.71k| else if(fl & FmtSign) ------------------ | Branch (532:10): [True: 0, False: 9.71k] ------------------ 533| 0| *p-- = '+'; 534| 9.71k| else if(fl & FmtSpace) ------------------ | Branch (534:10): [True: 0, False: 9.71k] ------------------ 535| 0| *p-- = ' '; 536| 9.83k| f->flags &= ~FmtPrec; 537| 9.83k| return __fmtcpy(f, p + 1, n, n + excess); 538| 9.83k|} __fmtdispatch: 156| 19.6k|{ 157| 19.6k| Rune rune, r; 158| 19.6k| int i, n; 159| | 160| 19.6k| f->flags = 0; 161| 19.6k| f->width = f->prec = 0; 162| | 163| 24.1k| for(;;){ 164| 24.1k| if(isrunes){ ------------------ | Branch (164:6): [True: 0, False: 24.1k] ------------------ 165| 0| r = *(Rune*)fmt; 166| 0| fmt = (Rune*)fmt + 1; 167| 24.1k| }else{ 168| 24.1k| fmt = (char*)fmt + chartorune(&rune, (char*)fmt); 169| 24.1k| r = rune; 170| 24.1k| } 171| 24.1k| f->r = r; 172| 24.1k| switch(r){ ------------------ | Branch (172:10): [True: 4.52k, False: 19.6k] ------------------ 173| 0| case '\0': ------------------ | Branch (173:3): [True: 0, False: 24.1k] ------------------ 174| 0| return nil; ------------------ | | 34| 0|#define nil 0 ------------------ 175| 2.26k| case '.': ------------------ | Branch (175:3): [True: 2.26k, False: 21.9k] ------------------ 176| 2.26k| f->flags |= FmtWidth|FmtPrec; 177| 2.26k| continue; 178| 0| case '0': ------------------ | Branch (178:3): [True: 0, False: 24.1k] ------------------ 179| 0| if(!(f->flags & FmtWidth)){ ------------------ | Branch (179:7): [True: 0, False: 0] ------------------ 180| 0| f->flags |= FmtZero; 181| 0| continue; 182| 0| } 183| | /* fall through */ 184| 2.26k| case '1': case '2': case '3': case '4': ------------------ | Branch (184:3): [True: 0, False: 24.1k] | Branch (184:13): [True: 2.26k, False: 21.9k] | Branch (184:23): [True: 0, False: 24.1k] | Branch (184:33): [True: 0, False: 24.1k] ------------------ 185| 2.26k| case '5': case '6': case '7': case '8': case '9': ------------------ | Branch (185:3): [True: 0, False: 24.1k] | Branch (185:13): [True: 0, False: 24.1k] | Branch (185:23): [True: 0, False: 24.1k] | Branch (185:33): [True: 0, False: 24.1k] | Branch (185:43): [True: 0, False: 24.1k] ------------------ 186| 2.26k| i = 0; 187| 4.52k| while(r >= '0' && r <= '9'){ ------------------ | Branch (187:10): [True: 4.52k, False: 0] | Branch (187:22): [True: 2.26k, False: 2.26k] ------------------ 188| 2.26k| i = i * 10 + r - '0'; 189| 2.26k| if(isrunes){ ------------------ | Branch (189:8): [True: 0, False: 2.26k] ------------------ 190| 0| r = *(Rune*)fmt; 191| 0| fmt = (Rune*)fmt + 1; 192| 2.26k| }else{ 193| 2.26k| r = *(char*)fmt; 194| 2.26k| fmt = (char*)fmt + 1; 195| 2.26k| } 196| 2.26k| } 197| 2.26k| if(isrunes) ------------------ | Branch (197:7): [True: 0, False: 2.26k] ------------------ 198| 0| fmt = (Rune*)fmt - 1; 199| 2.26k| else 200| 2.26k| fmt = (char*)fmt - 1; 201| 2.26k| numflag: 202| 2.26k| if(f->flags & FmtWidth){ ------------------ | Branch (202:7): [True: 2.26k, False: 0] ------------------ 203| 2.26k| f->flags |= FmtPrec; 204| 2.26k| f->prec = i; 205| 2.26k| }else{ 206| 0| f->flags |= FmtWidth; 207| 0| f->width = i; 208| 0| } 209| 2.26k| continue; 210| 0| case '*': ------------------ | Branch (210:3): [True: 0, False: 24.1k] ------------------ 211| 0| i = va_arg(f->args, int); 212| 0| if(i < 0){ ------------------ | Branch (212:7): [True: 0, False: 0] ------------------ 213| | /* 214| | * negative precision => 215| | * ignore the precision. 216| | */ 217| 0| if(f->flags & FmtPrec){ ------------------ | Branch (217:8): [True: 0, False: 0] ------------------ 218| 0| f->flags &= ~FmtPrec; 219| 0| f->prec = 0; 220| 0| continue; 221| 0| } 222| 0| i = -i; 223| 0| f->flags |= FmtLeft; 224| 0| } 225| 0| goto numflag; 226| 24.1k| } 227| 19.6k| n = (*fmtfmt(r))(f); 228| 19.6k| if(n < 0) ------------------ | Branch (228:6): [True: 0, False: 19.6k] ------------------ 229| 0| return nil; ------------------ | | 34| 0|#define nil 0 ------------------ 230| 19.6k| if(n == 0) ------------------ | Branch (230:6): [True: 19.6k, False: 0] ------------------ 231| 19.6k| return fmt; 232| 19.6k| } 233| 19.6k|} fmt.c:fmtfmt: 143| 19.6k|{ 144| 19.6k| Convfmt *p, *ep; 145| | 146| 19.6k| ep = &fmtalloc.fmt[atomic_load(&fmtalloc.nfmt)]; 147| 130k| for(p=ep; p-- > fmtalloc.fmt; ) ------------------ | Branch (147:12): [True: 130k, False: 0] ------------------ 148| 130k| if(p->c == c) ------------------ | Branch (148:6): [True: 19.6k, False: 110k] ------------------ 149| 19.6k| return p->fmt; 150| | 151| 0| return __badfmt; 152| 19.6k|} fmtfdinit: 25| 29.4k|{ 26| 29.4k| f->runes = 0; 27| 29.4k| f->start = buf; 28| 29.4k| f->to = buf; 29| 29.4k| f->stop = buf + size; 30| 29.4k| f->flush = __fmtFdFlush; 31| 29.4k| f->farg = (void*)(uintptr_t)fd; 32| 29.4k| f->flags = 0; 33| 29.4k| f->nfmt = 0; 34| 29.4k| fmtlocaleinit(f, nil, nil, nil); ------------------ | | 34| 29.4k|#define nil 0 ------------------ fmtlocaleinit(f, nil, nil, nil); ------------------ | | 34| 29.4k|#define nil 0 ------------------ fmtlocaleinit(f, nil, nil, nil); ------------------ | | 34| 29.4k|#define nil 0 ------------------ 35| 29.4k| return 0; 36| 29.4k|} __fmtFdFlush: 14| 34.4k|{ 15| 34.4k| int n; 16| | 17| 34.4k| n = (char*)f->to - (char*)f->start; 18| 34.4k| if(n && write((uintptr)f->farg, f->start, n) != n) ------------------ | Branch (18:5): [True: 34.4k, False: 0] | Branch (18:10): [True: 0, False: 34.4k] ------------------ 19| 0| return 0; 20| 34.4k| f->to = f->start; 21| 34.4k| return 1; 22| 34.4k|} fmtlocaleinit: 18| 30.9k|{ 19| 30.9k| if(decimal == nil || decimal[0] == '\0') ------------------ | | 34| 61.9k|#define nil 0 ------------------ | Branch (19:5): [True: 30.9k, False: 0] | Branch (19:23): [True: 0, False: 0] ------------------ 20| 30.9k| decimal = "."; 21| 30.9k| if(thousands == nil) ------------------ | | 34| 30.9k|#define nil 0 ------------------ | Branch (21:5): [True: 30.9k, False: 0] ------------------ 22| 30.9k| thousands = ","; 23| 30.9k| if(grouping == nil) ------------------ | | 34| 30.9k|#define nil 0 ------------------ | Branch (23:5): [True: 30.9k, False: 0] ------------------ 24| 30.9k| grouping = "\3"; 25| 30.9k| f->decimal = decimal; 26| 30.9k| f->thousands = thousands; 27| 30.9k| f->grouping = grouping; 28| 30.9k|} fmtstrflush: 10| 1.50k|{ 11| 1.50k| if(f->start == nil) ------------------ | | 34| 1.50k|#define nil 0 ------------------ | Branch (11:5): [True: 0, False: 1.50k] ------------------ 12| 0| return nil; ------------------ | | 34| 0|#define nil 0 ------------------ 13| 1.50k| *(char*)f->to = '\0'; 14| 1.50k| f->to = f->start; 15| 1.50k| return (char*)f->start; 16| 1.50k|} print: 9| 29.4k|{ 10| 29.4k| int n; 11| 29.4k| va_list args; 12| | 13| 29.4k| va_start(args, fmt); 14| 29.4k| n = vfprint(1, fmt, args); 15| | va_end(args); 16| 29.4k| return n; 17| 29.4k|} smprint: 9| 1.50k|{ 10| 1.50k| va_list args; 11| 1.50k| char *p; 12| | 13| 1.50k| va_start(args, fmt); 14| 1.50k| p = vsmprint(fmt, args); 15| | va_end(args); 16| 1.50k| return p; 17| 1.50k|} vfprint: 9| 29.4k|{ 10| 29.4k| Fmt f; 11| 29.4k| char buf[256]; 12| 29.4k| int n; 13| | 14| 29.4k| fmtfdinit(&f, fd, buf, sizeof(buf)); 15| 29.4k| VA_COPY(f.args,args); ------------------ | | 99| 29.4k|# define VA_COPY(a,b) va_copy(a,b) ------------------ 16| 29.4k| n = dofmt(&f, fmt); 17| 29.4k| VA_END(f.args); ------------------ | | 100| 29.4k|# define VA_END(a) va_end(a) ------------------ 18| 29.4k| if(n > 0 && __fmtFdFlush(&f) == 0) ------------------ | Branch (18:5): [True: 29.4k, False: 0] | Branch (18:14): [True: 0, False: 29.4k] ------------------ 19| 0| return -1; 20| 29.4k| return n; 21| 29.4k|} fmtstrinit: 46| 1.50k|{ 47| 1.50k| int n; 48| | 49| 1.50k| memset(f, 0, sizeof *f); 50| 1.50k| f->runes = 0; 51| 1.50k| n = 32; 52| 1.50k| f->start = malloc(n); ------------------ | | 137| 1.50k|#define malloc p9malloc ------------------ 53| 1.50k| if(f->start == nil) ------------------ | | 24| 1.50k|#define nil ((void*)0) ------------------ | Branch (53:5): [True: 0, False: 1.50k] ------------------ 54| 0| return -1; 55| 1.50k| f->to = f->start; 56| 1.50k| f->stop = (char*)f->start + n - 1; 57| 1.50k| f->flush = fmtStrFlush; 58| 1.50k| f->farg = (void*)(uintptr)n; 59| 1.50k| f->nfmt = 0; 60| 1.50k| fmtlocaleinit(f, nil, nil, nil); ------------------ | | 24| 1.50k|#define nil ((void*)0) ------------------ fmtlocaleinit(f, nil, nil, nil); ------------------ | | 24| 1.50k|#define nil ((void*)0) ------------------ fmtlocaleinit(f, nil, nil, nil); ------------------ | | 24| 1.50k|#define nil ((void*)0) ------------------ 61| 1.50k| return 0; 62| 1.50k|} vsmprint: 69| 1.50k|{ 70| 1.50k| Fmt f; 71| 1.50k| int n; 72| | 73| 1.50k| if(fmtstrinit(&f) < 0) ------------------ | Branch (73:5): [True: 0, False: 1.50k] ------------------ 74| 0| return nil; ------------------ | | 24| 0|#define nil ((void*)0) ------------------ 75| 1.50k| VA_COPY(f.args,args); ------------------ | | 99| 1.50k|# define VA_COPY(a,b) va_copy(a,b) ------------------ 76| 1.50k| n = dofmt(&f, fmt); 77| 1.50k| VA_END(f.args); ------------------ | | 100| 1.50k|# define VA_END(a) va_end(a) ------------------ 78| 1.50k| if(n < 0){ ------------------ | Branch (78:5): [True: 0, False: 1.50k] ------------------ 79| 0| free(f.start); ------------------ | | 140| 0|#define free p9free ------------------ 80| 0| return nil; ------------------ | | 24| 0|#define nil ((void*)0) ------------------ 81| 0| } 82| 1.50k| return fmtstrflush(&f); 83| 1.50k|} p9malloc: 13| 27.8k|{ 14| 27.8k| if(n == 0) ------------------ | Branch (14:5): [True: 0, False: 27.8k] ------------------ 15| 0| n++; 16| 27.8k| return malloc(n); 17| 27.8k|} p9free: 21| 2.87k|{ 22| 2.87k| free(v); 23| 2.87k|} chartorune: 48| 722k|{ 49| 722k| int c, c1, c2, c3; 50| 722k| long l; 51| | 52| | /* 53| | * one character sequence 54| | * 00000-0007F => T1 55| | */ 56| 722k| c = *(uchar*)str; 57| 722k| if(c < Tx) { ------------------ | Branch (57:5): [True: 24.1k, False: 697k] ------------------ 58| 24.1k| *rune = c; 59| 24.1k| return 1; 60| 24.1k| } 61| | 62| | /* 63| | * two character sequence 64| | * 0080-07FF => T2 Tx 65| | */ 66| 697k| c1 = *(uchar*)(str+1) ^ Tx; 67| 697k| if(c1 & Testx) ------------------ | Branch (67:5): [True: 493k, False: 204k] ------------------ 68| 493k| goto bad; 69| 204k| if(c < T3) { ------------------ | Branch (69:5): [True: 145k, False: 59.1k] ------------------ 70| 145k| if(c < T2) ------------------ | Branch (70:6): [True: 102k, False: 42.7k] ------------------ 71| 102k| goto bad; 72| 42.7k| l = ((c << Bitx) | c1) & Rune2; 73| 42.7k| if(l <= Rune1) ------------------ | Branch (73:6): [True: 5.54k, False: 37.2k] ------------------ 74| 5.54k| goto bad; 75| 37.2k| *rune = l; 76| 37.2k| return 2; 77| 42.7k| } 78| | 79| | /* 80| | * three character sequence 81| | * 0800-FFFF => T3 Tx Tx 82| | */ 83| 59.1k| c2 = *(uchar*)(str+2) ^ Tx; 84| 59.1k| if(c2 & Testx) ------------------ | Branch (84:5): [True: 17.1k, False: 41.9k] ------------------ 85| 17.1k| goto bad; 86| 41.9k| if(c < T4) { ------------------ | Branch (86:5): [True: 12.4k, False: 29.5k] ------------------ 87| 12.4k| l = ((((c << Bitx) | c1) << Bitx) | c2) & Rune3; 88| 12.4k| if(l <= Rune2) ------------------ | Branch (88:6): [True: 9.02k, False: 3.37k] ------------------ 89| 9.02k| goto bad; 90| 3.37k| *rune = l; 91| 3.37k| return 3; 92| 12.4k| } 93| | 94| | /* 95| | * four character sequence 96| | * 10000-10FFFF => T4 Tx Tx Tx 97| | */ 98| 29.5k| if(UTFmax >= 4) { ------------------ | Branch (98:5): [True: 29.5k, Folded] ------------------ 99| 29.5k| c3 = *(uchar*)(str+3) ^ Tx; 100| 29.5k| if(c3 & Testx) ------------------ | Branch (100:6): [True: 7.38k, False: 22.1k] ------------------ 101| 7.38k| goto bad; 102| 22.1k| if(c < T5) { ------------------ | Branch (102:6): [True: 19.8k, False: 2.31k] ------------------ 103| 19.8k| l = ((((((c << Bitx) | c1) << Bitx) | c2) << Bitx) | c3) & Rune4; 104| 19.8k| if(l <= Rune3) ------------------ | Branch (104:7): [True: 7.66k, False: 12.1k] ------------------ 105| 7.66k| goto bad; 106| 12.1k| if(l > Runemax) ------------------ | Branch (106:7): [True: 1.24k, False: 10.9k] ------------------ 107| 1.24k| goto bad; 108| 10.9k| *rune = l; 109| 10.9k| return 4; 110| 12.1k| } 111| 22.1k| } 112| | 113| | /* 114| | * bad decoding 115| | */ 116| 646k|bad: 117| 646k| *rune = Bad; 118| 646k| return 1; 119| 29.5k|} runetochar: 123| 357k|{ 124| 357k| long c; 125| | 126| | /* 127| | * one character sequence 128| | * 00000-0007F => 00-7F 129| | */ 130| 357k| c = *rune; 131| 357k| if(c <= Rune1) { ------------------ | Branch (131:5): [True: 3.96k, False: 353k] ------------------ 132| 3.96k| str[0] = c; 133| 3.96k| return 1; 134| 3.96k| } 135| | 136| | /* 137| | * two character sequence 138| | * 00080-007FF => T2 Tx 139| | */ 140| 353k| if(c <= Rune2) { ------------------ | Branch (140:5): [True: 18.9k, False: 334k] ------------------ 141| 18.9k| str[0] = T2 | (c >> 1*Bitx); 142| 18.9k| str[1] = Tx | (c & Maskx); 143| 18.9k| return 2; 144| 18.9k| } 145| | 146| | /* 147| | * three character sequence 148| | * 00800-0FFFF => T3 Tx Tx 149| | */ 150| 334k| if(c > Runemax) ------------------ | Branch (150:5): [True: 0, False: 334k] ------------------ 151| 0| c = Runeerror; 152| 334k| if(c <= Rune3) { ------------------ | Branch (152:5): [True: 329k, False: 5.58k] ------------------ 153| 329k| str[0] = T3 | (c >> 2*Bitx); 154| 329k| str[1] = Tx | ((c >> 1*Bitx) & Maskx); 155| 329k| str[2] = Tx | (c & Maskx); 156| 329k| return 3; 157| 329k| } 158| | 159| | /* 160| | * four character sequence 161| | * 010000-1FFFFF => T4 Tx Tx Tx 162| | */ 163| 5.58k| str[0] = T4 | (c >> 3*Bitx); 164| 5.58k| str[1] = Tx | ((c >> 2*Bitx) & Maskx); 165| 5.58k| str[2] = Tx | ((c >> 1*Bitx) & Maskx); 166| 5.58k| str[3] = Tx | (c & Maskx); 167| 5.58k| return 4; 168| 334k|} runelen: 172| 9.01k|{ 173| 9.01k| Rune rune; 174| 9.01k| char str[10]; 175| | 176| 9.01k| rune = c; 177| 9.01k| return runetochar(str, &rune); 178| 9.01k|} fullrune: 204| 448|{ 205| 448| int c; 206| | 207| 448| if(n <= 0) ------------------ | Branch (207:5): [True: 0, False: 448] ------------------ 208| 0| return 0; 209| 448| c = *(uchar*)str; 210| 448| if(c < Tx) ------------------ | Branch (210:5): [True: 0, False: 448] ------------------ 211| 0| return 1; 212| 448| if(c < T3) ------------------ | Branch (212:5): [True: 284, False: 164] ------------------ 213| 284| return n >= 2; 214| 164| if(UTFmax == 3 || c < T4) ------------------ | Branch (214:5): [Folded, False: 164] | Branch (214:20): [True: 67, False: 97] ------------------ 215| 67| return n >= 3; 216| 97| return n >= 4; 217| 164|} utflen: 21| 19.6k|{ 22| 19.6k| int c; 23| 19.6k| long n; 24| 19.6k| Rune rune; 25| | 26| 19.6k| n = 0; 27| 700k| for(;;) { 28| 700k| c = *(uchar*)s; 29| 700k| if(c < Runeself) { ------------------ | Branch (29:6): [True: 351k, False: 349k] ------------------ 30| 351k| if(c == 0) ------------------ | Branch (30:7): [True: 19.6k, False: 331k] ------------------ 31| 19.6k| return n; 32| 331k| s++; 33| 331k| } else 34| 349k| s += chartorune(&rune, s); 35| 680k| n++; 36| 680k| } 37| 19.6k|} asn1dump: 2550| 933|{ 2551| 933| Elem e; 2552| | 2553| 933| if(decode(der, len, &e) != ASN_OK){ ------------------ | Branch (2553:5): [True: 474, False: 459] ------------------ 2554| | //print("didn't parse\n"); 2555| | //exits("didn't parse"); 2556| 474| return; 2557| 474| } 2558| 459| edump(e); 2559| 459|} x509.c:makebytes: 1300| 5.55k|{ 1301| 5.55k| Bytes* ans; 1302| | 1303| 5.55k| ans = newbytes(len); 1304| 5.55k| memmove(ans->data, buf, len); 1305| 5.55k| return ans; 1306| 5.55k|} x509.c:newbytes: 1287| 6.48k|{ 1288| 6.48k| Bytes* ans; 1289| | 1290| | ans = (Bytes*)emalloc(OFFSETOF(data[0], Bytes) + len); ------------------ | | 9| 6.48k|#define OFFSETOF(a, b) offsetof(b, a) ------------------ 1291| 6.48k| ans->len = len; 1292| 6.48k| return ans; 1293| 6.48k|} x509.c:emalloc: 168| 25.3k|{ 169| 25.3k| void *p; 170| 25.3k| if(n==0) ------------------ | Branch (170:5): [True: 0, False: 25.3k] ------------------ 171| 0| n=1; 172| 25.3k| p = malloc(n); ------------------ | | 137| 25.3k|#define malloc p9malloc ------------------ 173| 25.3k| if(p == nil){ ------------------ | | 24| 25.3k|#define nil ((void*)0) ------------------ | Branch (173:5): [True: 0, False: 25.3k] ------------------ 174| 0| exits("out of memory"); 175| 0| } 176| 25.3k| memset(p, 0, n); 177| 25.3k| return p; 178| 25.3k|} x509.c:freebytes: 1310| 1.51k|{ 1311| 1.51k| if(b != nil) ------------------ | | 24| 1.51k|#define nil ((void*)0) ------------------ | Branch (1311:5): [True: 890, False: 628] ------------------ 1312| 890| free(b); ------------------ | | 140| 890|#define free p9free ------------------ 1313| 1.51k|} x509.c:tag_decode: 282| 161k|{ 283| 161k| int err; 284| 161k| int v; 285| 161k| uchar* p; 286| | 287| 161k| err = ASN_OK; 288| 161k| p = *pp; 289| 161k| if(pend-p >= 2) { ------------------ | Branch (289:5): [True: 161k, False: 48] ------------------ 290| 161k| v = *p++; 291| 161k| ptag->class = v&CLASS_MASK; ------------------ | | 150| 161k|#define CLASS_MASK 0xC0 ------------------ 292| 161k| if(v&CONSTR_MASK) ------------------ | | 149| 161k|#define CONSTR_MASK 0x20 ------------------ | Branch (292:6): [True: 147k, False: 13.2k] ------------------ 293| 147k| *pisconstr = 1; 294| 13.2k| else 295| 13.2k| *pisconstr = 0; 296| 161k| v &= TAG_MASK; ------------------ | | 148| 161k|#define TAG_MASK 0x1F ------------------ 297| 161k| if(v == TAG_MASK) ------------------ | | 148| 161k|#define TAG_MASK 0x1F ------------------ | Branch (297:6): [True: 357, False: 160k] ------------------ 298| 357| err = uint7_decode(&p, pend, &v); 299| 161k| ptag->num = v; 300| 161k| } 301| 48| else 302| 48| err = ASN_ESHORT; 303| 161k| *pp = p; 304| 161k| return err; 305| 161k|} x509.c:uint7_decode: 599| 3.05k|{ 600| 3.05k| int err; 601| 3.05k| int num; 602| 3.05k| int more; 603| 3.05k| int v; 604| 3.05k| uchar* p; 605| | 606| 3.05k| p = *pp; 607| 3.05k| err = ASN_OK; 608| 3.05k| num = 0; 609| 3.05k| more = 1; 610| 6.69k| while(more && p < pend) { ------------------ | Branch (610:8): [True: 3.66k, False: 3.03k] | Branch (610:16): [True: 3.65k, False: 11] ------------------ 611| 3.65k| v = *p++; 612| 3.65k| if(num&0x7F000000) { ------------------ | Branch (612:6): [True: 8, False: 3.64k] ------------------ 613| 8| err = ASN_ETOOBIG; 614| 8| break; 615| 8| } 616| 3.64k| num <<= 7; 617| 3.64k| more = v&0x80; 618| 3.64k| num |= (v&0x7F); 619| 3.64k| } 620| 3.05k| if(p == pend) ------------------ | Branch (620:5): [True: 30, False: 3.02k] ------------------ 621| 30| err = ASN_ESHORT; 622| 3.05k| *pint = num; 623| 3.05k| *pp = p; 624| 3.05k| return err; 625| 3.05k|} x509.c:length_decode: 310| 161k|{ 311| 161k| int err; 312| 161k| int num; 313| 161k| int v; 314| 161k| uchar* p; 315| | 316| 161k| err = ASN_OK; 317| 161k| num = 0; 318| 161k| p = *pp; 319| 161k| if(p < pend) { ------------------ | Branch (319:5): [True: 161k, False: 0] ------------------ 320| 161k| v = *p++; 321| 161k| if(v&0x80) ------------------ | Branch (321:6): [True: 2.14k, False: 158k] ------------------ 322| 2.14k| err = int_decode(&p, pend, v&0x7F, 1, &num); 323| 158k| else 324| 158k| num = v; 325| 161k| } 326| 0| else 327| 0| err = ASN_ESHORT; 328| 161k| *pp = p; 329| 161k| *plength = num; 330| 161k| return err; 331| 161k|} x509.c:int_decode: 565| 3.51k|{ 566| 3.51k| int err; 567| 3.51k| int num; 568| 3.51k| uchar* p; 569| | 570| 3.51k| p = *pp; 571| 3.51k| err = ASN_OK; 572| 3.51k| num = 0; 573| 3.51k| if(p+count <= pend) { ------------------ | Branch (573:5): [True: 3.50k, False: 15] ------------------ 574| 3.50k| if((count > 4) || (unsgned && count == 4 && (*p&0x80))) ------------------ | Branch (574:6): [True: 12, False: 3.49k] | Branch (574:22): [True: 2.12k, False: 1.37k] | Branch (574:33): [True: 137, False: 1.98k] | Branch (574:47): [True: 7, False: 130] ------------------ 575| 19| err = ASN_ETOOBIG; 576| 3.48k| else { 577| 3.48k| if(!unsgned && count > 0 && count < 4 && (*p&0x80)) ------------------ | Branch (577:7): [True: 1.37k, False: 2.11k] | Branch (577:19): [True: 998, False: 372] | Branch (577:32): [True: 918, False: 80] | Branch (577:45): [True: 150, False: 768] ------------------ 578| 150| num = -1; /* set all bits, initially */ 579| 6.84k| while(count--) ------------------ | Branch (579:10): [True: 3.36k, False: 3.48k] ------------------ 580| 3.36k| num = (num << 8)|(*p++); 581| 3.48k| } 582| 3.50k| } 583| 15| else 584| 15| err = ASN_ESHORT; 585| 3.51k| *pint = num; 586| 3.51k| *pp = p; 587| 3.51k| return err; 588| 3.51k|} x509.c:ber_decode: 255| 161k|{ 256| 161k| int err; 257| 161k| int isconstr; 258| 161k| int length; 259| 161k| Tag tag; 260| 161k| Value val; 261| | 262| 161k| err = tag_decode(pp, pend, &tag, &isconstr); 263| 161k| if(err == ASN_OK) { ------------------ | Branch (263:5): [True: 161k, False: 68] ------------------ 264| 161k| err = length_decode(pp, pend, &length); 265| 161k| if(err == ASN_OK) { ------------------ | Branch (265:6): [True: 161k, False: 34] ------------------ 266| 161k| if(tag.class == Universal) ------------------ | | 28| 161k|#define Universal 0 ------------------ | Branch (266:7): [True: 159k, False: 1.56k] ------------------ 267| 159k| err = value_decode(pp, pend, length, tag.num, isconstr, &val); 268| 1.56k| else 269| 1.56k| err = value_decode(pp, pend, length, OCTET_STRING, 0, &val); ------------------ | | 35| 1.56k|#define OCTET_STRING 4 ------------------ 270| 161k| if(err == ASN_OK) { ------------------ | Branch (270:7): [True: 18.5k, False: 142k] ------------------ 271| 18.5k| pelem->tag = tag; 272| 18.5k| pelem->val = val; 273| 18.5k| } 274| 161k| } 275| 161k| } 276| 161k| return err; 277| 161k|} x509.c:value_decode: 336| 161k|{ 337| 161k| int err; 338| 161k| Bytes* va; 339| 161k| int num; 340| 161k| int bitsunused; 341| 161k| int subids[MAXOBJIDLEN]; 342| 161k| int isubid; 343| 161k| Elist* vl; 344| 161k| uchar* p; 345| 161k| uchar* pe; 346| | 347| 161k| err = ASN_OK; 348| 161k| p = *pp; 349| 161k| if(length == -1) { /* "indefinite" length spec */ ------------------ | Branch (349:5): [True: 0, False: 161k] ------------------ 350| 0| if(!isconstr) ------------------ | Branch (350:6): [True: 0, False: 0] ------------------ 351| 0| err = ASN_EINVAL; 352| 0| } 353| 161k| else if(p + length > pend) ------------------ | Branch (353:10): [True: 169, False: 160k] ------------------ 354| 169| err = ASN_EVALLEN; 355| 161k| if(err != ASN_OK) ------------------ | Branch (355:5): [True: 169, False: 160k] ------------------ 356| 169| return err; 357| | 358| 160k| switch(kind) { 359| 5.37k| case 0: ------------------ | Branch (359:2): [True: 5.37k, False: 155k] ------------------ 360| | /* marker for end of indefinite constructions */ 361| 5.37k| if(length == 0) ------------------ | Branch (361:6): [True: 5.36k, False: 10] ------------------ 362| 5.36k| pval->tag = VNull; 363| 10| else 364| 10| err = ASN_EINVAL; 365| 5.37k| break; 366| | 367| 1.08k| case BOOLEAN: ------------------ | | 32| 1.08k|#define BOOLEAN 1 ------------------ | Branch (367:2): [True: 1.08k, False: 159k] ------------------ 368| 1.08k| if(isconstr) ------------------ | Branch (368:6): [True: 2, False: 1.08k] ------------------ 369| 2| err = ASN_ECONSTR; 370| 1.08k| else if(length != 1) ------------------ | Branch (370:11): [True: 8, False: 1.07k] ------------------ 371| 8| err = ASN_EVALLEN; 372| 1.07k| else { 373| 1.07k| pval->tag = VBool; 374| 1.07k| pval->u.boolval = (*p++ != 0); 375| 1.07k| } 376| 1.08k| break; 377| | 378| 1.46k| case INTEGER: ------------------ | | 33| 1.46k|#define INTEGER 2 ------------------ | Branch (378:2): [True: 1.46k, False: 159k] ------------------ 379| 1.89k| case ENUMERATED: ------------------ | | 41| 1.89k|#define ENUMERATED 10 ------------------ | Branch (379:2): [True: 430, False: 160k] ------------------ 380| 1.89k| if(isconstr) ------------------ | Branch (380:6): [True: 3, False: 1.88k] ------------------ 381| 3| err = ASN_ECONSTR; 382| 1.88k| else if(length <= 4) { ------------------ | Branch (382:11): [True: 1.37k, False: 519] ------------------ 383| 1.37k| err = int_decode(&p, pend, length, 0, &num); 384| 1.37k| if(err == ASN_OK) { ------------------ | Branch (384:7): [True: 1.37k, False: 0] ------------------ 385| 1.37k| pval->tag = VInt; 386| 1.37k| pval->u.intval = num; 387| 1.37k| } 388| 1.37k| } 389| 519| else { 390| 519| pval->tag = VBigInt; 391| 519| pval->u.bigintval = makebytes(p, length); 392| 519| p += length; 393| 519| } 394| 1.89k| break; 395| | 396| 578| case BIT_STRING: ------------------ | | 34| 578|#define BIT_STRING 3 ------------------ | Branch (396:2): [True: 578, False: 160k] ------------------ 397| 578| pval->tag = VBitString; 398| 578| if(isconstr) { ------------------ | Branch (398:6): [True: 4, False: 574] ------------------ 399| 4| if(length == -1 && p + 2 <= pend && *p == 0 && *(p+1) ==0) { ------------------ | Branch (399:7): [True: 0, False: 4] | Branch (399:23): [True: 0, False: 0] | Branch (399:40): [True: 0, False: 0] | Branch (399:51): [True: 0, False: 0] ------------------ 400| 0| pval->u.bitstringval = makebits(0, 0, 0); 401| 0| p += 2; 402| 0| } 403| 4| else 404| | /* TODO: recurse and concat results */ 405| 4| err = ASN_EUNIMPL; 406| 4| } 407| 574| else { 408| 574| if(length < 2) { ------------------ | Branch (408:7): [True: 218, False: 356] ------------------ 409| 218| if(length == 1 && *p == 0) { ------------------ | Branch (409:8): [True: 216, False: 2] | Branch (409:23): [True: 208, False: 8] ------------------ 410| 208| pval->u.bitstringval = makebits(0, 0, 0); 411| 208| p++; 412| 208| } 413| 10| else 414| 10| err = ASN_EINVAL; 415| 218| } 416| 356| else { 417| 356| bitsunused = *p; 418| 356| if(bitsunused > 7) ------------------ | Branch (418:8): [True: 5, False: 351] ------------------ 419| 5| err = ASN_EINVAL; 420| 351| else if(length > 0x0FFFFFFF) ------------------ | Branch (420:13): [True: 0, False: 351] ------------------ 421| 0| err = ASN_ETOOBIG; 422| 351| else { 423| 351| pval->u.bitstringval = makebits(p+1, length-1, bitsunused); 424| 351| p += length; 425| 351| } 426| 356| } 427| 574| } 428| 578| break; 429| | 430| 4.13k| case OCTET_STRING: ------------------ | | 35| 4.13k|#define OCTET_STRING 4 ------------------ | Branch (430:2): [True: 4.13k, False: 156k] ------------------ 431| 27.9k| case ObjectDescriptor: ------------------ | | 38| 27.9k|#define ObjectDescriptor 7 ------------------ | Branch (431:2): [True: 23.8k, False: 137k] ------------------ 432| 27.9k| err = octet_decode(&p, pend, length, isconstr, &va); 433| 27.9k| if(err == ASN_OK) { ------------------ | Branch (433:6): [True: 2.49k, False: 25.4k] ------------------ 434| 2.49k| pval->tag = VOctets; 435| 2.49k| pval->u.octetsval = va; 436| 2.49k| } 437| 27.9k| break; 438| | 439| 198| case NULLTAG: ------------------ | | 36| 198|#define NULLTAG 5 ------------------ | Branch (439:2): [True: 198, False: 160k] ------------------ 440| 198| if(isconstr) ------------------ | Branch (440:6): [True: 3, False: 195] ------------------ 441| 3| err = ASN_ECONSTR; 442| 195| else if(length != 0) ------------------ | Branch (442:11): [True: 4, False: 191] ------------------ 443| 4| err = ASN_EVALLEN; 444| 191| else 445| 191| pval->tag = VNull; 446| 198| break; 447| | 448| 754| case OBJECT_ID: ------------------ | | 37| 754|#define OBJECT_ID 6 ------------------ | Branch (448:2): [True: 754, False: 160k] ------------------ 449| 754| if(isconstr) ------------------ | Branch (449:6): [True: 1, False: 753] ------------------ 450| 1| err = ASN_ECONSTR; 451| 753| else if(length == 0) ------------------ | Branch (451:11): [True: 1, False: 752] ------------------ 452| 1| err = ASN_EVALLEN; 453| 752| else { 454| 752| isubid = 0; 455| 752| pe = p+length; 456| 3.43k| while(p < pe && isubid < MAXOBJIDLEN) { ------------------ | | 151| 2.69k|#define MAXOBJIDLEN 20 ------------------ | Branch (456:10): [True: 2.69k, False: 735] | Branch (456:20): [True: 2.69k, False: 1] ------------------ 457| 2.69k| err = uint7_decode(&p, pend, &num); 458| 2.69k| if(err != ASN_OK) ------------------ | Branch (458:8): [True: 16, False: 2.68k] ------------------ 459| 16| break; 460| 2.68k| if(isubid == 0) { ------------------ | Branch (460:8): [True: 750, False: 1.93k] ------------------ 461| 750| subids[isubid++] = num / 40; 462| 750| subids[isubid++] = num % 40; 463| 750| } 464| 1.93k| else 465| 1.93k| subids[isubid++] = num; 466| 2.68k| } 467| 752| if(err == ASN_OK) { ------------------ | Branch (467:7): [True: 736, False: 16] ------------------ 468| 736| if(p != pe) ------------------ | Branch (468:8): [True: 4, False: 732] ------------------ 469| 4| err = ASN_EVALLEN; 470| 732| else { 471| 732| pval->tag = VObjId; 472| 732| pval->u.objidval = makeints(subids, isubid); 473| 732| } 474| 736| } 475| 752| } 476| 754| break; 477| | 478| 193| case EXTERNAL: ------------------ | | 39| 193|#define EXTERNAL 8 ------------------ | Branch (478:2): [True: 193, False: 160k] ------------------ 479| 391| case EMBEDDED_PDV: ------------------ | | 42| 391|#define EMBEDDED_PDV 11 ------------------ | Branch (479:2): [True: 198, False: 160k] ------------------ 480| | /* TODO: parse this internally */ 481| 391| if(p+length > pend) ------------------ | Branch (481:6): [True: 0, False: 391] ------------------ 482| 0| err = ASN_EVALLEN; 483| 391| else { 484| 391| pval->tag = VOther; 485| 391| pval->u.otherval = makebytes(p, length); 486| 391| p += length; 487| 391| } 488| 391| break; 489| | 490| 351| case REAL: ------------------ | | 40| 351|#define REAL 9 ------------------ | Branch (490:2): [True: 351, False: 160k] ------------------ 491| | /* Let the application decode */ 492| 351| if(isconstr) ------------------ | Branch (492:6): [True: 1, False: 350] ------------------ 493| 1| err = ASN_ECONSTR; 494| 350| else if(p+length > pend) ------------------ | Branch (494:11): [True: 0, False: 350] ------------------ 495| 0| err = ASN_EVALLEN; 496| 350| else { 497| 350| pval->tag = VReal; 498| 350| pval->u.realval = makebytes(p, length); 499| 350| p += length; 500| 350| } 501| 351| break; 502| | 503| 12.7k| case SEQUENCE: ------------------ | | 43| 12.7k|#define SEQUENCE 16 /* also SEQUENCE OF */ ------------------ | Branch (503:2): [True: 12.7k, False: 148k] ------------------ 504| 12.7k| err = seq_decode(&p, pend, length, isconstr, &vl); 505| 12.7k| if(err == ASN_OK) { ------------------ | Branch (505:6): [True: 2.10k, False: 10.6k] ------------------ 506| 2.10k| pval->tag = VSeq ; 507| 2.10k| pval->u.seqval = vl; 508| 2.10k| } 509| 12.7k| break; 510| | 511| 2.93k| case SETOF: ------------------ | | 44| 2.93k|#define SETOF 17 /* also SETOF OF */ ------------------ | Branch (511:2): [True: 2.93k, False: 157k] ------------------ 512| 2.93k| err = seq_decode(&p, pend, length, isconstr, &vl); 513| 2.93k| if(err == ASN_OK) { ------------------ | Branch (513:6): [True: 1.47k, False: 1.46k] ------------------ 514| 1.47k| pval->tag = VSet; 515| 1.47k| pval->u.setval = vl; 516| 1.47k| } 517| 2.93k| break; 518| | 519| 832| case NumericString: ------------------ | | 45| 832|#define NumericString 18 ------------------ | Branch (519:2): [True: 832, False: 160k] ------------------ 520| 1.30k| case PrintableString: ------------------ | | 46| 1.30k|#define PrintableString 19 ------------------ | Branch (520:2): [True: 472, False: 160k] ------------------ 521| 3.62k| case TeletexString: ------------------ | | 47| 3.62k|#define TeletexString 20 ------------------ | Branch (521:2): [True: 2.31k, False: 158k] ------------------ 522| 4.16k| case VideotexString: ------------------ | | 48| 4.16k|#define VideotexString 21 ------------------ | Branch (522:2): [True: 545, False: 160k] ------------------ 523| 4.73k| case IA5String: ------------------ | | 49| 4.73k|#define IA5String 22 ------------------ | Branch (523:2): [True: 568, False: 160k] ------------------ 524| 5.78k| case UTCTime: ------------------ | | 50| 5.78k|#define UTCTime 23 ------------------ | Branch (524:2): [True: 1.04k, False: 159k] ------------------ 525| 6.63k| case GeneralizedTime: ------------------ | | 51| 6.63k|#define GeneralizedTime 24 ------------------ | Branch (525:2): [True: 856, False: 160k] ------------------ 526| 7.14k| case GraphicString: ------------------ | | 52| 7.14k|#define GraphicString 25 ------------------ | Branch (526:2): [True: 504, False: 160k] ------------------ 527| 7.48k| case VisibleString: ------------------ | | 53| 7.48k|#define VisibleString 26 ------------------ | Branch (527:2): [True: 346, False: 160k] ------------------ 528| 8.69k| case GeneralString: ------------------ | | 54| 8.69k|#define GeneralString 27 ------------------ | Branch (528:2): [True: 1.21k, False: 159k] ------------------ 529| 99.9k| case UniversalString: ------------------ | | 55| 99.9k|#define UniversalString 28 ------------------ | Branch (529:2): [True: 91.2k, False: 69.6k] ------------------ 530| 105k| case BMPString: ------------------ | | 56| 105k|#define BMPString 30 ------------------ | Branch (530:2): [True: 5.79k, False: 155k] ------------------ 531| | /* TODO: figure out when character set conversion is necessary */ 532| 105k| err = octet_decode(&p, pend, length, isconstr, &va); 533| 105k| if(err == ASN_OK) { ------------------ | Branch (533:6): [True: 1.05k, False: 104k] ------------------ 534| 1.05k| pval->tag = VString; 535| 1.05k| pval->u.stringval = (char*)emalloc(va->len+1); 536| 1.05k| memmove(pval->u.stringval, va->data, va->len); 537| 1.05k| pval->u.stringval[va->len] = 0; 538| 1.05k| free(va); ------------------ | | 140| 1.05k|#define free p9free ------------------ 539| 1.05k| } 540| 105k| break; 541| | 542| 872| default: ------------------ | Branch (542:2): [True: 872, False: 160k] ------------------ 543| 872| if(p+length > pend) ------------------ | Branch (543:6): [True: 0, False: 872] ------------------ 544| 0| err = ASN_EVALLEN; 545| 872| else { 546| 872| pval->tag = VOther; 547| 872| pval->u.otherval = makebytes(p, length); 548| 872| p += length; 549| 872| } 550| 872| break; 551| 160k| } 552| 160k| *pp = p; 553| 160k| return err; 554| 160k|} x509.c:makebits: 1387| 559|{ 1388| 559| Bits* ans; 1389| | 1390| 559| ans = newbits(len); 1391| 559| memmove(ans->data, buf, len); 1392| 559| ans->unusedbits = unusedbits; 1393| 559| return ans; 1394| 559|} x509.c:newbits: 1376| 559|{ 1377| 559| Bits* ans; 1378| | 1379| | ans = (Bits*)emalloc(OFFSETOF(data[0], Bits) + len); ------------------ | | 9| 559|#define OFFSETOF(a, b) offsetof(b, a) ------------------ 1380| 559| ans->len = len; 1381| 559| ans->unusedbits = 0; 1382| 559| return ans; 1383| 559|} x509.c:octet_decode: 634| 133k|{ 635| 133k| int err; 636| 133k| uchar* p; 637| 133k| Bytes* ans; 638| 133k| Bytes* newans; 639| 133k| uchar* pstart; 640| 133k| uchar* pold; 641| 133k| Elem elem; 642| | 643| 133k| err = ASN_OK; 644| 133k| p = *pp; 645| 133k| ans = nil; ------------------ | | 24| 133k|#define nil ((void*)0) ------------------ 646| 133k| if(length >= 0 && !isconstr) { ------------------ | Branch (646:5): [True: 133k, False: 0] | Branch (646:20): [True: 2.83k, False: 130k] ------------------ 647| 2.83k| ans = makebytes(p, length); 648| 2.83k| p += length; 649| 2.83k| } 650| 130k| else { 651| | /* constructed, either definite or indefinite length */ 652| 130k| pstart = p; 653| 132k| for(;;) { 654| 132k| if(length >= 0 && p >= pstart + length) { ------------------ | Branch (654:7): [True: 132k, False: 0] | Branch (654:22): [True: 758, False: 131k] ------------------ 655| 758| if(p != pstart + length) ------------------ | Branch (655:8): [True: 48, False: 710] ------------------ 656| 48| err = ASN_EVALLEN; 657| 758| break; 658| 758| } 659| 131k| pold = p; 660| 131k| err = ber_decode(&p, pend, &elem); 661| 131k| if(err != ASN_OK) ------------------ | Branch (661:7): [True: 130k, False: 1.56k] ------------------ 662| 130k| break; 663| 1.56k| switch(elem.val.tag) { 664| 1.51k| case VOctets: ------------------ | Branch (664:4): [True: 1.51k, False: 42] ------------------ 665| 1.51k| newans = catbytes(ans, elem.val.u.octetsval); 666| 1.51k| freebytes(ans); 667| 1.51k| ans = newans; 668| 1.51k| break; 669| | 670| 0| case VEOC: ------------------ | Branch (670:4): [True: 0, False: 1.56k] ------------------ 671| 0| if(length != -1) { ------------------ | Branch (671:8): [True: 0, False: 0] ------------------ 672| 0| p = pold; 673| 0| err = ASN_EINVAL; 674| 0| } 675| 0| goto cloop_done; 676| | 677| 42| default: ------------------ | Branch (677:4): [True: 42, False: 1.51k] ------------------ 678| 42| p = pold; 679| 42| err = ASN_EINVAL; 680| 42| goto cloop_done; 681| 1.56k| } 682| 1.56k| } 683| 130k|cloop_done: 684| 130k| ; 685| 130k| } 686| 133k| *pp = p; 687| 133k| *pbytes = ans; 688| 133k| return err; 689| 133k|} x509.c:catbytes: 1321| 1.51k|{ 1322| 1.51k| Bytes* ans; 1323| 1.51k| int n; 1324| | 1325| 1.51k| if(b1 == nil) { ------------------ | | 24| 1.51k|#define nil ((void*)0) ------------------ | Branch (1325:5): [True: 628, False: 890] ------------------ 1326| 628| if(b2 == nil) ------------------ | | 24| 628|#define nil ((void*)0) ------------------ | Branch (1326:6): [True: 300, False: 328] ------------------ 1327| 300| ans = newbytes(0); 1328| 328| else 1329| 328| ans = makebytes(b2->data, b2->len); 1330| 628| } 1331| 890| else if(b2 == nil) { ------------------ | | 24| 890|#define nil ((void*)0) ------------------ | Branch (1331:10): [True: 254, False: 636] ------------------ 1332| 254| ans = makebytes(b1->data, b1->len); 1333| 254| } 1334| 636| else { 1335| 636| n = b1->len + b2->len; 1336| 636| ans = newbytes(n); 1337| 636| ans->len = n; 1338| 636| memmove(ans->data, b1->data, b1->len); 1339| 636| memmove(ans->data+b1->len, b2->data, b2->len); 1340| 636| } 1341| 1.51k| return ans; 1342| 1.51k|} x509.c:makeints: 1357| 732|{ 1358| 732| Ints* ans; 1359| | 1360| 732| ans = newints(len); 1361| 732| if(len > 0) ------------------ | Branch (1361:5): [True: 732, False: 0] ------------------ 1362| 732| memmove(ans->data, buf, len*sizeof(int)); 1363| 732| return ans; 1364| 732|} x509.c:newints: 1347| 732|{ 1348| 732| Ints* ans; 1349| | 1350| | ans = (Ints*)emalloc(OFFSETOF(data[0], Ints) + len*sizeof(int)); ------------------ | | 9| 732|#define OFFSETOF(a, b) offsetof(b, a) ------------------ 1351| 732| ans->len = len; 1352| 732| return ans; 1353| 732|} x509.c:seq_decode: 698| 15.7k|{ 699| 15.7k| int err; 700| 15.7k| uchar* p; 701| 15.7k| uchar* pstart; 702| 15.7k| uchar* pold; 703| 15.7k| Elist* ans; 704| 15.7k| Elem elem; 705| 15.7k| Elist* lve; 706| 15.7k| Elist* lveold; 707| | 708| 15.7k| err = ASN_OK; 709| 15.7k| ans = nil; ------------------ | | 24| 15.7k|#define nil ((void*)0) ------------------ 710| 15.7k| p = *pp; 711| 15.7k| if(!isconstr) ------------------ | Branch (711:5): [True: 11, False: 15.7k] ------------------ 712| 11| err = ASN_EPRIM; 713| 15.7k| else { 714| | /* constructed, either definite or indefinite length */ 715| 15.7k| lve = nil; ------------------ | | 24| 15.7k|#define nil ((void*)0) ------------------ 716| 15.7k| pstart = p; 717| 32.2k| for(;;) { 718| 32.2k| if(length >= 0 && p >= pstart + length) { ------------------ | Branch (718:7): [True: 32.2k, False: 0] | Branch (718:22): [True: 3.60k, False: 28.6k] ------------------ 719| 3.60k| if(p != pstart + length) ------------------ | Branch (719:8): [True: 30, False: 3.57k] ------------------ 720| 30| err = ASN_EVALLEN; 721| 3.60k| break; 722| 3.60k| } 723| 28.6k| pold = p; 724| 28.6k| err = ber_decode(&p, pend, &elem); 725| 28.6k| if(err != ASN_OK) ------------------ | Branch (725:7): [True: 12.1k, False: 16.5k] ------------------ 726| 12.1k| break; 727| 16.5k| if(elem.val.tag == VEOC) { ------------------ | Branch (727:7): [True: 0, False: 16.5k] ------------------ 728| 0| if(length != -1) { ------------------ | Branch (728:8): [True: 0, False: 0] ------------------ 729| 0| p = pold; 730| 0| err = ASN_EINVAL; 731| 0| } 732| 0| break; 733| 0| } 734| 16.5k| else 735| 16.5k| lve = mkel(elem, lve); 736| 16.5k| } 737| 15.7k| if(err == ASN_OK) { ------------------ | Branch (737:6): [True: 3.57k, False: 12.1k] ------------------ 738| | /* reverse back to original order */ 739| 12.5k| while(lve != nil) { ------------------ | | 24| 12.5k|#define nil ((void*)0) ------------------ | Branch (739:10): [True: 8.99k, False: 3.57k] ------------------ 740| 8.99k| lveold = lve; 741| 8.99k| lve = lve->tl; 742| 8.99k| lveold->tl = ans; 743| 8.99k| ans = lveold; 744| 8.99k| } 745| 3.57k| } 746| 15.7k| } 747| 15.7k| *pp = p; 748| 15.7k| *pelist = ans; 749| 15.7k| return err; 750| 15.7k|} x509.c:mkel: 1405| 16.5k|{ 1406| 16.5k| Elist* el; 1407| | 1408| 16.5k| el = (Elist*)emalloc(sizeof(Elist)); 1409| 16.5k| el->hd = e; 1410| 16.5k| el->tl = tail; 1411| 16.5k| return el; 1412| 16.5k|} x509.c:decode: 202| 933|{ 203| 933| uchar* p = a; 204| | 205| 933| return ber_decode(&p, &a[alen], pelem); 206| 933|} x509.c:edump: 2514| 8.95k|{ 2515| 8.95k| Value v; 2516| 8.95k| Elist *el; 2517| 8.95k| int i; 2518| | 2519| 8.95k| print("%s{", tagdump(e.tag)); 2520| 8.95k| v = e.val; 2521| 8.95k| switch(v.tag){ ------------------ | Branch (2521:9): [True: 8.95k, False: 0] ------------------ 2522| 1.02k| case VBool: print("Bool %d",v.u.boolval); break; ------------------ | Branch (2522:2): [True: 1.02k, False: 7.93k] ------------------ 2523| 771| case VInt: print("Int %d",v.u.intval); break; ------------------ | Branch (2523:2): [True: 771, False: 8.18k] ------------------ 2524| 779| case VOctets: print("Octets[%d] %.2x%.2x...",v.u.octetsval->len,v.u.octetsval->data[0],v.u.octetsval->data[1]); break; ------------------ | Branch (2524:2): [True: 779, False: 8.18k] ------------------ 2525| 352| case VBigInt: print("BigInt[%d] %.2x%.2x...",v.u.bigintval->len,v.u.bigintval->data[0],v.u.bigintval->data[1]); break; ------------------ | Branch (2525:2): [True: 352, False: 8.60k] ------------------ 2526| 317| case VReal: print("Real..."); break; ------------------ | Branch (2526:2): [True: 317, False: 8.64k] ------------------ 2527| 705| case VOther: print("Other..."); break; ------------------ | Branch (2527:2): [True: 705, False: 8.25k] ------------------ 2528| 268| case VBitString: print("BitString..."); break; ------------------ | Branch (2528:2): [True: 268, False: 8.69k] ------------------ 2529| 512| case VNull: print("Null"); break; ------------------ | Branch (2529:2): [True: 512, False: 8.44k] ------------------ 2530| 0| case VEOC: print("EOC..."); break; ------------------ | Branch (2530:2): [True: 0, False: 8.95k] ------------------ 2531| 593| case VObjId: print("ObjId"); ------------------ | Branch (2531:2): [True: 593, False: 8.36k] ------------------ 2532| 3.18k| for(i = 0; ilen; i++) ------------------ | Branch (2532:14): [True: 2.59k, False: 593] ------------------ 2533| 2.59k| print(" %d", v.u.objidval->data[i]); 2534| 593| break; 2535| 859| case VString: print("String \"%s\"",v.u.stringval); break; ------------------ | Branch (2535:2): [True: 859, False: 8.10k] ------------------ 2536| 1.51k| case VSeq: print("Seq\n"); ------------------ | Branch (2536:2): [True: 1.51k, False: 7.44k] ------------------ 2537| 7.69k| for(el = v.u.seqval; el!=nil; el = el->tl) ------------------ | | 24| 7.69k|#define nil ((void*)0) ------------------ | Branch (2537:24): [True: 6.17k, False: 1.51k] ------------------ 2538| 6.17k| edump(el->hd); 2539| 1.51k| break; 2540| 1.26k| case VSet: print("Set\n"); ------------------ | Branch (2540:2): [True: 1.26k, False: 7.69k] ------------------ 2541| 3.58k| for(el = v.u.setval; el!=nil; el = el->tl) ------------------ | | 24| 3.58k|#define nil ((void*)0) ------------------ | Branch (2541:24): [True: 2.32k, False: 1.26k] ------------------ 2542| 2.32k| edump(el->hd); 2543| 1.26k| break; 2544| 8.95k| } 2545| 8.95k| print("}\n"); 2546| 8.95k|} x509.c:tagdump: 2478| 8.95k|{ 2479| 8.95k| if(tag.class != Universal) ------------------ | | 28| 8.95k|#define Universal 0 ------------------ | Branch (2479:5): [True: 550, False: 8.40k] ------------------ 2480| 550| return smprint("class%d,num%d", tag.class, tag.num); 2481| 8.40k| switch(tag.num){ 2482| 1.02k| case BOOLEAN: return "BOOLEAN"; break; ------------------ | | 32| 1.02k|#define BOOLEAN 1 ------------------ | Branch (2482:3): [True: 1.02k, False: 7.38k] ------------------ 2483| 1.03k| case INTEGER: return "INTEGER"; break; ------------------ | | 33| 1.03k|#define INTEGER 2 ------------------ | Branch (2483:3): [True: 1.03k, False: 7.37k] ------------------ 2484| 268| case BIT_STRING: return "BIT STRING"; break; ------------------ | | 34| 268|#define BIT_STRING 3 ------------------ | Branch (2484:3): [True: 268, False: 8.14k] ------------------ 2485| 224| case OCTET_STRING: return "OCTET STRING"; break; ------------------ | | 35| 224|#define OCTET_STRING 4 ------------------ | Branch (2485:3): [True: 224, False: 8.18k] ------------------ 2486| 14| case NULLTAG: return "NULLTAG"; break; ------------------ | | 36| 14|#define NULLTAG 5 ------------------ | Branch (2486:3): [True: 14, False: 8.39k] ------------------ 2487| 593| case OBJECT_ID: return "OID"; break; ------------------ | | 37| 593|#define OBJECT_ID 6 ------------------ | Branch (2487:3): [True: 593, False: 7.81k] ------------------ 2488| 5| case ObjectDescriptor: return "OBJECT_DES"; break; ------------------ | | 38| 5|#define ObjectDescriptor 7 ------------------ | Branch (2488:3): [True: 5, False: 8.40k] ------------------ 2489| 91| case EXTERNAL: return "EXTERNAL"; break; ------------------ | | 39| 91|#define EXTERNAL 8 ------------------ | Branch (2489:3): [True: 91, False: 8.31k] ------------------ 2490| 317| case REAL: return "REAL"; break; ------------------ | | 40| 317|#define REAL 9 ------------------ | Branch (2490:3): [True: 317, False: 8.09k] ------------------ 2491| 86| case ENUMERATED: return "ENUMERATED"; break; ------------------ | | 41| 86|#define ENUMERATED 10 ------------------ | Branch (2491:3): [True: 86, False: 8.32k] ------------------ 2492| 159| case EMBEDDED_PDV: return "EMBEDDED PDV"; break; ------------------ | | 42| 159|#define EMBEDDED_PDV 11 ------------------ | Branch (2492:3): [True: 159, False: 8.25k] ------------------ 2493| 1.51k| case SEQUENCE: return "SEQUENCE"; break; ------------------ | | 43| 1.51k|#define SEQUENCE 16 /* also SEQUENCE OF */ ------------------ | Branch (2493:3): [True: 1.51k, False: 6.89k] ------------------ 2494| 1.26k| case SETOF: return "SETOF"; break; ------------------ | | 44| 1.26k|#define SETOF 17 /* also SETOF OF */ ------------------ | Branch (2494:3): [True: 1.26k, False: 7.14k] ------------------ 2495| 75| case NumericString: return "NumericString"; break; ------------------ | | 45| 75|#define NumericString 18 ------------------ | Branch (2495:3): [True: 75, False: 8.33k] ------------------ 2496| 40| case PrintableString: return "PrintableString"; break; ------------------ | | 46| 40|#define PrintableString 19 ------------------ | Branch (2496:3): [True: 40, False: 8.36k] ------------------ 2497| 44| case TeletexString: return "TeletexString"; break; ------------------ | | 47| 44|#define TeletexString 20 ------------------ | Branch (2497:3): [True: 44, False: 8.36k] ------------------ 2498| 37| case VideotexString: return "VideotexString"; break; ------------------ | | 48| 37|#define VideotexString 21 ------------------ | Branch (2498:3): [True: 37, False: 8.37k] ------------------ 2499| 33| case IA5String: return "IA5String"; break; ------------------ | | 49| 33|#define IA5String 22 ------------------ | Branch (2499:3): [True: 33, False: 8.37k] ------------------ 2500| 381| case UTCTime: return "UTCTime"; break; ------------------ | | 50| 381|#define UTCTime 23 ------------------ | Branch (2500:3): [True: 381, False: 8.02k] ------------------ 2501| 36| case GeneralizedTime: return "GeneralizedTime"; break; ------------------ | | 51| 36|#define GeneralizedTime 24 ------------------ | Branch (2501:3): [True: 36, False: 8.37k] ------------------ 2502| 73| case GraphicString: return "GraphicString"; break; ------------------ | | 52| 73|#define GraphicString 25 ------------------ | Branch (2502:3): [True: 73, False: 8.33k] ------------------ 2503| 17| case VisibleString: return "VisibleString"; break; ------------------ | | 53| 17|#define VisibleString 26 ------------------ | Branch (2503:3): [True: 17, False: 8.39k] ------------------ 2504| 19| case GeneralString: return "GeneralString"; break; ------------------ | | 54| 19|#define GeneralString 27 ------------------ | Branch (2504:3): [True: 19, False: 8.39k] ------------------ 2505| 35| case UniversalString: return "UniversalString"; break; ------------------ | | 55| 35|#define UniversalString 28 ------------------ | Branch (2505:3): [True: 35, False: 8.37k] ------------------ 2506| 69| case BMPString: return "BMPString"; break; ------------------ | | 56| 69|#define BMPString 30 ------------------ | Branch (2506:3): [True: 69, False: 8.34k] ------------------ 2507| 953| default: ------------------ | Branch (2507:3): [True: 953, False: 7.45k] ------------------ 2508| 953| return smprint("Universal,num%d", tag.num); 2509| 8.40k| } 2510| 8.40k|}