Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(605)

Side by Side Diff: third_party/libxslt/libexslt/crypto.c

Issue 1848793005: Roll libxslt to 891681e3e948f31732229f53cb6db7215f740fc7 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/libxslt/libexslt/Makefile.in ('k') | third_party/libxslt/libexslt/date.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #define IN_LIBEXSLT 1 #define IN_LIBEXSLT
2 #include "libexslt/libexslt.h" 2 #include "libexslt/libexslt.h"
3 3
4 #if defined(WIN32) && !defined (__CYGWIN__) && (!__MINGW32__) 4 #if defined(WIN32) && !defined (__CYGWIN__) && (!__MINGW32__)
5 #include <win32config.h> 5 #include <win32config.h>
6 #else 6 #else
7 #include "config.h" 7 #include "config.h"
8 #endif 8 #endif
9 9
10 #include <libxml/tree.h> 10 #include <libxml/tree.h>
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 450
451 #endif /* defined(HAVE_GCRYPT) */ 451 #endif /* defined(HAVE_GCRYPT) */
452 452
453 #if defined(HAVE_CRYPTO) 453 #if defined(HAVE_CRYPTO)
454 454
455 /** 455 /**
456 * exsltCryptoPopString: 456 * exsltCryptoPopString:
457 * @ctxt: an XPath parser context 457 * @ctxt: an XPath parser context
458 * @nargs: the number of arguments 458 * @nargs: the number of arguments
459 * 459 *
460 * Helper function which checks for and returns first string argument and its le ngth 460 * Helper function which checks for and returns first string argument and its
461 * length in bytes.
461 */ 462 */
462 static int 463 static int
463 exsltCryptoPopString (xmlXPathParserContextPtr ctxt, int nargs, 464 exsltCryptoPopString (xmlXPathParserContextPtr ctxt, int nargs,
464 xmlChar ** str) { 465 xmlChar ** str) {
465 466
466 int str_len = 0; 467 int str_len = 0;
467 468
468 if ((nargs < 1) || (nargs > 2)) { 469 if ((nargs < 1) || (nargs > 2)) {
469 xmlXPathSetArityError (ctxt); 470 xmlXPathSetArityError (ctxt);
470 return 0; 471 return 0;
471 } 472 }
472 473
473 *str = xmlXPathPopString (ctxt); 474 *str = xmlXPathPopString (ctxt);
474 str_len = xmlUTF8Strlen (*str); 475 str_len = xmlStrlen (*str);
475 476
476 if (str_len == 0) { 477 if (str_len == 0) {
477 xmlXPathReturnEmptyString (ctxt); 478 xmlXPathReturnEmptyString (ctxt);
478 xmlFree (*str); 479 xmlFree (*str);
479 return 0; 480 return 0;
480 } 481 }
481 482
482 return str_len; 483 return str_len;
483 } 484 }
484 485
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 /** 585 /**
585 * exsltCryptoRc4EncryptFunction: 586 * exsltCryptoRc4EncryptFunction:
586 * @ctxt: an XPath parser context 587 * @ctxt: an XPath parser context
587 * @nargs: the number of arguments 588 * @nargs: the number of arguments
588 * 589 *
589 * computes the sha1 hash of a string and returns as hex 590 * computes the sha1 hash of a string and returns as hex
590 */ 591 */
591 static void 592 static void
592 exsltCryptoRc4EncryptFunction (xmlXPathParserContextPtr ctxt, int nargs) { 593 exsltCryptoRc4EncryptFunction (xmlXPathParserContextPtr ctxt, int nargs) {
593 594
594 int key_len = 0, key_size = 0; 595 int key_len = 0;
595 int str_len = 0, bin_len = 0, hex_len = 0; 596 int str_len = 0, bin_len = 0, hex_len = 0;
596 xmlChar *key = NULL, *str = NULL, *padkey = NULL; 597 xmlChar *key = NULL, *str = NULL, *padkey = NULL;
597 xmlChar *bin = NULL, *hex = NULL; 598 xmlChar *bin = NULL, *hex = NULL;
598 xsltTransformContextPtr tctxt = NULL; 599 xsltTransformContextPtr tctxt = NULL;
599 600
600 if (nargs != 2) { 601 if (nargs != 2) {
601 xmlXPathSetArityError (ctxt); 602 xmlXPathSetArityError (ctxt);
602 return; 603 return;
603 } 604 }
604 tctxt = xsltXPathGetTransformContext(ctxt); 605 tctxt = xsltXPathGetTransformContext(ctxt);
605 606
606 str = xmlXPathPopString (ctxt); 607 str = xmlXPathPopString (ctxt);
607 str_len = xmlUTF8Strlen (str); 608 str_len = xmlStrlen (str);
608 609
609 if (str_len == 0) { 610 if (str_len == 0) {
610 xmlXPathReturnEmptyString (ctxt); 611 xmlXPathReturnEmptyString (ctxt);
611 xmlFree (str); 612 xmlFree (str);
612 return; 613 return;
613 } 614 }
614 615
615 key = xmlXPathPopString (ctxt); 616 key = xmlXPathPopString (ctxt);
616 key_len = xmlUTF8Strlen (key); 617 key_len = xmlStrlen (key);
617 618
618 if (key_len == 0) { 619 if (key_len == 0) {
619 xmlXPathReturnEmptyString (ctxt); 620 xmlXPathReturnEmptyString (ctxt);
620 xmlFree (key); 621 xmlFree (key);
621 xmlFree (str); 622 xmlFree (str);
622 return; 623 return;
623 } 624 }
624 625
625 padkey = xmlMallocAtomic (RC4_KEY_LENGTH + 1); 626 padkey = xmlMallocAtomic (RC4_KEY_LENGTH + 1);
626 if (padkey == NULL) { 627 if (padkey == NULL) {
627 xsltTransformError(tctxt, NULL, tctxt->inst, 628 xsltTransformError(tctxt, NULL, tctxt->inst,
628 "exsltCryptoRc4EncryptFunction: Failed to allocate padkey\n"); 629 "exsltCryptoRc4EncryptFunction: Failed to allocate padkey\n");
629 tctxt->state = XSLT_STATE_STOPPED; 630 tctxt->state = XSLT_STATE_STOPPED;
630 xmlXPathReturnEmptyString (ctxt); 631 xmlXPathReturnEmptyString (ctxt);
631 goto done; 632 goto done;
632 } 633 }
633 memset(padkey, 0, RC4_KEY_LENGTH + 1); 634 memset(padkey, 0, RC4_KEY_LENGTH + 1);
634 635
635 key_size = xmlUTF8Strsize (key, key_len); 636 if ((key_len > RC4_KEY_LENGTH) || (key_len < 0)) {
636 if ((key_size > RC4_KEY_LENGTH) || (key_size < 0)) {
637 xsltTransformError(tctxt, NULL, tctxt->inst, 637 xsltTransformError(tctxt, NULL, tctxt->inst,
638 "exsltCryptoRc4EncryptFunction: key size too long or key broken\n"); 638 "exsltCryptoRc4EncryptFunction: key size too long or key broken\n");
639 tctxt->state = XSLT_STATE_STOPPED; 639 tctxt->state = XSLT_STATE_STOPPED;
640 xmlXPathReturnEmptyString (ctxt); 640 xmlXPathReturnEmptyString (ctxt);
641 goto done; 641 goto done;
642 } 642 }
643 memcpy (padkey, key, key_size); 643 memcpy (padkey, key, key_len);
644 644
645 /* encrypt it */ 645 /* encrypt it */
646 bin_len = str_len; 646 bin_len = str_len;
647 bin = xmlStrdup (str); 647 bin = xmlStrdup (str);
648 if (bin == NULL) { 648 if (bin == NULL) {
649 xsltTransformError(tctxt, NULL, tctxt->inst, 649 xsltTransformError(tctxt, NULL, tctxt->inst,
650 "exsltCryptoRc4EncryptFunction: Failed to allocate string\n"); 650 "exsltCryptoRc4EncryptFunction: Failed to allocate string\n");
651 tctxt->state = XSLT_STATE_STOPPED; 651 tctxt->state = XSLT_STATE_STOPPED;
652 xmlXPathReturnEmptyString (ctxt); 652 xmlXPathReturnEmptyString (ctxt);
653 goto done; 653 goto done;
(...skipping 28 matching lines...) Expand all
682 /** 682 /**
683 * exsltCryptoRc4DecryptFunction: 683 * exsltCryptoRc4DecryptFunction:
684 * @ctxt: an XPath parser context 684 * @ctxt: an XPath parser context
685 * @nargs: the number of arguments 685 * @nargs: the number of arguments
686 * 686 *
687 * computes the sha1 hash of a string and returns as hex 687 * computes the sha1 hash of a string and returns as hex
688 */ 688 */
689 static void 689 static void
690 exsltCryptoRc4DecryptFunction (xmlXPathParserContextPtr ctxt, int nargs) { 690 exsltCryptoRc4DecryptFunction (xmlXPathParserContextPtr ctxt, int nargs) {
691 691
692 int key_len = 0, key_size = 0; 692 int key_len = 0;
693 int str_len = 0, bin_len = 0, ret_len = 0; 693 int str_len = 0, bin_len = 0, ret_len = 0;
694 xmlChar *key = NULL, *str = NULL, *padkey = NULL, *bin = 694 xmlChar *key = NULL, *str = NULL, *padkey = NULL, *bin =
695 NULL, *ret = NULL; 695 NULL, *ret = NULL;
696 xsltTransformContextPtr tctxt = NULL; 696 xsltTransformContextPtr tctxt = NULL;
697 697
698 if (nargs != 2) { 698 if (nargs != 2) {
699 xmlXPathSetArityError (ctxt); 699 xmlXPathSetArityError (ctxt);
700 return; 700 return;
701 } 701 }
702 tctxt = xsltXPathGetTransformContext(ctxt); 702 tctxt = xsltXPathGetTransformContext(ctxt);
703 703
704 str = xmlXPathPopString (ctxt); 704 str = xmlXPathPopString (ctxt);
705 str_len = xmlUTF8Strlen (str); 705 str_len = xmlStrlen (str);
706 706
707 if (str_len == 0) { 707 if (str_len == 0) {
708 xmlXPathReturnEmptyString (ctxt); 708 xmlXPathReturnEmptyString (ctxt);
709 xmlFree (str); 709 xmlFree (str);
710 return; 710 return;
711 } 711 }
712 712
713 key = xmlXPathPopString (ctxt); 713 key = xmlXPathPopString (ctxt);
714 key_len = xmlUTF8Strlen (key); 714 key_len = xmlStrlen (key);
715 715
716 if (key_len == 0) { 716 if (key_len == 0) {
717 xmlXPathReturnEmptyString (ctxt); 717 xmlXPathReturnEmptyString (ctxt);
718 xmlFree (key); 718 xmlFree (key);
719 xmlFree (str); 719 xmlFree (str);
720 return; 720 return;
721 } 721 }
722 722
723 padkey = xmlMallocAtomic (RC4_KEY_LENGTH + 1); 723 padkey = xmlMallocAtomic (RC4_KEY_LENGTH + 1);
724 if (padkey == NULL) { 724 if (padkey == NULL) {
725 xsltTransformError(tctxt, NULL, tctxt->inst, 725 xsltTransformError(tctxt, NULL, tctxt->inst,
726 "exsltCryptoRc4EncryptFunction: Failed to allocate padkey\n"); 726 "exsltCryptoRc4EncryptFunction: Failed to allocate padkey\n");
727 tctxt->state = XSLT_STATE_STOPPED; 727 tctxt->state = XSLT_STATE_STOPPED;
728 xmlXPathReturnEmptyString (ctxt); 728 xmlXPathReturnEmptyString (ctxt);
729 goto done; 729 goto done;
730 } 730 }
731 memset(padkey, 0, RC4_KEY_LENGTH + 1); 731 memset(padkey, 0, RC4_KEY_LENGTH + 1);
732 key_size = xmlUTF8Strsize (key, key_len); 732 if ((key_len > RC4_KEY_LENGTH) || (key_len < 0)) {
733 if ((key_size > RC4_KEY_LENGTH) || (key_size < 0)) {
734 xsltTransformError(tctxt, NULL, tctxt->inst, 733 xsltTransformError(tctxt, NULL, tctxt->inst,
735 "exsltCryptoRc4EncryptFunction: key size too long or key broken\n"); 734 "exsltCryptoRc4EncryptFunction: key size too long or key broken\n");
736 tctxt->state = XSLT_STATE_STOPPED; 735 tctxt->state = XSLT_STATE_STOPPED;
737 xmlXPathReturnEmptyString (ctxt); 736 xmlXPathReturnEmptyString (ctxt);
738 goto done; 737 goto done;
739 } 738 }
740 memcpy (padkey, key, key_size); 739 memcpy (padkey, key, key_len);
741 740
742 /* decode hex to binary */ 741 /* decode hex to binary */
743 bin_len = str_len; 742 bin_len = str_len;
744 bin = xmlMallocAtomic (bin_len); 743 bin = xmlMallocAtomic (bin_len);
745 if (bin == NULL) { 744 if (bin == NULL) {
746 xsltTransformError(tctxt, NULL, tctxt->inst, 745 xsltTransformError(tctxt, NULL, tctxt->inst,
747 "exsltCryptoRc4EncryptFunction: Failed to allocate string\n"); 746 "exsltCryptoRc4EncryptFunction: Failed to allocate string\n");
748 tctxt->state = XSLT_STATE_STOPPED; 747 tctxt->state = XSLT_STATE_STOPPED;
749 xmlXPathReturnEmptyString (ctxt); 748 xmlXPathReturnEmptyString (ctxt);
750 goto done; 749 goto done;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 * 806 *
808 * Registers the EXSLT - Crypto module 807 * Registers the EXSLT - Crypto module
809 */ 808 */
810 void 809 void
811 exsltCryptoRegister (void) { 810 exsltCryptoRegister (void) {
812 } 811 }
813 812
814 #endif /* defined(HAVE_CRYPTO) */ 813 #endif /* defined(HAVE_CRYPTO) */
815 814
816 #endif /* EXSLT_CRYPTO_ENABLED */ 815 #endif /* EXSLT_CRYPTO_ENABLED */
OLDNEW
« no previous file with comments | « third_party/libxslt/libexslt/Makefile.in ('k') | third_party/libxslt/libexslt/date.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698