db_text: safety check for lres
authorDaniel-Constantin Mierla <miconda@gmail.com>
Tue, 13 Apr 2021 07:15:10 +0000 (09:15 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Thu, 15 Apr 2021 06:34:26 +0000 (08:34 +0200)
(cherry picked from commit 8a5b764e77d009eb6f236e74d3462bfce0d57f07)

src/modules/db_text/dbt_base.c
src/modules/db_text/dbt_res.c

index 1e5dd01..0b4437b 100644 (file)
@@ -258,7 +258,7 @@ int dbt_query(db1_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v,
 
                dbt_column_p pPrevCol = NULL;
                _tbc_temp->colv = (dbt_column_p*) shm_malloc(_nc*sizeof(dbt_column_p));
-               for(i=0; i < _nc; i++) {
+               for(i=0; lres && i < _nc; i++) {
                        dbt_column_p pCol = dbt_column_new(_tbc->colv[ lres[i] ]->name.s, _tbc->colv[ lres[i] ]->name.len);
                        pCol->type = _tbc->colv[ lres[i] ]->type;
                        pCol->flag = _tbc->colv[ lres[i] ]->flag;
index 16a11f2..87adc0b 100644 (file)
@@ -915,7 +915,7 @@ dbt_row_p dbt_result_extract_results(dbt_table_p _dtp, dbt_row_p* pRows, int _nr
        dbt_row_p pPrvRow=NULL;
        int i, n, r;
 
-       if(!_dtp || !pRows || _ncols<=0)
+       if(!_dtp || !pRows || _ncols<=0 || !_lres)
                return NULL;
 
        for(r=0; r < _nrows; r++) {