Skip to content

Commit fad80da

Browse files
committed
Merge branch 'master' of https://git.php.net/repository/php-src
* 'master' of https://git.php.net/repository/php-src: Make message and format arguments const char * to avoid build warning about invalid cast. Copy dba_*() keys before converting to string.
2 parents b3a17e5 + c760ff1 commit fad80da

File tree

4 files changed

+65
-14
lines changed

4 files changed

+65
-14
lines changed

Zend/zend_exceptions.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ ZEND_METHOD(exception, getPrevious)
560560
RETURN_ZVAL(previous, 1, 0);
561561
}
562562

563-
int zend_spprintf(char **message, int max_len, char *format, ...) /* {{{ */
563+
int zend_spprintf(char **message, int max_len, const char *format, ...) /* {{{ */
564564
{
565565
va_list arg;
566566
int len;
@@ -732,7 +732,7 @@ ZEND_API zend_class_entry *zend_get_error_exception(TSRMLS_D) /* {{{ */
732732
}
733733
/* }}} */
734734

735-
ZEND_API zval * zend_throw_exception(zend_class_entry *exception_ce, char *message, long code TSRMLS_DC) /* {{{ */
735+
ZEND_API zval * zend_throw_exception(zend_class_entry *exception_ce, const char *message, long code TSRMLS_DC) /* {{{ */
736736
{
737737
zval *ex;
738738

@@ -760,7 +760,7 @@ ZEND_API zval * zend_throw_exception(zend_class_entry *exception_ce, char *messa
760760
}
761761
/* }}} */
762762

763-
ZEND_API zval * zend_throw_exception_ex(zend_class_entry *exception_ce, long code TSRMLS_DC, char *format, ...) /* {{{ */
763+
ZEND_API zval * zend_throw_exception_ex(zend_class_entry *exception_ce, long code TSRMLS_DC, const char *format, ...) /* {{{ */
764764
{
765765
va_list arg;
766766
char *message;
@@ -775,7 +775,7 @@ ZEND_API zval * zend_throw_exception_ex(zend_class_entry *exception_ce, long cod
775775
}
776776
/* }}} */
777777

778-
ZEND_API zval * zend_throw_error_exception(zend_class_entry *exception_ce, char *message, long code, int severity TSRMLS_DC) /* {{{ */
778+
ZEND_API zval * zend_throw_error_exception(zend_class_entry *exception_ce, const char *message, long code, int severity TSRMLS_DC) /* {{{ */
779779
{
780780
zval *ex = zend_throw_exception(exception_ce, message, code TSRMLS_CC);
781781
zend_update_property_long(default_exception_ce, ex, "severity", sizeof("severity")-1, severity TSRMLS_CC);

Zend/zend_exceptions.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,20 @@ ZEND_API void zend_register_default_classes(TSRMLS_D);
4040

4141
/* exception_ce NULL or zend_exception_get_default() or a derived class
4242
* message NULL or the message of the exception */
43-
ZEND_API zval * zend_throw_exception(zend_class_entry *exception_ce, char *message, long code TSRMLS_DC);
44-
ZEND_API zval * zend_throw_exception_ex(zend_class_entry *exception_ce, long code TSRMLS_DC, char *format, ...);
43+
ZEND_API zval * zend_throw_exception(zend_class_entry *exception_ce, const char *message, long code TSRMLS_DC);
44+
ZEND_API zval * zend_throw_exception_ex(zend_class_entry *exception_ce, long code TSRMLS_DC, const char *format, ...);
4545
ZEND_API void zend_throw_exception_object(zval *exception TSRMLS_DC);
4646
ZEND_API void zend_clear_exception(TSRMLS_D);
4747

48-
ZEND_API zval * zend_throw_error_exception(zend_class_entry *exception_ce, char *message, long code, int severity TSRMLS_DC);
48+
ZEND_API zval * zend_throw_error_exception(zend_class_entry *exception_ce, const char *message, long code, int severity TSRMLS_DC);
4949

5050
extern ZEND_API void (*zend_throw_exception_hook)(zval *ex TSRMLS_DC);
5151

5252
/* show an exception using zend_error(severity,...), severity should be E_ERROR */
5353
ZEND_API void zend_exception_error(zval *exception, int severity TSRMLS_DC);
5454

5555
/* do not export, in php it's available thru spprintf directly */
56-
int zend_spprintf(char **message, int max_len, char *format, ...);
56+
int zend_spprintf(char **message, int max_len, const char *format, ...);
5757

5858
END_EXTERN_C()
5959

ext/dba/dba.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,17 @@ static size_t php_dba_make_key(zval *key, char **key_str, char **key_free TSRMLS
226226
*key_free = *key_str;
227227
return len;
228228
} else {
229-
*key_free = NULL;
229+
zval tmp = *key;
230+
int len;
230231

231-
convert_to_string(key);
232-
*key_str = Z_STRVAL_P(key);
232+
zval_copy_ctor(&tmp);
233+
convert_to_string(&tmp);
233234

234-
return Z_STRLEN_P(key);
235+
*key_free = *key_str = estrndup(Z_STRVAL(tmp), Z_STRLEN(tmp));
236+
len = Z_STRLEN(tmp);
237+
238+
zval_dtor(&tmp);
239+
return len;
235240
}
236241
}
237242
/* }}} */
@@ -297,6 +302,14 @@ static size_t php_dba_make_key(zval *key, char **key_str, char **key_free TSRMLS
297302
RETURN_FALSE; \
298303
}
299304

305+
/* the same check, but with a call to DBA_ID_DONE before returning */
306+
#define DBA_WRITE_CHECK_WITH_ID \
307+
if(info->mode != DBA_WRITER && info->mode != DBA_TRUNC && info->mode != DBA_CREAT) { \
308+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "You cannot perform a modification to a database without proper access"); \
309+
DBA_ID_DONE; \
310+
RETURN_FALSE; \
311+
}
312+
300313
/* }}} */
301314

302315
/* {{{ globals */
@@ -557,7 +570,7 @@ static void php_dba_update(INTERNAL_FUNCTION_PARAMETERS, int mode)
557570

558571
DBA_FETCH_RESOURCE(info, &id);
559572

560-
DBA_WRITE_CHECK;
573+
DBA_WRITE_CHECK_WITH_ID;
561574

562575
if (info->hnd->update(info, key_str, key_len, val, val_len, mode TSRMLS_CC) == SUCCESS) {
563576
DBA_ID_DONE;
@@ -1110,7 +1123,7 @@ PHP_FUNCTION(dba_delete)
11101123
{
11111124
DBA_ID_GET2;
11121125

1113-
DBA_WRITE_CHECK;
1126+
DBA_WRITE_CHECK_WITH_ID;
11141127

11151128
if(info->hnd->delete(info, key_str, key_len TSRMLS_CC) == SUCCESS)
11161129
{

ext/dba/tests/bug65708.phpt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
Bug #65708 (dba functions cast $key param to string in-place, bypassing copy on write)
3+
--SKIPIF--
4+
<?php
5+
require_once(dirname(__FILE__) .'/skipif.inc');
6+
?>
7+
--FILE--
8+
<?php
9+
10+
error_reporting(E_ALL);
11+
12+
require_once(dirname(__FILE__) .'/test.inc');
13+
14+
$db = dba_popen($db_filename, 'c');
15+
16+
$key = 1;
17+
$copy = $key;
18+
19+
echo gettype($key)."\n";
20+
echo gettype($copy)."\n";
21+
22+
dba_exists($key, $db);
23+
24+
echo gettype($key)."\n";
25+
echo gettype($copy)."\n";
26+
27+
dba_close($db);
28+
29+
?>
30+
--CLEAN--
31+
<?php
32+
require(dirname(__FILE__) .'/clean.inc');
33+
?>
34+
--EXPECT--
35+
integer
36+
integer
37+
integer
38+
integer

0 commit comments

Comments
 (0)