35
35
#include <stdarg.h>
36
36
#include "../../maperror.h"
37
37
38
- #define MAX_EXCEPTION_MSG 256
39
-
40
38
zend_class_entry * mapscript_ce_mapscriptexception ;
41
39
42
40
#if PHP_VERSION_ID >= 70000
@@ -46,9 +44,10 @@ zval* mapscript_throw_exception(char *format TSRMLS_DC, ...)
46
44
#endif
47
45
{
48
46
va_list args ;
49
- char message [MAX_EXCEPTION_MSG ];
47
+ char message [MESSAGELENGTH ];
50
48
va_start (args , format );
51
- vsprintf (message , format , args );
49
+ //prevent buffer overflow
50
+ vsnprintf (message , MESSAGELENGTH , format , args );
52
51
va_end (args );
53
52
return zend_throw_exception (mapscript_ce_mapscriptexception , message , 0 TSRMLS_CC );
54
53
}
@@ -60,7 +59,7 @@ zval* mapscript_throw_mapserver_exception(char *format TSRMLS_DC, ...)
60
59
#endif
61
60
{
62
61
va_list args ;
63
- char message [MAX_EXCEPTION_MSG ];
62
+ char message [MESSAGELENGTH ];
64
63
errorObj * ms_error ;
65
64
66
65
ms_error = msGetErrorObj ();
@@ -73,17 +72,20 @@ zval* mapscript_throw_mapserver_exception(char *format TSRMLS_DC, ...)
73
72
}
74
73
75
74
va_start (args , format );
76
- vsprintf (message , format , args );
75
+ //prevent buffer overflow
76
+ vsnprintf (message , MESSAGELENGTH , format , args );
77
77
va_end (args );
78
- return mapscript_throw_exception (message TSRMLS_CC );
78
+ //prevent format string attack
79
+ return mapscript_throw_exception ("%s" , message TSRMLS_CC );
79
80
}
80
81
81
82
void mapscript_report_php_error (int error_type , char * format TSRMLS_DC , ...)
82
83
{
83
84
va_list args ;
84
- char message [MAX_EXCEPTION_MSG ];
85
+ char message [MESSAGELENGTH ];
85
86
va_start (args , format );
86
- vsprintf (message , format , args );
87
+ //prevent buffer overflow
88
+ vsnprintf (message , MESSAGELENGTH , format , args );
87
89
va_end (args );
88
90
php_error_docref (NULL TSRMLS_CC , error_type , "%s," , message );
89
91
}
0 commit comments