]> git.ipfire.org Git - thirdparty/openssl.git/blame - util/check-format-test-negatives.c
Remove RSA SSLv23 padding mode
[thirdparty/openssl.git] / util / check-format-test-negatives.c
CommitLineData
99a16e04 1/*
4333b89f 2 * Copyright 2007-2021 The OpenSSL Project Authors. All Rights Reserved.
99a16e04
DDO
3 * Copyright Nokia 2007-2019
4 * Copyright Siemens AG 2015-2019
5 *
6 * Licensed under the Apache License 2.0 (the "License"). You may not use
7 * this file except in compliance with the License. You can obtain a copy
8 * in the file LICENSE in the source distribution or at
9 * https://www.openssl.org/source/license.html
10 */
11
12/*
13 * A collection of test cases where check-format.pl should not report issues.
14 * There are some known false positives, though, which are marked below.
15 */
16
17/*-
18 * allow double space in format-tagged multi-line comment
19 */
20int f(void) /*
21 * trailing multi-line comment
22 */
23{
24 if (ctx == NULL) { /* non-leading intra-line comment */
a77571c3 25 if (/* comment after '(' */ pem_name != NULL /* comment before ')' */)
99a16e04
DDO
26 /* entire-line comment indent usually like for the following line */
27 return NULL; /* hanging indent also for this line after comment */
28 /* leading comment has same indentation as normal code */ stmt;
29 /* entire-line comment may have same indent as normal code */
30 }
31
8e655da0
DDO
32 for (;;)
33 ;
34 for (i = 0;;)
35 ;
36 for (i = 0; i < 1;)
37 ;
38
99a16e04
DDO
39#if X
40 if (1) /* bad style: just part of control structure depends on #if */
41#else
42 if (2) /*@ resulting false positive */
43#endif
44 c; /*@ resulting false positive */
45
46 if (1)
47 if (2)
48 c;
49 else
50 e;
51 else
52 f;
53 do
54 do
55 2;
56 while (1);
57 while (2);
58
59 if (1)
60 f(a, b);
61 do
62 1; while (2); /*@ more than one stmt just to construct case */
63 if (1)
64 f(a, b);
65 else
66 do
67 1;
68 while (2);
69 if (1)
70 f(a, b);
71 else do /*@ (non-brace) code before 'do' just to construct case */
72 1;
73 while (2);
74 f1234(a,
75 b); do /*@ (non-brace) code before 'do' just to construct case */
76 1;
77 while (2);
78 if (1)
79 f(a,
80 b); do /*@ (non-brace) code before 'do' just to construct case */
81 1;
82 while (2);
83 if (1)
84 f(a, b);
85 else
86 do f(c, c); /*@ (non-brace) code after 'do' just to construct case */
87 while (2);
88
89 if (1)
90 f(a, b);
91 else
92 return;
93 if (1)
94 f(a,
95 b); else /*@ (non-brace) code before 'else' just to construct case */
96 do
97 1;
98 while (2);
99
100 if (1)
101 { /*@ brace after 'if' not on same line just to construct case */
102 c;
103 d;
104 }
105 /* this comment is correctly indented if it refers to the following line */
106 d;
107
108 if (1) {
109 2;
110 } else /*@ no brace after 'else' just to construct case */
111 3;
112 do {
113 } while (x);
114 if (1) {
115 2;
116 } else {
117 3;
118 }
119 if (4)
120 5;
121 else
122 6;
90a7c905
DDO
123
124 if (1) {
125 if (2) {
126 case MAC_TYPE_MAC:
127 {
128 EVP_MAC_CTX *new_mac_ctx;
129
130 if (ctx->pkey == NULL)
131 return 0;
132 }
133 break;
134 default:
135 /* This should be dead code */
136 return 0;
137 }
138 }
139 if (expr_line1
140 == expr_line2
141 && expr_line3) {
142 c1;
143 } else {
144 c;
145 d;
146 }
147 if (expr_line1
148 == expr_line2
149 && expr_line3)
150 hanging_stmt;
99a16e04 151}
90a7c905
DDO
152
153const OPTIONS passwd_options[] = {
154 {"aixmd5", OPT_AIXMD5, '-', "AIX MD5-based password algorithm"},
155#if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
156 {"crypt", OPT_CRYPT, '-', "Standard Unix password algorithm (default)"},
157#endif
158 OPT_R_OPTIONS,
159
160 {NULL}
161};
162
99a16e04
DDO
163typedef * d(int)
164 x;
165typedef (int)
166x;
167typedef (int)*()
168 x;
169typedef *int *
170x;
171typedef OSSL_CMP_MSG *(*cmp_srv_process_cb_t)
172 (OSSL_CMP_SRV_CTX *ctx, OSSL_CMP_MSG *msg)
173 xx;
174int f()
175{
176 c;
177 if (1) {
178 c;
179 }
180 c;
181 if (1)
182 if (2)
183 { /*@ brace after 'if' not on same line just to construct case */
184 c;
185 }
186 e;
187 const usign = {
188 0xDF,
189 {
190 dd
191 },
192 dd
193 };
194 const unsign = {
195 0xDF, {
196 dd
197 },
198 dd
199 };
200}
201const unsigned char trans_id[OSSL_CMP_TRANSACTIONID_LENGTH] = {
202 0xDF,
203};
204const unsigned char trans_id[OSSL_CMP_TRANSACTIONID_LENGTH] =
205 {
206 0xDF,
207 };
208typedef
209int
210a;
211
212typedef
213struct
214{
215 int a;
216} b;
217typedef enum {
218 w = 0
219} e_type;
220typedef struct {
221 enum {
222 w = 0
223 } e_type;
224 enum {
225 w = 0
226 } e_type;
227} e;
228struct s_type {
229 enum e_type {
230 w = 0
231 };
232};
233struct s_type
234{
235 enum e_type {
236 w = 0
237 };
238 enum e2_type {
239 w = 0
240 };
241};
242
243#define X 1 + 1
244#define Y /* .. */ 2 + 2
c9725776 245#define Z 3 + 3 * (*a++)
99a16e04 246
c9725776 247static varref cmp_vars[] = { /* comment. comment? comment! */
99a16e04
DDO
248 {&opt_config}, {&opt_section},
249
250 {&opt_server}, {&opt_proxy}, {&opt_path},
251};
252
253#define SWITCH(x) \
254 switch (x) { \
255 case 0: \
256 break; \
257 default: \
258 break; \
259 }
260
261#define DEFINE_SET_GET_BASE_TEST(PREFIX, SETN, GETN, DUP, FIELD, TYPE, ERR, \
262 DEFAULT, NEW, FREE) \
263 static int execute_CTX_##SETN##_##GETN##_##FIELD( \
264 TEST_FIXTURE *fixture) \
265 { \
266 CTX *ctx = fixture->ctx; \
267 int (*set_fn)(CTX *ctx, TYPE) = \
268 (int (*)(CTX *ctx, TYPE))PREFIX##_##SETN##_##FIELD; \
269 /* comment */ \
270 }
271
272/* 'struct' in function header */
273static int f(struct pem_pass_data *pass_data)
274{
275 if (pass_data == NULL)
276 return 0;
277}
278
279static void *fun(void)
280{
281 if (pem_name != NULL)
282 /* comment */
283 return NULL;
284
13a574d8
DDO
285label0:
286 label1: /* allow special indent 1 for label at outermost level in body */
99a16e04 287 do {
13a574d8 288 label2:
99a16e04
DDO
289 size_t available_len, data_len;
290 const char *curr = txt, *next = txt;
291 char *tmp;
13a574d8
DDO
292
293 {
294 label3:
295 }
99a16e04
DDO
296 } while (1);
297
298 char *intraline_string_with_comment_delimiters_and_dbl_space = "1 /*1";
299 char *multiline_string_with_comment_delimiters_and_dbl_space = "1 /*1\
3002222222\'22222222222222222\"222222222" "33333 /*3333333333" "44 /*44444444444\
30155555555555555\
3026666";
303}
304
305ASN1_CHOICE(OSSL_CRMF_POPO) = {
306 ASN1_IMP(OSSL_CRMF_POPO, value.raVerified, ASN1_NULL, 0),
307 ASN1_EXP(OSSL_CRMF_POPO, value.keyAgreement, OSSL_CRMF_POPOPRIVKEY, 3)
308} ASN1_CHOICE_END(OSSL_CRMF_POPO)
309IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_POPO)
310
311ASN1_ADB(OSSL_CRMF_ATTRIBUTETYPEANDVALUE) = {
312 ADB_ENTRY(NID_id_regCtrl_regToken,
313 ASN1_SIMPLE(OSSL_CRMF_ATTRIBUTETYPEANDVALUE,
314 value.regToken, ASN1_UTF8STRING)),
315} ASN1_ADB_END(OSSL_CRMF_ATTRIBUTETYPEANDVALUE, 0, type, 0,
316 &attributetypeandvalue_default_tt, NULL);
317
318ASN1_ITEM_TEMPLATE(OSSL_CRMF_MSGS) =
319 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0,
320 OSSL_CRMF_MSGS, OSSL_CRMF_MSG)
321ASN1_ITEM_TEMPLATE_END(OSSL_CRMF_MSGS)
322
323void f_looong_body_200()
324{ /* function body length up to 200 lines accepted */
43b2e9e0
DDO
325 ;
326 ;
327 ;
328 ;
329 ;
330 ;
331 ;
332 ;
333 ;
334 ;
335 ;
336 ;
337 ;
338 ;
339 ;
340 ;
341 ;
342 ;
343 ;
344 ;
345 ;
346 ;
347 ;
348 ;
349 ;
350 ;
351 ;
352 ;
353 ;
354 ;
355 ;
356 ;
357 ;
358 ;
359 ;
360 ;
361 ;
362 ;
363 ;
364 ;
365 ;
366 ;
367 ;
368 ;
369 ;
370 ;
371 ;
372 ;
373 ;
374 ;
375 ;
376 ;
377 ;
378 ;
379 ;
380 ;
381 ;
382 ;
383 ;
384 ;
385 ;
386 ;
387 ;
388 ;
389 ;
390 ;
391 ;
392 ;
393 ;
394 ;
395 ;
396 ;
397 ;
398 ;
399 ;
400 ;
401 ;
402 ;
403 ;
404 ;
405 ;
406 ;
407 ;
408 ;
409 ;
410 ;
411 ;
412 ;
413 ;
414 ;
415 ;
416 ;
417 ;
418 ;
419 ;
420 ;
421 ;
422 ;
423 ;
424 ;
425 ;
426 ;
427 ;
428 ;
429 ;
430 ;
431 ;
432 ;
433 ;
434 ;
435 ;
436 ;
437 ;
438 ;
439 ;
440 ;
441 ;
442 ;
443 ;
444 ;
445 ;
446 ;
447 ;
448 ;
449 ;
450 ;
451 ;
452 ;
453 ;
454 ;
455 ;
456 ;
457 ;
458 ;
459 ;
460 ;
461 ;
462 ;
463 ;
464 ;
465 ;
466 ;
467 ;
468 ;
469 ;
470 ;
471 ;
472 ;
473 ;
474 ;
475 ;
476 ;
477 ;
478 ;
479 ;
480 ;
481 ;
482 ;
483 ;
484 ;
485 ;
486 ;
487 ;
488 ;
489 ;
490 ;
491 ;
492 ;
493 ;
494 ;
495 ;
496 ;
497 ;
498 ;
499 ;
500 ;
501 ;
502 ;
503 ;
504 ;
505 ;
506 ;
507 ;
508 ;
509 ;
510 ;
511 ;
512 ;
513 ;
514 ;
515 ;
516 ;
517 ;
518 ;
519 ;
520 ;
521 ;
522 ;
523 ;
524 ;
99a16e04
DDO
525}
526
527void f_looong_body_201()
528{ /* function body length > 200 lines, but LONG BODY marker present */
43b2e9e0
DDO
529 ;
530 ;
531 ;
532 ;
533 ;
534 ;
535 ;
536 ;
537 ;
538 ;
539 ;
540 ;
541 ;
542 ;
543 ;
544 ;
545 ;
546 ;
547 ;
548 ;
549 ;
550 ;
551 ;
552 ;
553 ;
554 ;
555 ;
556 ;
557 ;
558 ;
559 ;
560 ;
561 ;
562 ;
563 ;
564 ;
565 ;
566 ;
567 ;
568 ;
569 ;
570 ;
571 ;
572 ;
573 ;
574 ;
575 ;
576 ;
577 ;
578 ;
579 ;
580 ;
581 ;
582 ;
583 ;
584 ;
585 ;
586 ;
587 ;
588 ;
589 ;
590 ;
591 ;
592 ;
593 ;
594 ;
595 ;
596 ;
597 ;
598 ;
599 ;
600 ;
601 ;
602 ;
603 ;
604 ;
605 ;
606 ;
607 ;
608 ;
609 ;
610 ;
611 ;
612 ;
613 ;
614 ;
615 ;
616 ;
617 ;
618 ;
619 ;
620 ;
621 ;
622 ;
623 ;
624 ;
625 ;
626 ;
627 ;
628 ;
629 ;
630 ;
631 ;
632 ;
633 ;
634 ;
635 ;
636 ;
637 ;
638 ;
639 ;
640 ;
641 ;
642 ;
643 ;
644 ;
645 ;
646 ;
647 ;
648 ;
649 ;
650 ;
651 ;
652 ;
653 ;
654 ;
655 ;
656 ;
657 ;
658 ;
659 ;
660 ;
661 ;
662 ;
663 ;
664 ;
665 ;
666 ;
667 ;
668 ;
669 ;
670 ;
671 ;
672 ;
673 ;
674 ;
675 ;
676 ;
677 ;
678 ;
679 ;
680 ;
681 ;
682 ;
683 ;
684 ;
685 ;
686 ;
687 ;
688 ;
689 ;
690 ;
691 ;
692 ;
693 ;
694 ;
695 ;
696 ;
697 ;
698 ;
699 ;
700 ;
701 ;
702 ;
703 ;
704 ;
705 ;
706 ;
707 ;
708 ;
709 ;
710 ;
711 ;
712 ;
713 ;
714 ;
715 ;
716 ;
717 ;
718 ;
719 ;
720 ;
721 ;
722 ;
723 ;
724 ;
725 ;
726 ;
727 ;
728 ;
729 ;
730 ;
99a16e04 731}