Browse code

db_text: safety check for lres

(cherry picked from commit 8a5b764e77d009eb6f236e74d3462bfce0d57f07)

Daniel-Constantin Mierla authored on 13/04/2021 07:15:10
Showing 2 changed files
... ...
@@ -258,7 +258,7 @@ int dbt_query(db1_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v,
258 258
 
259 259
 		dbt_column_p pPrevCol = NULL;
260 260
 		_tbc_temp->colv = (dbt_column_p*) shm_malloc(_nc*sizeof(dbt_column_p));
261
-		for(i=0; i < _nc; i++) {
261
+		for(i=0; lres && i < _nc; i++) {
262 262
 			dbt_column_p pCol = dbt_column_new(_tbc->colv[ lres[i] ]->name.s, _tbc->colv[ lres[i] ]->name.len);
263 263
 			pCol->type = _tbc->colv[ lres[i] ]->type;
264 264
 			pCol->flag = _tbc->colv[ lres[i] ]->flag;
... ...
@@ -915,7 +915,7 @@ dbt_row_p dbt_result_extract_results(dbt_table_p _dtp, dbt_row_p* pRows, int _nr
915 915
 	dbt_row_p pPrvRow=NULL;
916 916
 	int i, n, r;
917 917
 
918
-	if(!_dtp || !pRows || _ncols<=0)
918
+	if(!_dtp || !pRows || _ncols<=0 || !_lres)
919 919
 		return NULL;
920 920
 
921 921
 	for(r=0; r < _nrows; r++) {