Skip to content

Commit d738d27

Browse files
committed
Merge branch 'v1.15'
* v1.15: PHPC-2185: Windows builds for PHP 7.4 (#1397) Fix null pointer access for write concern errors without a message (#1396)
2 parents 1650a91 + c543c58 commit d738d27

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
fail-fast: true
9191
matrix:
9292
os: [ windows-2019, windows-2022 ]
93-
php: [ "7.2", "7.3", "8.0", "8.1", "8.2" ]
93+
php: [ "7.2", "7.3", "7.4", "8.0", "8.1", "8.2" ]
9494
arch: [ x64, x86 ]
9595
ts: [ ts, nts ]
9696
exclude:

.github/workflows/windows-release-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
# Note: keep this in sync with the Windows matrix in tests.yml
13-
php: [ "7.2", "7.3", "8.0", "8.1", "8.2" ]
13+
php: [ "7.2", "7.3", "7.4", "8.0", "8.1", "8.2" ]
1414
arch: [ x64, x86 ]
1515
ts: [ ts, nts ]
1616
runs-on: ubuntu-latest

src/MongoDB/WriteConcernError.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ static PHP_METHOD(MongoDB_Driver_WriteConcernError, getMessage)
6565

6666
PHONGO_PARSE_PARAMETERS_NONE();
6767

68+
if (!intern->message) {
69+
RETURN_STRING("");
70+
}
71+
6872
RETURN_STRING(intern->message);
6973
}
7074

@@ -107,7 +111,7 @@ static HashTable* php_phongo_writeconcernerror_get_debug_info(phongo_compat_obje
107111
intern = Z_OBJ_WRITECONCERNERROR(PHONGO_COMPAT_GET_OBJ(object));
108112

109113
array_init_size(&retval, 3);
110-
ADD_ASSOC_STRING(&retval, "message", intern->message);
114+
ADD_ASSOC_STRING(&retval, "message", intern->message ? intern->message : "");
111115
ADD_ASSOC_LONG_EX(&retval, "code", intern->code);
112116
if (!Z_ISUNDEF(intern->info)) {
113117
Z_ADDREF(intern->info);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
--TEST--
2+
MongoDB\Driver\WriteResult::getWriteConcernError() works for errors without a message
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_mongos(); ?>
6+
<?php skip_if_no_failcommand_failpoint(); ?>
7+
<?php skip_if_not_clean(); ?>
8+
--FILE--
9+
<?php
10+
require_once __DIR__ . "/../utils/basic.inc";
11+
12+
$manager = create_test_manager(null, ['retryWrites' => false]);
13+
14+
// Configure a fail point triggering a write concern error without message
15+
configureFailPoint(
16+
$manager,
17+
'failCommand',
18+
['times' => 1],
19+
[
20+
'failCommands' => ['insert'],
21+
'writeConcernError' => ['code' => 91],
22+
]
23+
);
24+
25+
$bulk = new MongoDB\Driver\BulkWrite();
26+
$bulk->insert(['write' => 1]);
27+
$result = $manager->executeBulkWrite(NS, $bulk);
28+
29+
var_dump($result->getWriteConcernError());
30+
31+
configureFailPoint($manager, 'failCommand', 'off');
32+
33+
?>
34+
===DONE===
35+
<?php exit(0); ?>
36+
--EXPECTF--
37+
object(MongoDB\Driver\WriteConcernError)#%d (%d) {
38+
["message"]=>
39+
string(0) ""
40+
["code"]=>
41+
int(91)
42+
["info"]=>
43+
NULL
44+
}
45+
===DONE===

0 commit comments

Comments
 (0)