Skip to content

Commit 095ad64

Browse files
committed
handle phpmapscript vulnerability in error handling (#6014)
1 parent f104189 commit 095ad64

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

mapscript/php/mapscript_error.c

+11-9
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
#include <stdarg.h>
3636
#include "../../maperror.h"
3737

38-
#define MAX_EXCEPTION_MSG 256
39-
4038
zend_class_entry *mapscript_ce_mapscriptexception;
4139

4240
#if PHP_VERSION_ID >= 70000
@@ -46,9 +44,10 @@ zval* mapscript_throw_exception(char *format TSRMLS_DC, ...)
4644
#endif
4745
{
4846
va_list args;
49-
char message[MAX_EXCEPTION_MSG];
47+
char message[MESSAGELENGTH];
5048
va_start(args, format);
51-
vsprintf(message, format, args);
49+
//prevent buffer overflow
50+
vsnprintf(message, MESSAGELENGTH, format, args);
5251
va_end(args);
5352
return zend_throw_exception(mapscript_ce_mapscriptexception, message, 0 TSRMLS_CC);
5453
}
@@ -60,7 +59,7 @@ zval* mapscript_throw_mapserver_exception(char *format TSRMLS_DC, ...)
6059
#endif
6160
{
6261
va_list args;
63-
char message[MAX_EXCEPTION_MSG];
62+
char message[MESSAGELENGTH];
6463
errorObj *ms_error;
6564

6665
ms_error = msGetErrorObj();
@@ -73,17 +72,20 @@ zval* mapscript_throw_mapserver_exception(char *format TSRMLS_DC, ...)
7372
}
7473

7574
va_start(args, format);
76-
vsprintf(message, format, args);
75+
//prevent buffer overflow
76+
vsnprintf(message, MESSAGELENGTH, format, args);
7777
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);
7980
}
8081

8182
void mapscript_report_php_error(int error_type, char *format TSRMLS_DC, ...)
8283
{
8384
va_list args;
84-
char message[MAX_EXCEPTION_MSG];
85+
char message[MESSAGELENGTH];
8586
va_start(args, format);
86-
vsprintf(message, format, args);
87+
//prevent buffer overflow
88+
vsnprintf(message, MESSAGELENGTH, format, args);
8789
va_end(args);
8890
php_error_docref(NULL TSRMLS_CC, error_type, "%s,", message);
8991
}

0 commit comments

Comments
 (0)