aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/lscript/lscript_execute/lscript_execute.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/lscript/lscript_execute/lscript_execute.cpp')
-rw-r--r--linden/indra/lscript/lscript_execute/lscript_execute.cpp111
1 files changed, 73 insertions, 38 deletions
diff --git a/linden/indra/lscript/lscript_execute/lscript_execute.cpp b/linden/indra/lscript/lscript_execute/lscript_execute.cpp
index a81d706..b5d395e 100644
--- a/linden/indra/lscript/lscript_execute/lscript_execute.cpp
+++ b/linden/indra/lscript/lscript_execute/lscript_execute.cpp
@@ -39,7 +39,7 @@
39void (*binary_operations[LST_EOF][LST_EOF])(U8 *buffer, LSCRIPTOpCodesEnum opcode); 39void (*binary_operations[LST_EOF][LST_EOF])(U8 *buffer, LSCRIPTOpCodesEnum opcode);
40void (*unary_operations[LST_EOF])(U8 *buffer, LSCRIPTOpCodesEnum opcode); 40void (*unary_operations[LST_EOF])(U8 *buffer, LSCRIPTOpCodesEnum opcode);
41 41
42char *LSCRIPTRunTimeFaultStrings[LSRF_EOF] = 42char* LSCRIPTRunTimeFaultStrings[LSRF_EOF] = /*Flawfinder: ignore*/
43{ 43{
44 "invalid", // LSRF_INVALID, 44 "invalid", // LSRF_INVALID,
45 "Math Error", // LSRF_MATH, 45 "Math Error", // LSRF_MATH,
@@ -2596,6 +2596,7 @@ BOOL run_jump(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
2596 offset += arg; 2596 offset += arg;
2597 return FALSE; 2597 return FALSE;
2598} 2598}
2599
2599BOOL run_jumpif(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id) 2600BOOL run_jumpif(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
2600{ 2601{
2601 if (b_print) 2602 if (b_print)
@@ -2648,8 +2649,10 @@ BOOL run_jumpif(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
2648 else if (type == LST_STRING) 2649 else if (type == LST_STRING)
2649 { 2650 {
2650 S32 base_address = lscript_pop_int(buffer); 2651 S32 base_address = lscript_pop_int(buffer);
2651 // this bit of nastiness is to get around that code paths to local variables can result in lack of initialization 2652 // this bit of nastiness is to get around that code paths to
2652 // and function clean up of ref counts isn't based on scope (a mistake, I know) 2653 // local variables can result in lack of initialization and
2654 // function clean up of ref counts isn't based on scope (a
2655 // mistake, I know)
2653 S32 address = base_address + get_register(buffer, LREG_HR) - 1; 2656 S32 address = base_address + get_register(buffer, LREG_HR) - 1;
2654 if (address) 2657 if (address)
2655 { 2658 {
@@ -2662,7 +2665,7 @@ BOOL run_jumpif(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
2662 S32 size = toffset - string; 2665 S32 size = toffset - string;
2663 char *sdata = new char[size]; 2666 char *sdata = new char[size];
2664 bytestream2char(sdata, buffer, string); 2667 bytestream2char(sdata, buffer, string);
2665 if (strlen(sdata)) 2668 if (strlen(sdata)) /*Flawfinder: ignore*/
2666 { 2669 {
2667 offset += arg; 2670 offset += arg;
2668 } 2671 }
@@ -2674,8 +2677,10 @@ BOOL run_jumpif(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
2674 else if (type == LST_KEY) 2677 else if (type == LST_KEY)
2675 { 2678 {
2676 S32 base_address = lscript_pop_int(buffer); 2679 S32 base_address = lscript_pop_int(buffer);
2677 // this bit of nastiness is to get around that code paths to local variables can result in lack of initialization 2680 // this bit of nastiness is to get around that code paths to
2678 // and function clean up of ref counts isn't based on scope (a mistake, I know) 2681 // local variables can result in lack of initialization and
2682 // function clean up of ref counts isn't based on scope (a
2683 // mistake, I know)
2679 S32 address = base_address + get_register(buffer, LREG_HR) - 1; 2684 S32 address = base_address + get_register(buffer, LREG_HR) - 1;
2680 if (address) 2685 if (address)
2681 { 2686 {
@@ -2688,29 +2693,37 @@ BOOL run_jumpif(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
2688 S32 size = toffset - string; 2693 S32 size = toffset - string;
2689 char *sdata = new char[size]; 2694 char *sdata = new char[size];
2690 bytestream2char(sdata, buffer, string); 2695 bytestream2char(sdata, buffer, string);
2691 if (strlen(sdata)) 2696 if (strlen(sdata)) /*Flawfinder: ignore*/
2692 { 2697 {
2693 LLUUID id; 2698 LLUUID id;
2694 id.set(sdata); 2699 if (id.set(sdata) && id.notNull())
2695 if (id != LLUUID::null)
2696 offset += arg; 2700 offset += arg;
2697 } 2701 }
2698 delete [] sdata; 2702 delete [] sdata;
2699 } 2703 }
2700 lsa_decrease_ref_count(buffer, base_address); 2704 lsa_decrease_ref_count(buffer, base_address);
2701 } 2705 }
2702 else if (type == LST_LIST) 2706 }
2707 else if (type == LST_LIST)
2708 {
2709 S32 base_address = lscript_pop_int(buffer);
2710 S32 address = base_address + get_register(buffer, LREG_HR) - 1;
2711 if (address)
2703 { 2712 {
2704 S32 address = lscript_pop_int(buffer); 2713 if (safe_heap_check_address(buffer, address + SIZEOF_SCRIPT_ALLOC_ENTRY, 1))
2705 LLScriptLibData *list = lsa_get_data(buffer, address, TRUE);
2706 if (list->getListLength())
2707 { 2714 {
2708 offset += arg; 2715 LLScriptLibData *list = lsa_get_list_ptr(buffer, base_address, TRUE);
2716 if (list && list->getListLength())
2717 {
2718 offset += arg;
2719 }
2720 delete list;
2709 } 2721 }
2710 } 2722 }
2711 } 2723 }
2712 return FALSE; 2724 return FALSE;
2713} 2725}
2726
2714BOOL run_jumpnif(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id) 2727BOOL run_jumpnif(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
2715{ 2728{
2716 if (b_print) 2729 if (b_print)
@@ -2763,8 +2776,10 @@ BOOL run_jumpnif(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
2763 else if (type == LST_STRING) 2776 else if (type == LST_STRING)
2764 { 2777 {
2765 S32 base_address = lscript_pop_int(buffer); 2778 S32 base_address = lscript_pop_int(buffer);
2766 // this bit of nastiness is to get around that code paths to local variables can result in lack of initialization 2779 // this bit of nastiness is to get around that code paths to
2767 // and function clean up of ref counts isn't based on scope (a mistake, I know) 2780 // local variables can result in lack of initialization and
2781 // function clean up of ref counts isn't based on scope (a
2782 // mistake, I know)
2768 S32 address = base_address + get_register(buffer, LREG_HR) - 1; 2783 S32 address = base_address + get_register(buffer, LREG_HR) - 1;
2769 if (address) 2784 if (address)
2770 { 2785 {
@@ -2777,7 +2792,7 @@ BOOL run_jumpnif(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
2777 S32 size = toffset - string; 2792 S32 size = toffset - string;
2778 char *sdata = new char[size]; 2793 char *sdata = new char[size];
2779 bytestream2char(sdata, buffer, string); 2794 bytestream2char(sdata, buffer, string);
2780 if (!strlen(sdata)) 2795 if (!strlen(sdata)) /*Flawfinder: ignore*/
2781 { 2796 {
2782 offset += arg; 2797 offset += arg;
2783 } 2798 }
@@ -2789,8 +2804,10 @@ BOOL run_jumpnif(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
2789 else if (type == LST_KEY) 2804 else if (type == LST_KEY)
2790 { 2805 {
2791 S32 base_address = lscript_pop_int(buffer); 2806 S32 base_address = lscript_pop_int(buffer);
2792 // this bit of nastiness is to get around that code paths to local variables can result in lack of initialization 2807 // this bit of nastiness is to get around that code paths to
2793 // and function clean up of ref counts isn't based on scope (a mistake, I know) 2808 // local variables can result in lack of initialization and
2809 // function clean up of ref counts isn't based on scope (a
2810 // mistake, I know)
2794 S32 address = base_address + get_register(buffer, LREG_HR) - 1; 2811 S32 address = base_address + get_register(buffer, LREG_HR) - 1;
2795 if (address) 2812 if (address)
2796 { 2813 {
@@ -2803,11 +2820,10 @@ BOOL run_jumpnif(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
2803 S32 size = toffset - string; 2820 S32 size = toffset - string;
2804 char *sdata = new char[size]; 2821 char *sdata = new char[size];
2805 bytestream2char(sdata, buffer, string); 2822 bytestream2char(sdata, buffer, string);
2806 if (strlen(sdata)) 2823 if (strlen(sdata)) /*Flawfinder: ignore*/
2807 { 2824 {
2808 LLUUID id; 2825 LLUUID id;
2809 id.set(sdata); 2826 if (!id.set(sdata) || id.isNull())
2810 if (id == LLUUID::null)
2811 offset += arg; 2827 offset += arg;
2812 } 2828 }
2813 else 2829 else
@@ -2818,13 +2834,25 @@ BOOL run_jumpnif(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
2818 } 2834 }
2819 lsa_decrease_ref_count(buffer, base_address); 2835 lsa_decrease_ref_count(buffer, base_address);
2820 } 2836 }
2821 else if (type == LST_LIST) 2837 }
2838 else if (type == LST_LIST)
2839 {
2840 S32 base_address = lscript_pop_int(buffer);
2841 // this bit of nastiness is to get around that code paths to
2842 // local variables can result in lack of initialization and
2843 // function clean up of ref counts isn't based on scope (a
2844 // mistake, I know)
2845 S32 address = base_address + get_register(buffer, LREG_HR) - 1;
2846 if (address)
2822 { 2847 {
2823 S32 address = lscript_pop_int(buffer); 2848 if (safe_heap_check_address(buffer, address + SIZEOF_SCRIPT_ALLOC_ENTRY, 1))
2824 LLScriptLibData *list = lsa_get_data(buffer, address, TRUE);
2825 if (!list->getListLength())
2826 { 2849 {
2827 offset += arg; 2850 LLScriptLibData *list = lsa_get_list_ptr(buffer, base_address, TRUE);
2851 if (!list || !list->getListLength())
2852 {
2853 offset += arg;
2854 }
2855 delete list;
2828 } 2856 }
2829 } 2857 }
2830 } 2858 }
@@ -2954,7 +2982,7 @@ S32 axtoi(char *hexStg)
2954 2982
2955BOOL run_cast(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id) 2983BOOL run_cast(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
2956{ 2984{
2957 char caststr[1024]; 2985 char caststr[1024]; /*Flawfinder: ignore*/
2958 if (b_print) 2986 if (b_print)
2959 printf("[0x%X]\tCAST ", offset); 2987 printf("[0x%X]\tCAST ", offset);
2960 offset++; 2988 offset++;
@@ -2987,7 +3015,7 @@ BOOL run_cast(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
2987 case LST_STRING: 3015 case LST_STRING:
2988 { 3016 {
2989 S32 address, source = lscript_pop_int(buffer); 3017 S32 address, source = lscript_pop_int(buffer);
2990 sprintf(caststr, "%d", source); 3018 snprintf(caststr, sizeof(caststr), "%d", source); /*Flawfinder: ignore*/
2991 address = lsa_heap_add_data(buffer, new LLScriptLibData(caststr), get_max_heap_size(buffer), TRUE); 3019 address = lsa_heap_add_data(buffer, new LLScriptLibData(caststr), get_max_heap_size(buffer), TRUE);
2992 lscript_push(buffer, address); 3020 lscript_push(buffer, address);
2993 } 3021 }
@@ -3024,7 +3052,7 @@ BOOL run_cast(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
3024 { 3052 {
3025 S32 address; 3053 S32 address;
3026 F32 source = lscript_pop_float(buffer); 3054 F32 source = lscript_pop_float(buffer);
3027 sprintf(caststr, "%f", source); 3055 snprintf(caststr, sizeof(caststr), "%f", source); /*Flawfinder: ignore*/
3028 address = lsa_heap_add_data(buffer, new LLScriptLibData(caststr), get_max_heap_size(buffer), TRUE); 3056 address = lsa_heap_add_data(buffer, new LLScriptLibData(caststr), get_max_heap_size(buffer), TRUE);
3029 lscript_push(buffer, address); 3057 lscript_push(buffer, address);
3030 } 3058 }
@@ -3233,7 +3261,7 @@ BOOL run_cast(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
3233 S32 address; 3261 S32 address;
3234 LLVector3 source; 3262 LLVector3 source;
3235 lscript_pop_vector(buffer, source); 3263 lscript_pop_vector(buffer, source);
3236 sprintf(caststr, "<%5.5f, %5.5f, %5.5f>", source.mV[VX], source.mV[VY], source.mV[VZ]); 3264 snprintf(caststr, sizeof(caststr), "<%5.5f, %5.5f, %5.5f>", source.mV[VX], source.mV[VY], source.mV[VZ]); /*Flawfinder: ignore*/
3237 address = lsa_heap_add_data(buffer, new LLScriptLibData(caststr), get_max_heap_size(buffer), TRUE); 3265 address = lsa_heap_add_data(buffer, new LLScriptLibData(caststr), get_max_heap_size(buffer), TRUE);
3238 lscript_push(buffer, address); 3266 lscript_push(buffer, address);
3239 } 3267 }
@@ -3266,7 +3294,7 @@ BOOL run_cast(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
3266 S32 address; 3294 S32 address;
3267 LLQuaternion source; 3295 LLQuaternion source;
3268 lscript_pop_quaternion(buffer, source); 3296 lscript_pop_quaternion(buffer, source);
3269 sprintf(caststr, "<%5.5f, %5.5f, %5.5f, %5.5f>", source.mQ[VX], source.mQ[VY], source.mQ[VZ], source.mQ[VS]); 3297 snprintf(caststr, sizeof(caststr), "<%5.5f, %5.5f, %5.5f, %5.5f>", source.mQ[VX], source.mQ[VY], source.mQ[VZ], source.mQ[VS]); /*Flawfinder: ignore*/
3270 address = lsa_heap_add_data(buffer, new LLScriptLibData(caststr), get_max_heap_size(buffer), TRUE); 3298 address = lsa_heap_add_data(buffer, new LLScriptLibData(caststr), get_max_heap_size(buffer), TRUE);
3271 lscript_push(buffer, address); 3299 lscript_push(buffer, address);
3272 } 3300 }
@@ -3590,22 +3618,29 @@ void lscript_run(char *filename, BOOL b_debug)
3590 char *error; 3618 char *error;
3591 BOOL b_state; 3619 BOOL b_state;
3592 LLScriptExecute *execute = NULL; 3620 LLScriptExecute *execute = NULL;
3593 FILE *file = LLFile::fopen(filename, "r"); 3621 if (filename == NULL)
3622 {
3623 llerrs << "filename is empty" << llendl;
3624 // Just reporting error is likely not enough. Need
3625 // to check how to abort or error out gracefully
3626 // from this function. XXXTBD
3627 }
3628 FILE* file = LLFile::fopen(filename, "r"); /* Flawfinder: ignore */
3594 if (file) 3629 if (file)
3595 { 3630 {
3596 execute = new LLScriptExecute(file); 3631 execute = new LLScriptExecute(file);
3597 fclose(file); 3632 fclose(file);
3598 } 3633 }
3599 file = LLFile::fopen(filename, "r"); 3634 file = LLFile::fopen(filename, "r"); /* Flawfinder: ignore */
3600 if (file) 3635 if (file)
3601 { 3636 {
3602 FILE *fp = LLFile::fopen("lscript.parse", "w"); 3637 FILE* fp = LLFile::fopen("lscript.parse", "w"); /*Flawfinder: ignore*/
3603 LLScriptLSOParse *parse = new LLScriptLSOParse(file); 3638 LLScriptLSOParse *parse = new LLScriptLSOParse(file);
3604 parse->printData(fp); 3639 parse->printData(fp);
3605 fclose(file); 3640 fclose(file);
3606 fclose(fp); 3641 fclose(fp);
3607 } 3642 }
3608 file = LLFile::fopen(filename, "r"); 3643 file = LLFile::fopen(filename, "r"); /*Flawfinder: ignore*/
3609 if (file && execute) 3644 if (file && execute)
3610 { 3645 {
3611 timer.reset(); 3646 timer.reset();
@@ -3814,7 +3849,7 @@ BOOL run_calllib(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
3814 3849
3815 if (gScriptLibrary.mFunctions[arg]->mArgs) 3850 if (gScriptLibrary.mFunctions[arg]->mArgs)
3816 { 3851 {
3817 number = (S32)strlen(gScriptLibrary.mFunctions[arg]->mArgs); 3852 number = (S32)strlen(gScriptLibrary.mFunctions[arg]->mArgs); /*Flawfinder: ignore*/
3818 arguments = new LLScriptLibData[number]; 3853 arguments = new LLScriptLibData[number];
3819 } 3854 }
3820 else 3855 else
@@ -3885,7 +3920,7 @@ BOOL run_calllib_two_byte(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &i
3885 3920
3886 if (gScriptLibrary.mFunctions[arg]->mArgs) 3921 if (gScriptLibrary.mFunctions[arg]->mArgs)
3887 { 3922 {
3888 number = (S32)strlen(gScriptLibrary.mFunctions[arg]->mArgs); 3923 number = (S32)strlen(gScriptLibrary.mFunctions[arg]->mArgs); /*Flawfinder: ignore*/
3889 arguments = new LLScriptLibData[number]; 3924 arguments = new LLScriptLibData[number];
3890 } 3925 }
3891 else 3926 else