Skip to content

Commit 85b437a

Browse files
bjoriderickr
authored andcommitted
Fixed PHPC-502: bson_init_static(): precondition failed: data
1 parent 78c177c commit 85b437a

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

php_phongo.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ bool phongo_query_init(php_phongo_query_t *query, bson_t *filter, bson_t *option
319319

320320

321321
if (bson_iter_init_find(&iter, options, "modifiers")) {
322-
bson_t tmp;
323322
uint32_t len = 0;
324323
const uint8_t *data = NULL;
325324

@@ -329,9 +328,13 @@ bool phongo_query_init(php_phongo_query_t *query, bson_t *filter, bson_t *option
329328
}
330329

331330
bson_iter_document(&iter, &len, &data);
332-
bson_init_static(&tmp, data, len);
333-
bson_copy_to_excluding_noinit(&tmp, query->query, "nadastrada", NULL);
334-
bson_destroy (&tmp);
331+
if (len) {
332+
bson_t tmp;
333+
334+
bson_init_static(&tmp, data, len);
335+
bson_copy_to_excluding_noinit(&tmp, query->query, "nadastrada", NULL);
336+
bson_destroy (&tmp);
337+
}
335338
}
336339

337340
if (bson_iter_init_find(&iter, options, "projection")) {
@@ -344,11 +347,12 @@ bool phongo_query_init(php_phongo_query_t *query, bson_t *filter, bson_t *option
344347
}
345348

346349
bson_iter_document(&iter, &len, &data);
347-
query->selector = bson_new_from_data(data, len);
350+
if (len) {
351+
query->selector = bson_new_from_data(data, len);
352+
}
348353
}
349354

350355
if (bson_iter_init_find(&iter, options, "sort")) {
351-
bson_t tmp;
352356
uint32_t len = 0;
353357
const uint8_t *data = NULL;
354358

@@ -358,9 +362,13 @@ bool phongo_query_init(php_phongo_query_t *query, bson_t *filter, bson_t *option
358362
}
359363

360364
phongo_bson_iter_as_document(&iter, &len, &data);
361-
bson_init_static(&tmp, data, len);
362-
bson_append_document(query->query, "$orderby", -1, &tmp);
363-
bson_destroy(&tmp);
365+
if (len) {
366+
bson_t tmp;
367+
368+
bson_init_static(&tmp, data, len);
369+
bson_append_document(query->query, "$orderby", -1, &tmp);
370+
bson_destroy(&tmp);
371+
}
364372
}
365373
}
366374

0 commit comments

Comments
 (0)