summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2022-12-23 02:31:56 +0000
committerjsing <>2022-12-23 02:31:56 +0000
commit8d2a4066281adb06dfb03f958f7b178286156e32 (patch)
treea7f65847f0b0be06f9557b0dd2f774986d950edc
parentdb6281c6da9f0680a4284ec6cb9ea68ce90b7399 (diff)
downloadopenbsd-8d2a4066281adb06dfb03f958f7b178286156e32.tar.gz
openbsd-8d2a4066281adb06dfb03f958f7b178286156e32.tar.bz2
openbsd-8d2a4066281adb06dfb03f958f7b178286156e32.zip
Consistently check for NULL early.
Also be more consistent with variable naming. ok tb@
-rw-r--r--src/lib/libcrypto/ui/ui_lib.c153
1 files changed, 89 insertions, 64 deletions
diff --git a/src/lib/libcrypto/ui/ui_lib.c b/src/lib/libcrypto/ui/ui_lib.c
index 8811bf86c7..546540ad83 100644
--- a/src/lib/libcrypto/ui/ui_lib.c
+++ b/src/lib/libcrypto/ui/ui_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ui_lib.c,v 1.49 2022/12/23 02:27:47 jsing Exp $ */ 1/* $OpenBSD: ui_lib.c,v 1.50 2022/12/23 02:31:56 jsing Exp $ */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL 2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001. 3 * project 2001.
4 */ 4 */
@@ -117,6 +117,7 @@ UI_free(UI *ui)
117{ 117{
118 if (ui == NULL) 118 if (ui == NULL)
119 return; 119 return;
120
120 sk_UI_STRING_pop_free(ui->strings, free_string); 121 sk_UI_STRING_pop_free(ui->strings, free_string);
121 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_UI, ui, &ui->ex_data); 122 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_UI, ui, &ui->ex_data);
122 free(ui); 123 free(ui);
@@ -379,6 +380,7 @@ UI_add_user_data(UI *ui, void *user_data)
379 void *old_data = ui->user_data; 380 void *old_data = ui->user_data;
380 381
381 ui->user_data = user_data; 382 ui->user_data = user_data;
383
382 return old_data; 384 return old_data;
383} 385}
384LCRYPTO_ALIAS(UI_add_user_data) 386LCRYPTO_ALIAS(UI_add_user_data)
@@ -486,6 +488,7 @@ UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f) (void))
486 UIerror(ERR_R_PASSED_NULL_PARAMETER); 488 UIerror(ERR_R_PASSED_NULL_PARAMETER);
487 return -1; 489 return -1;
488 } 490 }
491
489 switch (cmd) { 492 switch (cmd) {
490 case UI_CTRL_PRINT_ERRORS: 493 case UI_CTRL_PRINT_ERRORS:
491 { 494 {
@@ -530,18 +533,18 @@ UI_get_ex_data(UI *r, int idx)
530LCRYPTO_ALIAS(UI_get_ex_data) 533LCRYPTO_ALIAS(UI_get_ex_data)
531 534
532void 535void
533UI_set_default_method(const UI_METHOD *meth) 536UI_set_default_method(const UI_METHOD *method)
534{ 537{
535 default_UI_meth = meth; 538 default_UI_meth = method;
536} 539}
537LCRYPTO_ALIAS(UI_set_default_method) 540LCRYPTO_ALIAS(UI_set_default_method)
538 541
539const UI_METHOD * 542const UI_METHOD *
540UI_get_default_method(void) 543UI_get_default_method(void)
541{ 544{
542 if (default_UI_meth == NULL) { 545 if (default_UI_meth == NULL)
543 default_UI_meth = UI_OpenSSL(); 546 default_UI_meth = UI_OpenSSL();
544 } 547
545 return default_UI_meth; 548 return default_UI_meth;
546} 549}
547LCRYPTO_ALIAS(UI_get_default_method) 550LCRYPTO_ALIAS(UI_get_default_method)
@@ -554,9 +557,10 @@ UI_get_method(UI *ui)
554LCRYPTO_ALIAS(UI_get_method) 557LCRYPTO_ALIAS(UI_get_method)
555 558
556const UI_METHOD * 559const UI_METHOD *
557UI_set_method(UI *ui, const UI_METHOD *meth) 560UI_set_method(UI *ui, const UI_METHOD *method)
558{ 561{
559 ui->meth = meth; 562 ui->meth = method;
563
560 return ui->meth; 564 return ui->meth;
561} 565}
562LCRYPTO_ALIAS(UI_set_method) 566LCRYPTO_ALIAS(UI_set_method)
@@ -597,55 +601,60 @@ LCRYPTO_ALIAS(UI_destroy_method)
597int 601int
598UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui)) 602UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui))
599{ 603{
600 if (method) { 604 if (method == NULL)
601 method->ui_open_session = opener; 605 return -1;
602 return 0; 606
603 } 607 method->ui_open_session = opener;
604 return -1; 608
609 return 0;
605} 610}
606LCRYPTO_ALIAS(UI_method_set_opener) 611LCRYPTO_ALIAS(UI_method_set_opener)
607 612
608int 613int
609UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis)) 614UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis))
610{ 615{
611 if (method) { 616 if (method == NULL)
612 method->ui_write_string = writer; 617 return -1;
613 return 0; 618
614 } 619 method->ui_write_string = writer;
615 return -1; 620
621 return 0;
616} 622}
617LCRYPTO_ALIAS(UI_method_set_writer) 623LCRYPTO_ALIAS(UI_method_set_writer)
618 624
619int 625int
620UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui)) 626UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui))
621{ 627{
622 if (method) { 628 if (method == NULL)
623 method->ui_flush = flusher; 629 return -1;
624 return 0; 630
625 } 631 method->ui_flush = flusher;
626 return -1; 632
633 return 0;
627} 634}
628LCRYPTO_ALIAS(UI_method_set_flusher) 635LCRYPTO_ALIAS(UI_method_set_flusher)
629 636
630int 637int
631UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis)) 638UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis))
632{ 639{
633 if (method) { 640 if (method == NULL)
634 method->ui_read_string = reader; 641 return -1;
635 return 0; 642
636 } 643 method->ui_read_string = reader;
637 return -1; 644
645 return 0;
638} 646}
639LCRYPTO_ALIAS(UI_method_set_reader) 647LCRYPTO_ALIAS(UI_method_set_reader)
640 648
641int 649int
642UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui)) 650UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui))
643{ 651{
644 if (method) { 652 if (method == NULL)
645 method->ui_close_session = closer; 653 return -1;
646 return 0; 654
647 } 655 method->ui_close_session = closer;
648 return -1; 656
657 return 0;
649} 658}
650LCRYPTO_ALIAS(UI_method_set_closer) 659LCRYPTO_ALIAS(UI_method_set_closer)
651 660
@@ -654,56 +663,62 @@ UI_method_set_prompt_constructor(UI_METHOD *method,
654 char *(*prompt_constructor)(UI *ui, const char *object_desc, 663 char *(*prompt_constructor)(UI *ui, const char *object_desc,
655 const char *object_name)) 664 const char *object_name))
656{ 665{
657 if (method) { 666 if (method == NULL)
658 method->ui_construct_prompt = prompt_constructor; 667 return -1;
659 return 0; 668
660 } 669 method->ui_construct_prompt = prompt_constructor;
661 return -1; 670
671 return 0;
662} 672}
663LCRYPTO_ALIAS(UI_method_set_prompt_constructor) 673LCRYPTO_ALIAS(UI_method_set_prompt_constructor)
664 674
665int 675int
666(*UI_method_get_opener(const UI_METHOD * method))(UI *) 676(*UI_method_get_opener(const UI_METHOD * method))(UI *)
667{ 677{
668 if (method) 678 if (method == NULL)
669 return method->ui_open_session; 679 return NULL;
670 return NULL; 680
681 return method->ui_open_session;
671} 682}
672LCRYPTO_ALIAS(UI_method_get_opener) 683LCRYPTO_ALIAS(UI_method_get_opener)
673 684
674int 685int
675(*UI_method_get_writer(const UI_METHOD *method))(UI *, UI_STRING *) 686(*UI_method_get_writer(const UI_METHOD *method))(UI *, UI_STRING *)
676{ 687{
677 if (method) 688 if (method == NULL)
678 return method->ui_write_string; 689 return NULL;
679 return NULL; 690
691 return method->ui_write_string;
680} 692}
681LCRYPTO_ALIAS(UI_method_get_writer) 693LCRYPTO_ALIAS(UI_method_get_writer)
682 694
683int 695int
684(*UI_method_get_flusher(const UI_METHOD *method)) (UI *) 696(*UI_method_get_flusher(const UI_METHOD *method)) (UI *)
685{ 697{
686 if (method) 698 if (method == NULL)
687 return method->ui_flush; 699 return NULL;
688 return NULL; 700
701 return method->ui_flush;
689} 702}
690LCRYPTO_ALIAS(UI_method_get_flusher) 703LCRYPTO_ALIAS(UI_method_get_flusher)
691 704
692int 705int
693(*UI_method_get_reader(const UI_METHOD *method))(UI *, UI_STRING *) 706(*UI_method_get_reader(const UI_METHOD *method))(UI *, UI_STRING *)
694{ 707{
695 if (method) 708 if (method == NULL)
696 return method->ui_read_string; 709 return NULL;
697 return NULL; 710
711 return method->ui_read_string;
698} 712}
699LCRYPTO_ALIAS(UI_method_get_reader) 713LCRYPTO_ALIAS(UI_method_get_reader)
700 714
701int 715int
702(*UI_method_get_closer(const UI_METHOD *method))(UI *) 716(*UI_method_get_closer(const UI_METHOD *method))(UI *)
703{ 717{
704 if (method) 718 if (method == NULL)
705 return method->ui_close_session; 719 return NULL;
706 return NULL; 720
721 return method->ui_close_session;
707} 722}
708LCRYPTO_ALIAS(UI_method_get_closer) 723LCRYPTO_ALIAS(UI_method_get_closer)
709 724
@@ -711,17 +726,19 @@ char *
711(*UI_method_get_prompt_constructor(const UI_METHOD *method))(UI *, const char *, 726(*UI_method_get_prompt_constructor(const UI_METHOD *method))(UI *, const char *,
712 const char *) 727 const char *)
713{ 728{
714 if (method) 729 if (method == NULL)
715 return method->ui_construct_prompt; 730 return NULL;
716 return NULL; 731
732 return method->ui_construct_prompt;
717} 733}
718LCRYPTO_ALIAS(UI_method_get_prompt_constructor) 734LCRYPTO_ALIAS(UI_method_get_prompt_constructor)
719 735
720enum UI_string_types 736enum UI_string_types
721UI_get_string_type(UI_STRING *uis) 737UI_get_string_type(UI_STRING *uis)
722{ 738{
723 if (!uis) 739 if (uis == NULL)
724 return UIT_NONE; 740 return UIT_NONE;
741
725 return uis->type; 742 return uis->type;
726} 743}
727LCRYPTO_ALIAS(UI_get_string_type) 744LCRYPTO_ALIAS(UI_get_string_type)
@@ -729,8 +746,9 @@ LCRYPTO_ALIAS(UI_get_string_type)
729int 746int
730UI_get_input_flags(UI_STRING *uis) 747UI_get_input_flags(UI_STRING *uis)
731{ 748{
732 if (!uis) 749 if (uis == NULL)
733 return 0; 750 return 0;
751
734 return uis->input_flags; 752 return uis->input_flags;
735} 753}
736LCRYPTO_ALIAS(UI_get_input_flags) 754LCRYPTO_ALIAS(UI_get_input_flags)
@@ -738,8 +756,9 @@ LCRYPTO_ALIAS(UI_get_input_flags)
738const char * 756const char *
739UI_get0_output_string(UI_STRING *uis) 757UI_get0_output_string(UI_STRING *uis)
740{ 758{
741 if (!uis) 759 if (uis == NULL)
742 return NULL; 760 return NULL;
761
743 return uis->out_string; 762 return uis->out_string;
744} 763}
745LCRYPTO_ALIAS(UI_get0_output_string) 764LCRYPTO_ALIAS(UI_get0_output_string)
@@ -747,8 +766,9 @@ LCRYPTO_ALIAS(UI_get0_output_string)
747const char * 766const char *
748UI_get0_action_string(UI_STRING *uis) 767UI_get0_action_string(UI_STRING *uis)
749{ 768{
750 if (!uis) 769 if (uis == NULL)
751 return NULL; 770 return NULL;
771
752 switch (uis->type) { 772 switch (uis->type) {
753 case UIT_PROMPT: 773 case UIT_PROMPT:
754 case UIT_BOOLEAN: 774 case UIT_BOOLEAN:
@@ -762,8 +782,9 @@ LCRYPTO_ALIAS(UI_get0_action_string)
762const char * 782const char *
763UI_get0_result_string(UI_STRING *uis) 783UI_get0_result_string(UI_STRING *uis)
764{ 784{
765 if (!uis) 785 if (uis == NULL)
766 return NULL; 786 return NULL;
787
767 switch (uis->type) { 788 switch (uis->type) {
768 case UIT_PROMPT: 789 case UIT_PROMPT:
769 case UIT_VERIFY: 790 case UIT_VERIFY:
@@ -777,8 +798,9 @@ LCRYPTO_ALIAS(UI_get0_result_string)
777const char * 798const char *
778UI_get0_test_string(UI_STRING *uis) 799UI_get0_test_string(UI_STRING *uis)
779{ 800{
780 if (!uis) 801 if (uis == NULL)
781 return NULL; 802 return NULL;
803
782 switch (uis->type) { 804 switch (uis->type) {
783 case UIT_VERIFY: 805 case UIT_VERIFY:
784 return uis->_.string_data.test_buf; 806 return uis->_.string_data.test_buf;
@@ -791,8 +813,9 @@ LCRYPTO_ALIAS(UI_get0_test_string)
791int 813int
792UI_get_result_minsize(UI_STRING *uis) 814UI_get_result_minsize(UI_STRING *uis)
793{ 815{
794 if (!uis) 816 if (uis == NULL)
795 return -1; 817 return -1;
818
796 switch (uis->type) { 819 switch (uis->type) {
797 case UIT_PROMPT: 820 case UIT_PROMPT:
798 case UIT_VERIFY: 821 case UIT_VERIFY:
@@ -806,8 +829,9 @@ LCRYPTO_ALIAS(UI_get_result_minsize)
806int 829int
807UI_get_result_maxsize(UI_STRING *uis) 830UI_get_result_maxsize(UI_STRING *uis)
808{ 831{
809 if (!uis) 832 if (uis == NULL)
810 return -1; 833 return -1;
834
811 switch (uis->type) { 835 switch (uis->type) {
812 case UIT_PROMPT: 836 case UIT_PROMPT:
813 case UIT_VERIFY: 837 case UIT_VERIFY:
@@ -826,8 +850,9 @@ UI_set_result(UI *ui, UI_STRING *uis, const char *result)
826 850
827 ui->flags &= ~UI_FLAG_REDOABLE; 851 ui->flags &= ~UI_FLAG_REDOABLE;
828 852
829 if (!uis) 853 if (uis == NULL)
830 return -1; 854 return -1;
855
831 switch (uis->type) { 856 switch (uis->type) {
832 case UIT_PROMPT: 857 case UIT_PROMPT:
833 case UIT_VERIFY: 858 case UIT_VERIFY: