summaryrefslogtreecommitdiffstats
path: root/0005-fix-segfault-in-013.solrclient_getByIds.sh.patch
blob: 109b604d0e90c18a2e40c8e16c184cfbfb3fb77c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
From 9c0e23403876814f2812b4bad04989873194c91f Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@php.net>
Date: Fri, 12 Oct 2018 14:10:54 +0200
Subject: [PATCH 5/5] fix segfault in 013.solrclient_getByIds.sh

---
 src/php7/php_solr_client.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/src/php7/php_solr_client.c b/src/php7/php_solr_client.c
index 3c76f52..8bad5df 100644
--- a/src/php7/php_solr_client.c
+++ b/src/php7/php_solr_client.c
@@ -1346,22 +1346,24 @@ PHP_METHOD(SolrClient, getByIds)
 
     solr_string_init(&query_string);
     solr_string_appends(&query_string, "ids=", sizeof("ids=")-1);
-    SOLR_HASHTABLE_FOR_LOOP(ids)
-    {
-        zval *id_zv = NULL;
-        id_zv = zend_hash_get_current_data(ids);
-        if (Z_TYPE_P(id_zv) == IS_STRING && Z_STRLEN_P(id_zv)) {
-            solr_string_appends(&query_string, Z_STRVAL_P(id_zv), Z_STRLEN_P(id_zv));
-            solr_string_appendc(&query_string, ',');
-        } else {
-            invalid_param = 1;
-            goto solr_getbyids_exit;
+
+    if (ids->nNumOfElements) {
+        SOLR_HASHTABLE_FOR_LOOP(ids)
+        {
+            zval *id_zv = NULL;
+            id_zv = zend_hash_get_current_data(ids);
+            if (Z_TYPE_P(id_zv) == IS_STRING && Z_STRLEN_P(id_zv)) {
+                solr_string_appends(&query_string, Z_STRVAL_P(id_zv), Z_STRLEN_P(id_zv));
+                solr_string_appendc(&query_string, ',');
+            } else {
+                invalid_param = 1;
+                goto solr_getbyids_exit;
+            }
+            current_position++;
         }
-        current_position++;
     }
 
 
-
 solr_getbyids_exit:
     if (invalid_param) {
         solr_string_free(&query_string);
-- 
2.14.4