diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llmessage/lldatapacker.cpp | 221 |
1 files changed, 133 insertions, 88 deletions
diff --git a/linden/indra/llmessage/lldatapacker.cpp b/linden/indra/llmessage/lldatapacker.cpp index d4c8704..2448c40 100644 --- a/linden/indra/llmessage/lldatapacker.cpp +++ b/linden/indra/llmessage/lldatapacker.cpp | |||
@@ -4,6 +4,7 @@ | |||
4 | * | 4 | * |
5 | * Copyright (c) 2006-2007, Linden Research, Inc. | 5 | * Copyright (c) 2006-2007, Linden Research, Inc. |
6 | * | 6 | * |
7 | * Second Life Viewer Source Code | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | 8 | * The source code in this file ("Source Code") is provided by Linden Lab |
8 | * to you under the terms of the GNU General Public License, version 2.0 | 9 | * to you under the terms of the GNU General Public License, version 2.0 |
9 | * ("GPL"), unless you have obtained a separate licensing agreement | 10 | * ("GPL"), unless you have obtained a separate licensing agreement |
@@ -557,7 +558,7 @@ void LLDataPackerBinaryBuffer::dumpBufferToLog() | |||
557 | S32 cur_line = 0; | 558 | S32 cur_line = 0; |
558 | for (i = 0; i < mBufferSize; i++) | 559 | for (i = 0; i < mBufferSize; i++) |
559 | { | 560 | { |
560 | snprintf(line_buffer + cur_line_pos*3, sizeof(line_buffer) - cur_line_pos*3, "%02x ", mBufferp[i]); /*Flawfinder: ignore*/ | 561 | snprintf(line_buffer + cur_line_pos*3, sizeof(line_buffer) - cur_line_pos*3, "%02x ", mBufferp[i]); /* Flawfinder: ignore */ |
561 | cur_line_pos++; | 562 | cur_line_pos++; |
562 | if (cur_line_pos >= 16) | 563 | if (cur_line_pos >= 16) |
563 | { | 564 | { |
@@ -582,7 +583,7 @@ BOOL LLDataPackerAsciiBuffer::packString(const char *value, const char *name) | |||
582 | int numCopied = 0; | 583 | int numCopied = 0; |
583 | if (mWriteEnabled) | 584 | if (mWriteEnabled) |
584 | { | 585 | { |
585 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%s\n", value); /*Flawfinder: ignore*/ | 586 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%s\n", value); /* Flawfinder: ignore */ |
586 | } | 587 | } |
587 | else | 588 | else |
588 | { | 589 | { |
@@ -591,14 +592,15 @@ BOOL LLDataPackerAsciiBuffer::packString(const char *value, const char *name) | |||
591 | 592 | ||
592 | // snprintf returns number of bytes that would have been written | 593 | // snprintf returns number of bytes that would have been written |
593 | // had the output not being truncated. In that case, it will | 594 | // had the output not being truncated. In that case, it will |
594 | // return >= passed in size value. so a check needs to be added | 595 | // return either -1 or value >= passed in size value . So a check needs to be added |
595 | // to detect truncation, and if there is any, only account for the | 596 | // to detect truncation, and if there is any, only account for the |
596 | // actual number of bytes written..and not what could have been | 597 | // actual number of bytes written..and not what could have been |
597 | // written. | 598 | // written. |
598 | if (numCopied > getBufferSize()-getCurrentSize()) | 599 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) |
599 | { | 600 | { |
600 | // *NOTE: I believe we need to mark a failure bit at this point. | 601 | // *NOTE: I believe we need to mark a failure bit at this point. |
601 | numCopied = getBufferSize()-getCurrentSize(); | 602 | numCopied = getBufferSize()-getCurrentSize(); |
603 | llwarns << "LLDataPackerAsciiBuffer::packString: string truncated: " << value << llendl; | ||
602 | } | 604 | } |
603 | mCurBufferp += numCopied; | 605 | mCurBufferp += numCopied; |
604 | return success; | 606 | return success; |
@@ -626,7 +628,7 @@ BOOL LLDataPackerAsciiBuffer::packBinaryData(const U8 *value, S32 size, const ch | |||
626 | int numCopied = 0; | 628 | int numCopied = 0; |
627 | if (mWriteEnabled) | 629 | if (mWriteEnabled) |
628 | { | 630 | { |
629 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%010d ", size); /*Flawfinder: ignore*/ | 631 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%010d ", size); /* Flawfinder: ignore */ |
630 | 632 | ||
631 | // snprintf returns number of bytes that would have been | 633 | // snprintf returns number of bytes that would have been |
632 | // written had the output not being truncated. In that case, | 634 | // written had the output not being truncated. In that case, |
@@ -634,9 +636,10 @@ BOOL LLDataPackerAsciiBuffer::packBinaryData(const U8 *value, S32 size, const ch | |||
634 | // to be added to detect truncation, and if there is any, only | 636 | // to be added to detect truncation, and if there is any, only |
635 | // account for the actual number of bytes written..and not | 637 | // account for the actual number of bytes written..and not |
636 | // what could have been written. | 638 | // what could have been written. |
637 | if (numCopied > getBufferSize()-getCurrentSize()) | 639 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) |
638 | { | 640 | { |
639 | numCopied = getBufferSize()-getCurrentSize(); | 641 | numCopied = getBufferSize()-getCurrentSize(); |
642 | llwarns << "LLDataPackerAsciiBuffer::packBinaryData: number truncated: " << size << llendl; | ||
640 | } | 643 | } |
641 | mCurBufferp += numCopied; | 644 | mCurBufferp += numCopied; |
642 | 645 | ||
@@ -645,10 +648,11 @@ BOOL LLDataPackerAsciiBuffer::packBinaryData(const U8 *value, S32 size, const ch | |||
645 | BOOL bBufferFull = FALSE; | 648 | BOOL bBufferFull = FALSE; |
646 | for (i = 0; i < size && !bBufferFull; i++) | 649 | for (i = 0; i < size && !bBufferFull; i++) |
647 | { | 650 | { |
648 | numCopied = snprintf(mCurBufferp, getBufferSize()-getCurrentSize(), "%02x ", value[i]); /* Flawfinder: ignore */ | 651 | numCopied = snprintf(mCurBufferp, getBufferSize()-getCurrentSize(), "%02x ", value[i]); /* Flawfinder: ignore */ |
649 | if (numCopied > getBufferSize()-getCurrentSize()) | 652 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) |
650 | { | 653 | { |
651 | numCopied = getBufferSize()-getCurrentSize(); | 654 | numCopied = getBufferSize()-getCurrentSize(); |
655 | llwarns << "LLDataPackerAsciiBuffer::packBinaryData: data truncated: " << llendl; | ||
652 | bBufferFull = TRUE; | 656 | bBufferFull = TRUE; |
653 | } | 657 | } |
654 | mCurBufferp += numCopied; | 658 | mCurBufferp += numCopied; |
@@ -656,10 +660,11 @@ BOOL LLDataPackerAsciiBuffer::packBinaryData(const U8 *value, S32 size, const ch | |||
656 | 660 | ||
657 | if (!bBufferFull) | 661 | if (!bBufferFull) |
658 | { | 662 | { |
659 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(), "\n"); /* Flawfinder: ignore */ | 663 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(), "\n"); /* Flawfinder: ignore */ |
660 | if (numCopied > getBufferSize()-getCurrentSize()) | 664 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) |
661 | { | 665 | { |
662 | numCopied = getBufferSize()-getCurrentSize(); | 666 | numCopied = getBufferSize()-getCurrentSize(); |
667 | llwarns << "LLDataPackerAsciiBuffer::packBinaryData: newline truncated: " << llendl; | ||
663 | } | 668 | } |
664 | mCurBufferp += numCopied; | 669 | mCurBufferp += numCopied; |
665 | } | 670 | } |
@@ -717,10 +722,11 @@ BOOL LLDataPackerAsciiBuffer::packBinaryDataFixed(const U8 *value, S32 size, con | |||
717 | BOOL bBufferFull = FALSE; | 722 | BOOL bBufferFull = FALSE; |
718 | for (i = 0; i < size && !bBufferFull; i++) | 723 | for (i = 0; i < size && !bBufferFull; i++) |
719 | { | 724 | { |
720 | numCopied = snprintf(mCurBufferp, getBufferSize()-getCurrentSize(), "%02x ", value[i]); /* Flawfinder: ignore */ | 725 | numCopied = snprintf(mCurBufferp, getBufferSize()-getCurrentSize(), "%02x ", value[i]); /* Flawfinder: ignore */ |
721 | if (numCopied > getBufferSize()-getCurrentSize()) | 726 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) |
722 | { | 727 | { |
723 | numCopied = getBufferSize()-getCurrentSize(); | 728 | numCopied = getBufferSize()-getCurrentSize(); |
729 | llwarns << "LLDataPackerAsciiBuffer::packBinaryDataFixed: data truncated: " << llendl; | ||
724 | bBufferFull = TRUE; | 730 | bBufferFull = TRUE; |
725 | } | 731 | } |
726 | mCurBufferp += numCopied; | 732 | mCurBufferp += numCopied; |
@@ -728,10 +734,11 @@ BOOL LLDataPackerAsciiBuffer::packBinaryDataFixed(const U8 *value, S32 size, con | |||
728 | } | 734 | } |
729 | if (!bBufferFull) | 735 | if (!bBufferFull) |
730 | { | 736 | { |
731 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(), "\n"); /* Flawfinder: ignore */ | 737 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(), "\n"); /* Flawfinder: ignore */ |
732 | if (numCopied > getBufferSize()-getCurrentSize()) | 738 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) |
733 | { | 739 | { |
734 | numCopied = getBufferSize()-getCurrentSize(); | 740 | numCopied = getBufferSize()-getCurrentSize(); |
741 | llwarns << "LLDataPackerAsciiBuffer::packBinaryDataFixed: newline truncated: " << llendl; | ||
735 | } | 742 | } |
736 | 743 | ||
737 | mCurBufferp += numCopied; | 744 | mCurBufferp += numCopied; |
@@ -781,21 +788,24 @@ BOOL LLDataPackerAsciiBuffer::packU8(const U8 value, const char *name) | |||
781 | int numCopied = 0; | 788 | int numCopied = 0; |
782 | if (mWriteEnabled) | 789 | if (mWriteEnabled) |
783 | { | 790 | { |
784 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%d\n", value); /*Flawfinder: ignore*/ | 791 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%d\n", value); /* Flawfinder: ignore */ |
785 | } | 792 | } |
786 | else | 793 | else |
787 | { | 794 | { |
788 | // just do the write to a temp buffer to get the length | 795 | // just do the write to a temp buffer to get the length |
789 | numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%d\n", value); /* Flawfinder: ignore */ | 796 | numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%d\n", value); /* Flawfinder: ignore */ |
790 | } | 797 | } |
791 | 798 | ||
792 | // snprintf returns number of bytes that would have been written had the | 799 | // snprintf returns number of bytes that would have been written |
793 | // output not being truncated. In that case, it will retuen >= passed in size value. | 800 | // had the output not being truncated. In that case, it will |
794 | // so a check needs to be added to detect truncation, and if there is any, | 801 | // return either -1 or value >= passed in size value . So a check needs to be added |
795 | // only account for the actual number of bytes written..and not what could have been written. | 802 | // to detect truncation, and if there is any, only account for the |
796 | if (numCopied > getBufferSize()-getCurrentSize()) | 803 | // actual number of bytes written..and not what could have been |
804 | // written. | ||
805 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) | ||
797 | { | 806 | { |
798 | numCopied = getBufferSize()-getCurrentSize(); | 807 | numCopied = getBufferSize()-getCurrentSize(); |
808 | llwarns << "LLDataPackerAsciiBuffer::packU8: val truncated: " << llendl; | ||
799 | } | 809 | } |
800 | 810 | ||
801 | mCurBufferp += numCopied; | 811 | mCurBufferp += numCopied; |
@@ -826,20 +836,23 @@ BOOL LLDataPackerAsciiBuffer::packU16(const U16 value, const char *name) | |||
826 | int numCopied = 0; | 836 | int numCopied = 0; |
827 | if (mWriteEnabled) | 837 | if (mWriteEnabled) |
828 | { | 838 | { |
829 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%d\n", value); /*Flawfinder: ignore*/ | 839 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%d\n", value); /* Flawfinder: ignore */ |
830 | } | 840 | } |
831 | else | 841 | else |
832 | { | 842 | { |
833 | numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%d\n", value); /* Flawfinder: ignore */ | 843 | numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%d\n", value); /* Flawfinder: ignore */ |
834 | } | 844 | } |
835 | 845 | ||
836 | // snprintf returns number of bytes that would have been written had the | 846 | // snprintf returns number of bytes that would have been written |
837 | // output not being truncated. In that case, it will retuen >= passed in size value. | 847 | // had the output not being truncated. In that case, it will |
838 | // so a check needs to be added to detect truncation, and if there is any, | 848 | // return either -1 or value >= passed in size value . So a check needs to be added |
839 | // only account for the actual number of bytes written..and not what could have been written. | 849 | // to detect truncation, and if there is any, only account for the |
840 | if (numCopied > getBufferSize()-getCurrentSize()) | 850 | // actual number of bytes written..and not what could have been |
851 | // written. | ||
852 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) | ||
841 | { | 853 | { |
842 | numCopied = getBufferSize()-getCurrentSize(); | 854 | numCopied = getBufferSize()-getCurrentSize(); |
855 | llwarns << "LLDataPackerAsciiBuffer::packU16: val truncated: " << llendl; | ||
843 | } | 856 | } |
844 | 857 | ||
845 | mCurBufferp += numCopied; | 858 | mCurBufferp += numCopied; |
@@ -871,19 +884,22 @@ BOOL LLDataPackerAsciiBuffer::packU32(const U32 value, const char *name) | |||
871 | int numCopied = 0; | 884 | int numCopied = 0; |
872 | if (mWriteEnabled) | 885 | if (mWriteEnabled) |
873 | { | 886 | { |
874 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%u\n", value); /* Flawfinder: ignore */ | 887 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%u\n", value); /* Flawfinder: ignore */ |
875 | } | 888 | } |
876 | else | 889 | else |
877 | { | 890 | { |
878 | numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%u\n", value); /* Flawfinder: ignore */ | 891 | numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%u\n", value); /* Flawfinder: ignore */ |
879 | } | 892 | } |
880 | // snprintf returns number of bytes that would have been written had the | 893 | // snprintf returns number of bytes that would have been written |
881 | // output not being truncated. In that case, it will retuen >= passed in size value. | 894 | // had the output not being truncated. In that case, it will |
882 | // so a check needs to be added to detect truncation, and if there is any, | 895 | // return either -1 or value >= passed in size value . So a check needs to be added |
883 | // only account for the actual number of bytes written..and not what could have been written. | 896 | // to detect truncation, and if there is any, only account for the |
884 | if (numCopied > getBufferSize()-getCurrentSize()) | 897 | // actual number of bytes written..and not what could have been |
898 | // written. | ||
899 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) | ||
885 | { | 900 | { |
886 | numCopied = getBufferSize()-getCurrentSize(); | 901 | numCopied = getBufferSize()-getCurrentSize(); |
902 | llwarns << "LLDataPackerAsciiBuffer::packU32: val truncated: " << llendl; | ||
887 | } | 903 | } |
888 | 904 | ||
889 | mCurBufferp += numCopied; | 905 | mCurBufferp += numCopied; |
@@ -912,19 +928,22 @@ BOOL LLDataPackerAsciiBuffer::packS32(const S32 value, const char *name) | |||
912 | int numCopied = 0; | 928 | int numCopied = 0; |
913 | if (mWriteEnabled) | 929 | if (mWriteEnabled) |
914 | { | 930 | { |
915 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%d\n", value); /* Flawfinder: ignore */ | 931 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%d\n", value); /* Flawfinder: ignore */ |
916 | } | 932 | } |
917 | else | 933 | else |
918 | { | 934 | { |
919 | numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%d\n", value); /* Flawfinder: ignore */ | 935 | numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%d\n", value); /* Flawfinder: ignore */ |
920 | } | 936 | } |
921 | // snprintf returns number of bytes that would have been written had the | 937 | // snprintf returns number of bytes that would have been written |
922 | // output not being truncated. In that case, it will retuen >= passed in size value. | 938 | // had the output not being truncated. In that case, it will |
923 | // so a check needs to be added to detect truncation, and if there is any, | 939 | // return either -1 or value >= passed in size value . So a check needs to be added |
924 | // only account for the actual number of bytes written..and not what could have been written. | 940 | // to detect truncation, and if there is any, only account for the |
925 | if (numCopied > getBufferSize()-getCurrentSize()) | 941 | // actual number of bytes written..and not what could have been |
942 | // written. | ||
943 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) | ||
926 | { | 944 | { |
927 | numCopied = getBufferSize()-getCurrentSize(); | 945 | numCopied = getBufferSize()-getCurrentSize(); |
946 | llwarns << "LLDataPackerAsciiBuffer::packS32: val truncated: " << llendl; | ||
928 | } | 947 | } |
929 | 948 | ||
930 | mCurBufferp += numCopied; | 949 | mCurBufferp += numCopied; |
@@ -953,19 +972,22 @@ BOOL LLDataPackerAsciiBuffer::packF32(const F32 value, const char *name) | |||
953 | int numCopied = 0; | 972 | int numCopied = 0; |
954 | if (mWriteEnabled) | 973 | if (mWriteEnabled) |
955 | { | 974 | { |
956 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%g\n", value); /* Flawfinder: ignore */ | 975 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%g\n", value); /* Flawfinder: ignore */ |
957 | } | 976 | } |
958 | else | 977 | else |
959 | { | 978 | { |
960 | numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%g\n", value); /* Flawfinder: ignore */ | 979 | numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%g\n", value); /* Flawfinder: ignore */ |
961 | } | 980 | } |
962 | // snprintf returns number of bytes that would have been written had the | 981 | // snprintf returns number of bytes that would have been written |
963 | // output not being truncated. In that case, it will retuen >= passed in size value. | 982 | // had the output not being truncated. In that case, it will |
964 | // so a check needs to be added to detect truncation, and if there is any, | 983 | // return either -1 or value >= passed in size value . So a check needs to be added |
965 | // only account for the actual number of bytes written..and not what could have been written. | 984 | // to detect truncation, and if there is any, only account for the |
966 | if (numCopied > getBufferSize()-getCurrentSize()) | 985 | // actual number of bytes written..and not what could have been |
986 | // written. | ||
987 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) | ||
967 | { | 988 | { |
968 | numCopied = getBufferSize()-getCurrentSize(); | 989 | numCopied = getBufferSize()-getCurrentSize(); |
990 | llwarns << "LLDataPackerAsciiBuffer::packF32: val truncated: " << llendl; | ||
969 | } | 991 | } |
970 | 992 | ||
971 | mCurBufferp += numCopied; | 993 | mCurBufferp += numCopied; |
@@ -994,19 +1016,22 @@ BOOL LLDataPackerAsciiBuffer::packColor4(const LLColor4 &value, const char *name | |||
994 | int numCopied = 0; | 1016 | int numCopied = 0; |
995 | if (mWriteEnabled) | 1017 | if (mWriteEnabled) |
996 | { | 1018 | { |
997 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%g %g %g %g\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ | 1019 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%g %g %g %g\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ |
998 | } | 1020 | } |
999 | else | 1021 | else |
1000 | { | 1022 | { |
1001 | numCopied = snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%g %g %g %g\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ | 1023 | numCopied = snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%g %g %g %g\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ |
1002 | } | 1024 | } |
1003 | // snprintf returns number of bytes that would have been written had the | 1025 | // snprintf returns number of bytes that would have been written |
1004 | // output not being truncated. In that case, it will retuen >= passed in size value. | 1026 | // had the output not being truncated. In that case, it will |
1005 | // so a check needs to be added to detect truncation, and if there is any, | 1027 | // return either -1 or value >= passed in size value . So a check needs to be added |
1006 | // only account for the actual number of bytes written..and not what could have been written. | 1028 | // to detect truncation, and if there is any, only account for the |
1007 | if (numCopied > getBufferSize()-getCurrentSize()) | 1029 | // actual number of bytes written..and not what could have been |
1030 | // written. | ||
1031 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) | ||
1008 | { | 1032 | { |
1009 | numCopied = getBufferSize()-getCurrentSize(); | 1033 | numCopied = getBufferSize()-getCurrentSize(); |
1034 | llwarns << "LLDataPackerAsciiBuffer::packColor4: truncated: " << llendl; | ||
1010 | } | 1035 | } |
1011 | 1036 | ||
1012 | mCurBufferp += numCopied; | 1037 | mCurBufferp += numCopied; |
@@ -1034,19 +1059,22 @@ BOOL LLDataPackerAsciiBuffer::packColor4U(const LLColor4U &value, const char *na | |||
1034 | int numCopied = 0; | 1059 | int numCopied = 0; |
1035 | if (mWriteEnabled) | 1060 | if (mWriteEnabled) |
1036 | { | 1061 | { |
1037 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%d %d %d %d\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ | 1062 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%d %d %d %d\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ |
1038 | } | 1063 | } |
1039 | else | 1064 | else |
1040 | { | 1065 | { |
1041 | numCopied = snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%d %d %d %d\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ | 1066 | numCopied = snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%d %d %d %d\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ |
1042 | } | 1067 | } |
1043 | // snprintf returns number of bytes that would have been written had the | 1068 | // snprintf returns number of bytes that would have been written |
1044 | // output not being truncated. In that case, it will retuen >= passed in size value. | 1069 | // had the output not being truncated. In that case, it will |
1045 | // so a check needs to be added to detect truncation, and if there is any, | 1070 | // return either -1 or value >= passed in size value . So a check needs to be added |
1046 | // only account for the actual number of bytes written..and not what could have been written. | 1071 | // to detect truncation, and if there is any, only account for the |
1047 | if (numCopied > getBufferSize()-getCurrentSize()) | 1072 | // actual number of bytes written..and not what could have been |
1073 | // written. | ||
1074 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) | ||
1048 | { | 1075 | { |
1049 | numCopied = getBufferSize()-getCurrentSize(); | 1076 | numCopied = getBufferSize()-getCurrentSize(); |
1077 | llwarns << "LLDataPackerAsciiBuffer::packColor4U: truncated: " << llendl; | ||
1050 | } | 1078 | } |
1051 | 1079 | ||
1052 | mCurBufferp += numCopied; | 1080 | mCurBufferp += numCopied; |
@@ -1085,15 +1113,18 @@ BOOL LLDataPackerAsciiBuffer::packVector2(const LLVector2 &value, const char *na | |||
1085 | } | 1113 | } |
1086 | else | 1114 | else |
1087 | { | 1115 | { |
1088 | numCopied = snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%g %g\n", value.mV[0], value.mV[1]); /* Flawfinder: ignore */ | 1116 | numCopied = snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%g %g\n", value.mV[0], value.mV[1]); /* Flawfinder: ignore */ |
1089 | } | 1117 | } |
1090 | // snprintf returns number of bytes that would have been written had the | 1118 | // snprintf returns number of bytes that would have been written |
1091 | // output not being truncated. In that case, it will retuen >= passed in size value. | 1119 | // had the output not being truncated. In that case, it will |
1092 | // so a check needs to be added to detect truncation, and if there is any, | 1120 | // return either -1 or value >= passed in size value . So a check needs to be added |
1093 | // only account for the actual number of bytes written..and not what could have been written. | 1121 | // to detect truncation, and if there is any, only account for the |
1094 | if (numCopied > getBufferSize()-getCurrentSize()) | 1122 | // actual number of bytes written..and not what could have been |
1123 | // written. | ||
1124 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) | ||
1095 | { | 1125 | { |
1096 | numCopied = getBufferSize()-getCurrentSize(); | 1126 | numCopied = getBufferSize()-getCurrentSize(); |
1127 | llwarns << "LLDataPackerAsciiBuffer::packVector2: truncated: " << llendl; | ||
1097 | } | 1128 | } |
1098 | 1129 | ||
1099 | mCurBufferp += numCopied; | 1130 | mCurBufferp += numCopied; |
@@ -1128,13 +1159,16 @@ BOOL LLDataPackerAsciiBuffer::packVector3(const LLVector3 &value, const char *na | |||
1128 | { | 1159 | { |
1129 | numCopied = snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%g %g %g\n", value.mV[0], value.mV[1], value.mV[2]); /* Flawfinder: ignore */ | 1160 | numCopied = snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%g %g %g\n", value.mV[0], value.mV[1], value.mV[2]); /* Flawfinder: ignore */ |
1130 | } | 1161 | } |
1131 | // snprintf returns number of bytes that would have been written had the | 1162 | // snprintf returns number of bytes that would have been written |
1132 | // output not being truncated. In that case, it will retuen >= passed in size value. | 1163 | // had the output not being truncated. In that case, it will |
1133 | // so a check needs to be added to detect truncation, and if there is any, | 1164 | // return either -1 or value >= passed in size value . So a check needs to be added |
1134 | // only account for the actual number of bytes written..and not what could have been written. | 1165 | // to detect truncation, and if there is any, only account for the |
1135 | if (numCopied > getBufferSize()-getCurrentSize()) | 1166 | // actual number of bytes written..and not what could have been |
1167 | // written. | ||
1168 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) | ||
1136 | { | 1169 | { |
1137 | numCopied = getBufferSize()-getCurrentSize(); | 1170 | numCopied = getBufferSize()-getCurrentSize(); |
1171 | llwarns << "LLDataPackerAsciiBuffer::packVector3: truncated: " << llendl; | ||
1138 | } | 1172 | } |
1139 | 1173 | ||
1140 | mCurBufferp += numCopied; | 1174 | mCurBufferp += numCopied; |
@@ -1168,13 +1202,16 @@ BOOL LLDataPackerAsciiBuffer::packVector4(const LLVector4 &value, const char *na | |||
1168 | { | 1202 | { |
1169 | numCopied = snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%g %g %g %g\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ | 1203 | numCopied = snprintf(DUMMY_BUFFER,sizeof(DUMMY_BUFFER),"%g %g %g %g\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); /* Flawfinder: ignore */ |
1170 | } | 1204 | } |
1171 | // snprintf returns number of bytes that would have been written had the | 1205 | // snprintf returns number of bytes that would have been written |
1172 | // output not being truncated. In that case, it will retuen >= passed in size value. | 1206 | // had the output not being truncated. In that case, it will |
1173 | // so a check needs to be added to detect truncation, and if there is any, | 1207 | // return either -1 or value >= passed in size value . So a check needs to be added |
1174 | // only account for the actual number of bytes written..and not what could have been written. | 1208 | // to detect truncation, and if there is any, only account for the |
1175 | if (numCopied > getBufferSize()-getCurrentSize()) | 1209 | // actual number of bytes written..and not what could have been |
1210 | // written. | ||
1211 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) | ||
1176 | { | 1212 | { |
1177 | numCopied = getBufferSize()-getCurrentSize(); | 1213 | numCopied = getBufferSize()-getCurrentSize(); |
1214 | llwarns << "LLDataPackerAsciiBuffer::packVector4: truncated: " << llendl; | ||
1178 | } | 1215 | } |
1179 | 1216 | ||
1180 | mCurBufferp += numCopied; | 1217 | mCurBufferp += numCopied; |
@@ -1212,13 +1249,16 @@ BOOL LLDataPackerAsciiBuffer::packUUID(const LLUUID &value, const char *name) | |||
1212 | { | 1249 | { |
1213 | numCopied = 64 + 1; // UUID + newline | 1250 | numCopied = 64 + 1; // UUID + newline |
1214 | } | 1251 | } |
1215 | // snprintf returns number of bytes that would have been written had the | 1252 | // snprintf returns number of bytes that would have been written |
1216 | // output not being truncated. In that case, it will retuen >= passed in size value. | 1253 | // had the output not being truncated. In that case, it will |
1217 | // so a check needs to be added to detect truncation, and if there is any, | 1254 | // return either -1 or value >= passed in size value . So a check needs to be added |
1218 | // only account for the actual number of bytes written..and not what could have been written. | 1255 | // to detect truncation, and if there is any, only account for the |
1219 | if (numCopied > getBufferSize()-getCurrentSize()) | 1256 | // actual number of bytes written..and not what could have been |
1257 | // written. | ||
1258 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) | ||
1220 | { | 1259 | { |
1221 | numCopied = getBufferSize()-getCurrentSize(); | 1260 | numCopied = getBufferSize()-getCurrentSize(); |
1261 | llwarns << "LLDataPackerAsciiBuffer::packUUID: truncated: " << llendl; | ||
1222 | success = FALSE; | 1262 | success = FALSE; |
1223 | } | 1263 | } |
1224 | mCurBufferp += numCopied; | 1264 | mCurBufferp += numCopied; |
@@ -1254,21 +1294,26 @@ void LLDataPackerAsciiBuffer::writeIndentedName(const char *name) | |||
1254 | int numCopied = 0; | 1294 | int numCopied = 0; |
1255 | if (mWriteEnabled) | 1295 | if (mWriteEnabled) |
1256 | { | 1296 | { |
1257 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%s\t", name); /* Flawfinder: ignore */ | 1297 | numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%s\t", name); /* Flawfinder: ignore */ |
1258 | } | 1298 | } |
1259 | else | 1299 | else |
1260 | { | 1300 | { |
1261 | numCopied = (S32)strlen(name) + 1; /* Flawfinder: ignore */ //name + tab | 1301 | numCopied = (S32)strlen(name) + 1; /* Flawfinder: ignore */ //name + tab |
1262 | } | 1302 | } |
1263 | 1303 | ||
1264 | // snprintf returns number of bytes that would have been written had the | 1304 | // snprintf returns number of bytes that would have been written |
1265 | // output not being truncated. In that case, it will retuen >= passed in size value. | 1305 | // had the output not being truncated. In that case, it will |
1266 | // so a check needs to be added to detect truncation, and if there is any, | 1306 | // return either -1 or value >= passed in size value . So a check needs to be added |
1267 | // only account for the actual number of bytes written..and not what could have been written. | 1307 | // to detect truncation, and if there is any, only account for the |
1268 | if (numCopied > getBufferSize()-getCurrentSize()) | 1308 | // actual number of bytes written..and not what could have been |
1309 | // written. | ||
1310 | if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) | ||
1269 | { | 1311 | { |
1270 | numCopied = getBufferSize()-getCurrentSize(); | 1312 | numCopied = getBufferSize()-getCurrentSize(); |
1313 | llwarns << "LLDataPackerAsciiBuffer::writeIndentedName: truncated: " << llendl; | ||
1271 | } | 1314 | } |
1315 | |||
1316 | mCurBufferp += numCopied; | ||
1272 | } | 1317 | } |
1273 | } | 1318 | } |
1274 | 1319 | ||
@@ -1424,7 +1469,7 @@ BOOL LLDataPackerAsciiFile::packBinaryDataFixed(const U8 *value, S32 size, const | |||
1424 | S32 i; | 1469 | S32 i; |
1425 | for (i = 0; i < size; i++) | 1470 | for (i = 0; i < size; i++) |
1426 | { | 1471 | { |
1427 | snprintf(buffer, sizeof(buffer), "%02x ", value[i]); /*Flawfinder: ignore*/ | 1472 | snprintf(buffer, sizeof(buffer), "%02x ", value[i]); /* Flawfinder: ignore */ |
1428 | *mOutputStream << buffer; | 1473 | *mOutputStream << buffer; |
1429 | } | 1474 | } |
1430 | *mOutputStream << "\n"; | 1475 | *mOutputStream << "\n"; |