1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-06 19:59:18 +03:00

Remove infinite-loop hazards in ecpg test suite.

A report from Andrew Dunstan showed that an ecpglib breakage that
causes repeated query failures could lead to infinite loops in some
ecpg test scripts, because they contain "while(1)" loops with no
exit condition other than successful test completion.  That might
be all right for manual testing, but it seems entirely unacceptable
for automated test environments such as our buildfarm.  We don't
want buildfarm owners to have to intervene manually when a test
goes wrong.

To fix, just change all those while(1) loops to exit after at most
100 iterations (which is more than any of them expect to iterate).
This seems sufficient since we'd see discrepancies in the test output
if any loop executed the wrong number of times.

I tested this by dint of intentionally breaking ecpg_do_prologue
to always fail, and verifying that the tests still got to completion.

Back-patch to all supported branches, since the whole point of this
exercise is to protect the buildfarm against future mistakes.

Discussion: https://postgr.es/m/18693.1548302004@sss.pgh.pa.us
This commit is contained in:
Tom Lane 2019-01-24 16:46:55 -05:00
parent bbd5c207b9
commit d5a1fde397
18 changed files with 46 additions and 43 deletions

View File

@ -11,7 +11,7 @@ static void dosqlprint(void) {
int main(void) int main(void)
{ {
$int i = 14; $int i = 14, loopcount;
$decimal j, m, n; $decimal j, m, n;
$string c[10]; $string c[10];
@ -52,7 +52,7 @@ int main(void)
deccvint(0, &j); deccvint(0, &j);
while (1) for (loopcount = 0; loopcount < 100; loopcount++)
{ {
$fetch forward c into :i, :j, :c; $fetch forward c into :i, :j, :c;
if (sqlca.sqlcode == 100) break; if (sqlca.sqlcode == 100) break;

View File

@ -19,7 +19,7 @@ int main() {
EXEC SQL WHENEVER SQLERROR SQLPRINT; EXEC SQL WHENEVER SQLERROR SQLPRINT;
const char *ppppp = "XXXXX"; const char *ppppp = "XXXXX";
int loopcount;
EXEC SQL BEGIN DECLARE SECTION; EXEC SQL BEGIN DECLARE SECTION;
char shortstr[5]; char shortstr[5];
char bigstr[11]; char bigstr[11];
@ -44,7 +44,7 @@ int main() {
EXEC SQL WHENEVER NOT FOUND DO BREAK; EXEC SQL WHENEVER NOT FOUND DO BREAK;
printf("Full Str. : Short Ind.\n"); printf("Full Str. : Short Ind.\n");
while(1) { for (loopcount = 0; loopcount < 100; loopcount++) {
strncpy(shortstr, ppppp, sizeof shortstr); strncpy(shortstr, ppppp, sizeof shortstr);
memset(bigstr, 0, sizeof bigstr); memset(bigstr, 0, sizeof bigstr);
EXEC SQL FETCH C into :bigstr :bigstr_ind, :shortstr :shstr_ind; EXEC SQL FETCH C into :bigstr :bigstr_ind, :shortstr :shstr_ind;

View File

@ -33,7 +33,7 @@ int main(void)
{ {
#line 14 "test_informix.pgc" #line 14 "test_informix.pgc"
int i = 14 ; int i = 14 , loopcount ;
#line 14 "test_informix.pgc" #line 14 "test_informix.pgc"
@ -156,7 +156,7 @@ if (sqlca.sqlcode < 0) dosqlprint ( );}
deccvint(0, &j); deccvint(0, &j);
while (1) for (loopcount = 0; loopcount < 100; loopcount++)
{ {
{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "fetch forward c", ECPGt_EOIT, { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "fetch forward c", ECPGt_EOIT,
ECPGt_int,&(i),(long)1,(long)1,sizeof(int), ECPGt_int,&(i),(long)1,(long)1,sizeof(int),

View File

@ -41,7 +41,7 @@ int main() {
const char *ppppp = "XXXXX"; const char *ppppp = "XXXXX";
int loopcount;
/* exec sql begin declare section */ /* exec sql begin declare section */
@ -156,7 +156,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
printf("Full Str. : Short Ind.\n"); printf("Full Str. : Short Ind.\n");
while(1) { for (loopcount = 0; loopcount < 100; loopcount++) {
strncpy(shortstr, ppppp, sizeof shortstr); strncpy(shortstr, ppppp, sizeof shortstr);
memset(bigstr, 0, sizeof bigstr); memset(bigstr, 0, sizeof bigstr);
{ ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "fetch C", ECPGt_EOIT, { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "fetch C", ECPGt_EOIT,

View File

@ -36,13 +36,13 @@ int
main(void) main(void)
{ {
/* exec sql begin declare section */ /* exec sql begin declare section */
#line 21 "nan_test.pgc" #line 21 "nan_test.pgc"
int id ; int id , loopcount ;
#line 22 "nan_test.pgc" #line 22 "nan_test.pgc"
double d ; double d ;
@ -90,7 +90,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
if (sqlca.sqlcode < 0) sqlprint ( );} if (sqlca.sqlcode < 0) sqlprint ( );}
#line 36 "nan_test.pgc" #line 36 "nan_test.pgc"
while (1) for (loopcount = 0; loopcount < 100; loopcount++)
{ {
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur", ECPGt_EOIT, { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur", ECPGt_EOIT,
ECPGt_int,&(id),(long)1,(long)1,sizeof(int), ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
@ -145,7 +145,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
if (sqlca.sqlcode < 0) sqlprint ( );} if (sqlca.sqlcode < 0) sqlprint ( );}
#line 52 "nan_test.pgc" #line 52 "nan_test.pgc"
while (1) for (loopcount = 0; loopcount < 100; loopcount++)
{ {
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur", ECPGt_EOIT, { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur", ECPGt_EOIT,
ECPGt_int,&(id),(long)1,(long)1,sizeof(int), ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
@ -229,7 +229,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
if (sqlca.sqlcode < 0) sqlprint ( );} if (sqlca.sqlcode < 0) sqlprint ( );}
#line 78 "nan_test.pgc" #line 78 "nan_test.pgc"
while (1) for (loopcount = 0; loopcount < 100; loopcount++)
{ {
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur1", ECPGt_EOIT, { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur1", ECPGt_EOIT,
ECPGt_int,&(id),(long)1,(long)1,sizeof(int), ECPGt_int,&(id),(long)1,(long)1,sizeof(int),

View File

@ -197,7 +197,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
i = 0; i = 0;
while (1) while (i < 100)
{ {
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch cur1", ECPGt_EOIT, { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch cur1", ECPGt_EOIT,
ECPGt_int,&(item1),(long)1,(long)1,sizeof(int), ECPGt_int,&(item1),(long)1,(long)1,sizeof(int),

View File

@ -267,7 +267,7 @@ main (void)
{ {
MYTYPE *myvar; MYTYPE *myvar;
MYNULLTYPE *mynullvar; MYNULLTYPE *mynullvar;
int loopcount;
char msg[128]; char msg[128];
ECPGdebug(1, stderr); ECPGdebug(1, stderr);
@ -333,7 +333,7 @@ if (sqlca.sqlcode < 0) exit (1);}
#line 96 "outofscope.pgc" #line 96 "outofscope.pgc"
while (1) for (loopcount = 0; loopcount < 100; loopcount++)
{ {
memset(myvar, 0, sizeof(MYTYPE)); memset(myvar, 0, sizeof(MYTYPE));
get_record1(); get_record1();

View File

@ -120,7 +120,7 @@ main (void)
#line 37 "variable.pgc" #line 37 "variable.pgc"
int loopcount;
char msg[128]; char msg[128];
ECPGdebug(1, stderr); ECPGdebug(1, stderr);
@ -204,7 +204,7 @@ if (sqlca.sqlcode < 0) exit (1);}
p=&personal; p=&personal;
i=&ind_personal; i=&ind_personal;
memset(i, 0, sizeof(ind_personal)); memset(i, 0, sizeof(ind_personal));
while (1) { for (loopcount = 0; loopcount < 100; loopcount++) {
strcpy(msg, "fetch"); strcpy(msg, "fetch");
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch cur", ECPGt_EOIT, { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch cur", ECPGt_EOIT,
ECPGt_varchar,&(p->name),(long)BUFFERSIZ,(long)-1,sizeof( struct birthinfo ), ECPGt_varchar,&(p->name),(long)BUFFERSIZ,(long)-1,sizeof( struct birthinfo ),

View File

@ -33,7 +33,7 @@ int main(void)
#line 15 "whenever_do_continue.pgc" #line 15 "whenever_do_continue.pgc"
@ -48,6 +48,9 @@ int main(void)
float comm ; float comm ;
} emp ; } emp ;
#line 16 "whenever_do_continue.pgc"
int loopcount ;
#line 17 "whenever_do_continue.pgc" #line 17 "whenever_do_continue.pgc"
char msg [ 128 ] ; char msg [ 128 ] ;
/* exec sql end declare section */ /* exec sql end declare section */
@ -119,7 +122,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
#line 42 "whenever_do_continue.pgc" #line 42 "whenever_do_continue.pgc"
while (1) for (loopcount = 0; loopcount < 100; loopcount++)
{ {
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch c", ECPGt_EOIT, { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch c", ECPGt_EOIT,
ECPGt_char,&(emp.ename),(long)12,(long)1,(12)*sizeof(char), ECPGt_char,&(emp.ename),(long)12,(long)1,(12)*sizeof(char),

View File

@ -25,13 +25,13 @@
int main() { int main() {
/* exec sql begin declare section */ /* exec sql begin declare section */
#line 9 "fetch.pgc" #line 9 "fetch.pgc"
char str [ 25 ] ; char str [ 25 ] ;
#line 10 "fetch.pgc" #line 10 "fetch.pgc"
int i , count = 1 ; int i , count = 1 , loopcount ;
/* exec sql end declare section */ /* exec sql end declare section */
#line 11 "fetch.pgc" #line 11 "fetch.pgc"
@ -112,7 +112,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
/* exec sql whenever not found break ; */ /* exec sql whenever not found break ; */
#line 30 "fetch.pgc" #line 30 "fetch.pgc"
while (1) { for (loopcount = 0; loopcount < 100; loopcount++) {
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 in C", ECPGt_EOIT, { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 in C", ECPGt_EOIT,
ECPGt_int,&(i),(long)1,(long)1,sizeof(int), ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
@ -191,7 +191,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
/* exec sql whenever not found break ; */ /* exec sql whenever not found break ; */
#line 48 "fetch.pgc" #line 48 "fetch.pgc"
while (1) { for (loopcount = 0; loopcount < 100; loopcount++) {
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 in D", ECPGt_EOIT, { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 in D", ECPGt_EOIT,
ECPGt_int,&(i),(long)1,(long)1,sizeof(int), ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,

View File

@ -25,13 +25,13 @@
int main() { int main() {
/* exec sql begin declare section */ /* exec sql begin declare section */
#line 9 "quote.pgc" #line 9 "quote.pgc"
char var [ 25 ] ; char var [ 25 ] ;
#line 10 "quote.pgc" #line 10 "quote.pgc"
int i ; int i , loopcount ;
/* exec sql end declare section */ /* exec sql end declare section */
#line 11 "quote.pgc" #line 11 "quote.pgc"
@ -176,7 +176,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
#line 47 "quote.pgc" #line 47 "quote.pgc"
while (true) for (loopcount = 0; loopcount < 100; loopcount++)
{ {
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch C", ECPGt_EOIT, { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch C", ECPGt_EOIT,
ECPGt_int,&(i),(long)1,(long)1,sizeof(int), ECPGt_int,&(i),(long)1,(long)1,sizeof(int),

View File

@ -18,7 +18,7 @@ int
main(void) main(void)
{ {
exec sql begin declare section; exec sql begin declare section;
int id; int id, loopcount;
double d; double d;
numeric *num; numeric *num;
char val[16]; char val[16];
@ -34,7 +34,7 @@ main(void)
exec sql declare cur cursor for select id, d, d from nantest1; exec sql declare cur cursor for select id, d, d from nantest1;
exec sql open cur; exec sql open cur;
while (1) for (loopcount = 0; loopcount < 100; loopcount++)
{ {
exec sql fetch from cur into :id, :d, :val; exec sql fetch from cur into :id, :d, :val;
if (sqlca.sqlcode) if (sqlca.sqlcode)
@ -50,7 +50,7 @@ main(void)
exec sql close cur; exec sql close cur;
exec sql open cur; exec sql open cur;
while (1) for (loopcount = 0; loopcount < 100; loopcount++)
{ {
exec sql fetch from cur into :id, :d, :val; exec sql fetch from cur into :id, :d, :val;
if (sqlca.sqlcode) if (sqlca.sqlcode)
@ -76,7 +76,7 @@ main(void)
exec sql declare cur1 cursor for select id, d, d from nantest2; exec sql declare cur1 cursor for select id, d, d from nantest2;
exec sql open cur1; exec sql open cur1;
while (1) for (loopcount = 0; loopcount < 100; loopcount++)
{ {
exec sql fetch from cur1 into :id, :num, :val; exec sql fetch from cur1 into :id, :num, :val;
if (sqlca.sqlcode) if (sqlca.sqlcode)

View File

@ -50,7 +50,7 @@ static void test(void) {
EXEC SQL WHENEVER NOT FOUND DO BREAK; EXEC SQL WHENEVER NOT FOUND DO BREAK;
i = 0; i = 0;
while (1) while (i < 100)
{ {
EXEC SQL FETCH cur1 INTO :item1:ind1; EXEC SQL FETCH cur1 INTO :item1:ind1;
printf("item[%d] = %d\n", i, ind1 ? -1 : item1); printf("item[%d] = %d\n", i, ind1 ? -1 : item1);

View File

@ -66,7 +66,7 @@ main (void)
{ {
MYTYPE *myvar; MYTYPE *myvar;
MYNULLTYPE *mynullvar; MYNULLTYPE *mynullvar;
int loopcount;
char msg[128]; char msg[128];
ECPGdebug(1, stderr); ECPGdebug(1, stderr);
@ -95,7 +95,7 @@ main (void)
exec sql whenever not found do break; exec sql whenever not found do break;
while (1) for (loopcount = 0; loopcount < 100; loopcount++)
{ {
memset(myvar, 0, sizeof(MYTYPE)); memset(myvar, 0, sizeof(MYTYPE));
get_record1(); get_record1();

View File

@ -35,7 +35,7 @@ exec sql end declare section;
exec sql char *married = NULL; exec sql char *married = NULL;
exec sql long ind_married; exec sql long ind_married;
exec sql ind children; exec sql ind children;
int loopcount;
char msg[128]; char msg[128];
ECPGdebug(1, stderr); ECPGdebug(1, stderr);
@ -67,7 +67,7 @@ exec sql end declare section;
p=&personal; p=&personal;
i=&ind_personal; i=&ind_personal;
memset(i, 0, sizeof(ind_personal)); memset(i, 0, sizeof(ind_personal));
while (1) { for (loopcount = 0; loopcount < 100; loopcount++) {
strcpy(msg, "fetch"); strcpy(msg, "fetch");
exec sql fetch cur into :p:i, :married:ind_married, :children.integer:ind_children.smallint; exec sql fetch cur into :p:i, :married:ind_married, :children.integer:ind_children.smallint;
printf("%8.8s", personal.name.arr); printf("%8.8s", personal.name.arr);

View File

@ -13,7 +13,7 @@ int main(void)
float sal; float sal;
float comm; float comm;
} emp; } emp;
int loopcount;
char msg[128]; char msg[128];
exec sql end declare section; exec sql end declare section;
@ -41,7 +41,7 @@ int main(void)
/* The DO CONTINUE makes the loop start at the next iteration when an error occurs.*/ /* The DO CONTINUE makes the loop start at the next iteration when an error occurs.*/
exec sql whenever sqlerror do continue; exec sql whenever sqlerror do continue;
while (1) for (loopcount = 0; loopcount < 100; loopcount++)
{ {
exec sql fetch c into :emp; exec sql fetch c into :emp;
/* The employees with non-NULL commissions will be displayed. */ /* The employees with non-NULL commissions will be displayed. */

View File

@ -7,7 +7,7 @@ EXEC SQL INCLUDE ../regression;
int main() { int main() {
EXEC SQL BEGIN DECLARE SECTION; EXEC SQL BEGIN DECLARE SECTION;
char str[25]; char str[25];
int i, count=1; int i, count=1, loopcount;
EXEC SQL END DECLARE SECTION; EXEC SQL END DECLARE SECTION;
ECPGdebug(1, stderr); ECPGdebug(1, stderr);
@ -28,7 +28,7 @@ int main() {
EXEC SQL OPEN C; EXEC SQL OPEN C;
EXEC SQL WHENEVER NOT FOUND DO BREAK; EXEC SQL WHENEVER NOT FOUND DO BREAK;
while (1) { for (loopcount = 0; loopcount < 100; loopcount++) {
EXEC SQL FETCH 1 IN C INTO :i, :str; EXEC SQL FETCH 1 IN C INTO :i, :str;
printf("%d: %s\n", i, str); printf("%d: %s\n", i, str);
} }
@ -46,7 +46,7 @@ int main() {
EXEC SQL OPEN D using 1; EXEC SQL OPEN D using 1;
EXEC SQL WHENEVER NOT FOUND DO BREAK; EXEC SQL WHENEVER NOT FOUND DO BREAK;
while (1) { for (loopcount = 0; loopcount < 100; loopcount++) {
EXEC SQL FETCH 1 IN D INTO :i, :str; EXEC SQL FETCH 1 IN D INTO :i, :str;
printf("%d: %s\n", i, str); printf("%d: %s\n", i, str);
} }

View File

@ -7,7 +7,7 @@ EXEC SQL INCLUDE ../regression;
int main() { int main() {
EXEC SQL BEGIN DECLARE SECTION; EXEC SQL BEGIN DECLARE SECTION;
char var[25]; char var[25];
int i; int i, loopcount;
EXEC SQL END DECLARE SECTION; EXEC SQL END DECLARE SECTION;
ECPGdebug(1, stderr); ECPGdebug(1, stderr);
@ -46,7 +46,7 @@ int main() {
EXEC SQL WHENEVER NOT FOUND DO BREAK; EXEC SQL WHENEVER NOT FOUND DO BREAK;
while (true) for (loopcount = 0; loopcount < 100; loopcount++)
{ {
EXEC SQL FETCH C INTO :i, :var; EXEC SQL FETCH C INTO :i, :var;
printf("value: %d %s\n", i, var); printf("value: %d %s\n", i, var);