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

Commit94a4842

Browse files
author
Michael Meskes
committed
Check for out of memory when allocating sqlca.
Patch by Michael Paquier
1 parentaf0b49f commit94a4842

File tree

7 files changed

+104
-1
lines changed

7 files changed

+104
-1
lines changed

‎src/interfaces/ecpg/compatlib/informix.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,8 @@ void
10321032
ECPG_informix_reset_sqlca(void)
10331033
{
10341034
structsqlca_t*sqlca=ECPGget_sqlca();
1035+
if (sqlca==NULL)
1036+
return;
10351037

10361038
memcpy((char*)sqlca, (char*)&sqlca_init,sizeof(structsqlca_t));
10371039
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@ ECPGnoticeReceiver(void *arg, const PGresult *result)
223223
structsqlca_t*sqlca=ECPGget_sqlca();
224224
intsqlcode;
225225

226+
if (sqlca==NULL)
227+
{
228+
ecpg_log("out of memory");
229+
return;
230+
}
231+
226232
(void)arg;/* keep the compiler quiet */
227233
if (sqlstate==NULL)
228234
sqlstate=ECPG_SQLSTATE_ECPG_INTERNAL_ERROR;
@@ -278,6 +284,14 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
278284
constchar**conn_keywords;
279285
constchar**conn_values;
280286

287+
if (sqlca==NULL)
288+
{
289+
ecpg_raise(lineno,ECPG_OUT_OF_MEMORY,
290+
ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY,NULL);
291+
ecpg_free(dbname);
292+
return false;
293+
}
294+
281295
ecpg_init_sqlca(sqlca);
282296

283297
/*
@@ -657,6 +671,13 @@ ECPGdisconnect(int lineno, const char *connection_name)
657671
structsqlca_t*sqlca=ECPGget_sqlca();
658672
structconnection*con;
659673

674+
if (sqlca==NULL)
675+
{
676+
ecpg_raise(lineno,ECPG_OUT_OF_MEMORY,
677+
ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY,NULL);
678+
return (false);
679+
}
680+
660681
#ifdefENABLE_THREAD_SAFETY
661682
pthread_mutex_lock(&connections_mutex);
662683
#endif

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
132132
intvalue_for_indicator=0;
133133
longlog_offset;
134134

135+
if (sqlca==NULL)
136+
{
137+
ecpg_raise(lineno,ECPG_OUT_OF_MEMORY,
138+
ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY,NULL);
139+
return (false);
140+
}
141+
135142
/*
136143
* If we are running in a regression test, do not log the offset variable,
137144
* it depends on the machine's alignment.

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ ECPGget_desc_header(int lineno, const char *desc_name, int *count)
9393
PGresult*ECPGresult;
9494
structsqlca_t*sqlca=ECPGget_sqlca();
9595

96+
if (sqlca==NULL)
97+
{
98+
ecpg_raise(lineno,ECPG_OUT_OF_MEMORY,
99+
ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY,NULL);
100+
return false;
101+
}
102+
96103
ecpg_init_sqlca(sqlca);
97104
ECPGresult=ecpg_result_by_descriptor(lineno,desc_name);
98105
if (!ECPGresult)
@@ -245,6 +252,13 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
245252
structvariabledata_var;
246253
structsqlca_t*sqlca=ECPGget_sqlca();
247254

255+
if (sqlca==NULL)
256+
{
257+
ecpg_raise(lineno,ECPG_OUT_OF_MEMORY,
258+
ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY,NULL);
259+
return false;
260+
}
261+
248262
va_start(args,index);
249263
ecpg_init_sqlca(sqlca);
250264
ECPGresult=ecpg_result_by_descriptor(lineno,desc_name);
@@ -701,6 +715,13 @@ ECPGdeallocate_desc(int line, const char *name)
701715
structdescriptor*prev;
702716
structsqlca_t*sqlca=ECPGget_sqlca();
703717

718+
if (sqlca==NULL)
719+
{
720+
ecpg_raise(line,ECPG_OUT_OF_MEMORY,
721+
ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY,NULL);
722+
return false;
723+
}
724+
704725
ecpg_init_sqlca(sqlca);
705726
for (desc=get_descriptors(),prev=NULL;desc;prev=desc,desc=desc->next)
706727
{
@@ -740,6 +761,13 @@ ECPGallocate_desc(int line, const char *name)
740761
structdescriptor*new;
741762
structsqlca_t*sqlca=ECPGget_sqlca();
742763

764+
if (sqlca==NULL)
765+
{
766+
ecpg_raise(line,ECPG_OUT_OF_MEMORY,
767+
ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY,NULL);
768+
return false;
769+
}
770+
743771
ecpg_init_sqlca(sqlca);
744772
new= (structdescriptor*)ecpg_alloc(sizeof(structdescriptor),line);
745773
if (!new)

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ ecpg_raise(int line, int code, const char *sqlstate, const char *str)
1414
{
1515
structsqlca_t*sqlca=ECPGget_sqlca();
1616

17+
if (sqlca==NULL)
18+
{
19+
ecpg_log("out of memory");
20+
ECPGfree_auto_mem();
21+
return;
22+
}
23+
1724
sqlca->sqlcode=code;
1825
strncpy(sqlca->sqlstate,sqlstate,sizeof(sqlca->sqlstate));
1926

@@ -215,6 +222,13 @@ ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat)
215222
char*sqlstate;
216223
char*message;
217224

225+
if (sqlca==NULL)
226+
{
227+
ecpg_log("out of memory");
228+
ECPGfree_auto_mem();
229+
return;
230+
}
231+
218232
if (result)
219233
{
220234
sqlstate=PQresultErrorField(result,PG_DIAG_SQLSTATE);
@@ -323,6 +337,12 @@ sqlprint(void)
323337
{
324338
structsqlca_t*sqlca=ECPGget_sqlca();
325339

340+
if (sqlca==NULL)
341+
{
342+
ecpg_log("out of memory");
343+
return;
344+
}
345+
326346
sqlca->sqlerrm.sqlerrmc[sqlca->sqlerrm.sqlerrml]='\0';
327347
fprintf(stderr,ecpg_gettext("SQL error: %s\n"),sqlca->sqlerrm.sqlerrmc);
328348
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,13 @@ ecpg_process_output(struct statement * stmt, bool clear_result)
14931493
ntuples,
14941494
act_field;
14951495

1496+
if (sqlca==NULL)
1497+
{
1498+
ecpg_raise(stmt->lineno,ECPG_OUT_OF_MEMORY,
1499+
ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY,NULL);
1500+
return (false);
1501+
}
1502+
14961503
var=stmt->outlist;
14971504
switch (PQresultStatus(stmt->results))
14981505
{

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ ecpg_init(const struct connection * con, const char *connection_name, const int
106106
{
107107
structsqlca_t*sqlca=ECPGget_sqlca();
108108

109+
if (sqlca==NULL)
110+
{
111+
ecpg_raise(lineno,ECPG_OUT_OF_MEMORY,ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY,
112+
NULL);
113+
return (false);
114+
}
115+
109116
ecpg_init_sqlca(sqlca);
110117
if (con==NULL)
111118
{
@@ -143,6 +150,8 @@ ECPGget_sqlca(void)
143150
if (sqlca==NULL)
144151
{
145152
sqlca=malloc(sizeof(structsqlca_t));
153+
if (sqlca==NULL)
154+
returnNULL;
146155
ecpg_init_sqlca(sqlca);
147156
pthread_setspecific(sqlca_key,sqlca);
148157
}
@@ -286,9 +295,11 @@ ecpg_log(const char *format,...)
286295
va_end(ap);
287296

288297
/* dump out internal sqlca variables */
289-
if (ecpg_internal_regression_mode)
298+
if (ecpg_internal_regression_mode&&sqlca!=NULL)
299+
{
290300
fprintf(debugstream,"[NO_PID]: sqlca: code: %ld, state: %s\n",
291301
sqlca->sqlcode,sqlca->sqlstate);
302+
}
292303

293304
fflush(debugstream);
294305

@@ -524,6 +535,13 @@ ECPGset_var(int number, void *pointer, int lineno)
524535
{
525536
structsqlca_t*sqlca=ECPGget_sqlca();
526537

538+
if (sqlca==NULL)
539+
{
540+
ecpg_raise(lineno,ECPG_OUT_OF_MEMORY,
541+
ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY,NULL);
542+
return;
543+
}
544+
527545
sqlca->sqlcode=ECPG_OUT_OF_MEMORY;
528546
strncpy(sqlca->sqlstate,"YE001",sizeof(sqlca->sqlstate));
529547
snprintf(sqlca->sqlerrm.sqlerrmc,sizeof(sqlca->sqlerrm.sqlerrmc),"out of memory on line %d",lineno);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp