Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5ee5bc3

Browse files
author
Michael Meskes
committed
This routine was calling ecpg_alloc to allocate to memory but did not
actually check the returned pointer allocated, potentially NULL whichcould be the result of a malloc call.Issue noted by Coverity, fixed by Michael Paquier <michael@otacoo.com>
1 parentd88976c commit5ee5bc3

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

‎src/interfaces/ecpg/ecpglib/descriptor.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,15 +432,14 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
432432
/* allocate storage if needed */
433433
if (arrsize==0&&*(void**)var==NULL)
434434
{
435-
void*mem= (void*)ecpg_alloc(offset*ntuples,lineno);
435+
void*mem= (void*)ecpg_auto_alloc(offset*ntuples,lineno);
436436

437437
if (!mem)
438438
{
439439
va_end(args);
440440
return false;
441441
}
442442
*(void**)var=mem;
443-
ecpg_add_mem(mem,lineno);
444443
var=mem;
445444
}
446445

@@ -510,15 +509,14 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
510509
/* allocate storage if needed */
511510
if (data_var.ind_arrsize==0&&data_var.ind_value==NULL)
512511
{
513-
void*mem= (void*)ecpg_alloc(data_var.ind_offset*ntuples,lineno);
512+
void*mem= (void*)ecpg_auto_alloc(data_var.ind_offset*ntuples,lineno);
514513

515514
if (!mem)
516515
{
517516
va_end(args);
518517
return false;
519518
}
520519
*(void**)data_var.ind_pointer=mem;
521-
ecpg_add_mem(mem,lineno);
522520
data_var.ind_value=mem;
523521
}
524522

‎src/interfaces/ecpg/ecpglib/execute.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,23 +398,21 @@ ecpg_store_result(const PGresult *results, int act_field,
398398
}
399399

400400
ecpg_log("ecpg_store_result on line %d: allocating memory for %d tuples\n",stmt->lineno,ntuples);
401-
var->value= (char*)ecpg_alloc(len,stmt->lineno);
401+
var->value= (char*)ecpg_auto_alloc(len,stmt->lineno);
402402
if (!var->value)
403403
return false;
404404
*((char**)var->pointer)=var->value;
405-
ecpg_add_mem(var->value,stmt->lineno);
406405
}
407406

408407
/* allocate indicator variable if needed */
409408
if ((var->ind_arrsize==0||var->ind_varcharsize==0)&&var->ind_value==NULL&&var->ind_pointer!=NULL)
410409
{
411410
intlen=var->ind_offset*ntuples;
412411

413-
var->ind_value= (char*)ecpg_alloc(len,stmt->lineno);
412+
var->ind_value= (char*)ecpg_auto_alloc(len,stmt->lineno);
414413
if (!var->ind_value)
415414
return false;
416415
*((char**)var->ind_pointer)=var->ind_value;
417-
ecpg_add_mem(var->ind_value,stmt->lineno);
418416
}
419417

420418
/* fill the variable with the tuple(s) */

‎src/interfaces/ecpg/ecpglib/extern.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ extern struct var_list *ivlist;
136136

137137
/* Here are some methods used by the lib. */
138138

139-
/* Returns a pointer to a string containing a simple type name. */
140-
voidecpg_add_mem(void*ptr,intlineno);
139+
boolecpg_add_mem(void*ptr,intlineno);
141140

142141
boolecpg_get_data(constPGresult*,int,int,int,enumECPGttypetype,
143142
enumECPGttype,char*,char*,long,long,long,
@@ -148,6 +147,7 @@ voidecpg_pthreads_init(void);
148147
#endif
149148
structconnection*ecpg_get_connection(constchar*);
150149
char*ecpg_alloc(long,int);
150+
char*ecpg_auto_alloc(long,int);
151151
char*ecpg_realloc(void*,long,int);
152152
voidecpg_free(void*);
153153
boolecpg_init(conststructconnection*,constchar*,constint);

‎src/interfaces/ecpg/ecpglib/memory.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,34 @@ static struct auto_mem *auto_allocs = NULL;
104104
#defineset_auto_allocs(am)do { auto_allocs = (am); } while(0)
105105
#endif
106106

107-
void
107+
char*
108+
ecpg_auto_alloc(longsize,intlineno)
109+
{
110+
void*ptr= (void*)ecpg_alloc(size,lineno);
111+
112+
if (!ptr)
113+
returnNULL;
114+
115+
if (!ecpg_add_mem(ptr,lineno))
116+
{
117+
ecpg_free(ptr);
118+
returnNULL;
119+
}
120+
returnptr;
121+
}
122+
123+
bool
108124
ecpg_add_mem(void*ptr,intlineno)
109125
{
110126
structauto_mem*am= (structauto_mem*)ecpg_alloc(sizeof(structauto_mem),lineno);
111127

128+
if (!am)
129+
return false;
130+
112131
am->pointer=ptr;
113132
am->next=get_auto_allocs();
114133
set_auto_allocs(am);
134+
return true;
115135
}
116136

117137
void

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp