Remove infinite-loop hazards in ecpg test suite.
authorTom Lane <[email protected]>
Thu, 24 Jan 2019 21:46:55 +0000 (16:46 -0500)
committerTom Lane <[email protected]>
Thu, 24 Jan 2019 21:47:06 +0000 (16:47 -0500)
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

18 files changed:
src/interfaces/ecpg/test/compat_informix/test_informix.pgc
src/interfaces/ecpg/test/compat_oracle/char_array.pgc
src/interfaces/ecpg/test/expected/compat_informix-test_informix.c
src/interfaces/ecpg/test/expected/compat_oracle-char_array.c
src/interfaces/ecpg/test/expected/pgtypeslib-nan_test.c
src/interfaces/ecpg/test/expected/preproc-autoprep.c
src/interfaces/ecpg/test/expected/preproc-outofscope.c
src/interfaces/ecpg/test/expected/preproc-variable.c
src/interfaces/ecpg/test/expected/preproc-whenever_do_continue.c
src/interfaces/ecpg/test/expected/sql-fetch.c
src/interfaces/ecpg/test/expected/sql-quote.c
src/interfaces/ecpg/test/pgtypeslib/nan_test.pgc
src/interfaces/ecpg/test/preproc/autoprep.pgc
src/interfaces/ecpg/test/preproc/outofscope.pgc
src/interfaces/ecpg/test/preproc/variable.pgc
src/interfaces/ecpg/test/preproc/whenever_do_continue.pgc
src/interfaces/ecpg/test/sql/fetch.pgc
src/interfaces/ecpg/test/sql/quote.pgc

index 8b7692b0fdd1066e2b6d823a82c67cb482305ac8..82a7d45b7688ff5fe07b9d5fe4c132023783b4af 100644 (file)
@@ -11,7 +11,7 @@ static void dosqlprint(void) {
 
 int main(void)
 {
-   $int i = 14;
+   $int i = 14, loopcount;
    $decimal j, m, n;
    $string c[10];
 
@@ -52,7 +52,7 @@ int main(void)
 
    deccvint(0, &j);
 
-   while (1)
+   for (loopcount = 0; loopcount < 100; loopcount++)
    {
        $fetch forward c into :i, :j, :c;
        if (sqlca.sqlcode == 100) break;
index 8d7d9bf2d19884e39f928e09c464e1e2cb73bffe..7ee312216ca902e2f27655ce9c5e590c5f6b3df7 100644 (file)
@@ -19,7 +19,7 @@ int main() {
   EXEC SQL WHENEVER SQLERROR SQLPRINT;
 
   const char *ppppp = "XXXXX";
-
+  int loopcount;
   EXEC SQL BEGIN DECLARE SECTION;
   char shortstr[5];
   char bigstr[11];
@@ -44,7 +44,7 @@ int main() {
   EXEC SQL WHENEVER NOT FOUND DO BREAK;
 
   printf("Full Str.  :  Short  Ind.\n");
-  while(1) {
+  for (loopcount = 0; loopcount < 100; loopcount++) {
     strncpy(shortstr, ppppp, sizeof shortstr);
     memset(bigstr, 0, sizeof bigstr);
     EXEC SQL FETCH C into :bigstr :bigstr_ind, :shortstr :shstr_ind;
index 99349475f873cc25c0459c217e77f36eaec84124..644153449815f2894724bfb8fd8a5192704fb526 100644 (file)
@@ -33,7 +33,7 @@ int main(void)
 {
    
 #line 14 "test_informix.pgc"
- int i = 14 ;
+ int i = 14 , loopcount ;
 
 #line 14 "test_informix.pgc"
 
@@ -156,7 +156,7 @@ if (sqlca.sqlcode < 0) dosqlprint ( );}
 
    deccvint(0, &j);
 
-   while (1)
+   for (loopcount = 0; loopcount < 100; loopcount++)
    {
        { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "fetch forward c", ECPGt_EOIT, 
    ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
index c9d2badb6a60f7a7d2c600d1b6812b9ee741ec80..ee8624f0ec50cfa80d4a4bf0b5e88e0d661820d0 100644 (file)
@@ -41,7 +41,7 @@ int main() {
 
 
   const char *ppppp = "XXXXX";
-
+  int loopcount;
   /* exec sql begin declare section */
    
    
@@ -156,7 +156,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
 
   printf("Full Str.  :  Short  Ind.\n");
-  while(1) {
+  for (loopcount = 0; loopcount < 100; loopcount++) {
     strncpy(shortstr, ppppp, sizeof shortstr);
     memset(bigstr, 0, sizeof bigstr);
     { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "fetch C", ECPGt_EOIT, 
index c83128405914dd59befd5bb08f7d0be772203786..b7e8054795069d5e130c7f2a1480278aec625715 100644 (file)
@@ -36,13 +36,13 @@ int
 main(void)
 {
    /* exec sql begin declare section */
-       
+        
        
        
        
    
 #line 21 "nan_test.pgc"
- int id ;
+ int id , loopcount ;
  
 #line 22 "nan_test.pgc"
  double d ;
@@ -90,7 +90,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #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, 
    ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
@@ -145,7 +145,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #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, 
    ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
@@ -229,7 +229,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #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, 
    ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
index 10ede3ec62771a2dc0775e73926b3be44e7e68c1..8ed5a2ca2c148954c030773a072076161c31e9d8 100644 (file)
@@ -197,7 +197,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
 
   i = 0;
-  while (1)
+  while (i < 100)
   {
    { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch cur1", ECPGt_EOIT, 
    ECPGt_int,&(item1),(long)1,(long)1,sizeof(int), 
index b23107714c9d4c7db09fbea8f21df79a1bd0070e..dc9cdbc909e76ffec512d896584d73c53d9ba4ff 100644 (file)
@@ -267,7 +267,7 @@ main (void)
 {
    MYTYPE      *myvar;
    MYNULLTYPE  *mynullvar;
-
+   int loopcount;
    char msg[128];
 
    ECPGdebug(1, stderr);
@@ -333,7 +333,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 #line 96 "outofscope.pgc"
 
 
-   while (1)
+   for (loopcount = 0; loopcount < 100; loopcount++)
    {
        memset(myvar, 0, sizeof(MYTYPE));
        get_record1();
index 08e2355d169201c2562439164693af7cdf3fe1a7..3954f837690990841d20bbc0440caf8f744e99ea 100644 (file)
@@ -120,7 +120,7 @@ main (void)
 
 #line 37 "variable.pgc"
 
-
+   int loopcount;
    char msg[128];
 
         ECPGdebug(1, stderr);
@@ -204,7 +204,7 @@ if (sqlca.sqlcode < 0) exit (1);}
    p=&personal;
    i=&ind_personal;
    memset(i, 0, sizeof(ind_personal));
-   while (1) {
+   for (loopcount = 0; loopcount < 100; loopcount++) {
        strcpy(msg, "fetch");
        { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch cur", ECPGt_EOIT, 
    ECPGt_varchar,&(p->name),(long)BUFFERSIZ,(long)-1,sizeof( struct birthinfo ), 
index a367af00f378deedb3fdfae9c155a8e102c9e5e9..86b9984c0440fa5ff7615a2de3611ed6d437c3f0 100644 (file)
@@ -33,7 +33,7 @@ int main(void)
         
         
     
-
+    
     
    
 #line 15 "whenever_do_continue.pgc"
@@ -48,6 +48,9 @@ int main(void)
  float comm ;
  } emp ;
  
+#line 16 "whenever_do_continue.pgc"
+ int loopcount ;
 #line 17 "whenever_do_continue.pgc"
  char msg [ 128 ] ;
 /* exec sql end declare section */
@@ -119,7 +122,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #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, 
    ECPGt_char,&(emp.ename),(long)12,(long)1,(12)*sizeof(char), 
index b547b25c7a8b1e8da7eb7cbd700d83a71a7cdec4..b1b13aeb7529ba14ae0422887e49d422961b6058 100644 (file)
 int main() {
   /* exec sql begin declare section */
      
-      
+       
   
 #line 9 "fetch.pgc"
  char str [ 25 ] ;
  
 #line 10 "fetch.pgc"
- int i , count = 1 ;
+ int i , count = 1 , loopcount ;
 /* exec sql end declare section */
 #line 11 "fetch.pgc"
 
@@ -112,7 +112,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
   /* exec sql whenever not found  break ; */
 #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, 
    ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
    ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
@@ -191,7 +191,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
   /* exec sql whenever not found  break ; */
 #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, 
    ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
    ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
index 0a3b77c57565399d2490ffafd96f6225b7d86d52..7943384fd87292ad3dfb26553881e4af47d0650e 100644 (file)
 int main() {
   /* exec sql begin declare section */
      
-     
+      
   
 #line 9 "quote.pgc"
  char var [ 25 ] ;
  
 #line 10 "quote.pgc"
- int i ;
+ int i , loopcount ;
 /* exec sql end declare section */
 #line 11 "quote.pgc"
 
@@ -176,7 +176,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 47 "quote.pgc"
 
 
-  while (true)
+  for (loopcount = 0; loopcount < 100; loopcount++)
   {
    { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch C", ECPGt_EOIT, 
    ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
index bc682b93d560b99a426899479d112bd699025802..7df08194e196db641ea5138238bcad60b3890269 100644 (file)
@@ -18,7 +18,7 @@ int
 main(void)
 {
    exec sql begin declare section;
-   int id;
+   int id, loopcount;
    double  d;
    numeric *num;
    char    val[16];
@@ -34,7 +34,7 @@ main(void)
 
    exec sql declare cur cursor for select id, d, d from nantest1;
    exec sql open cur;
-   while (1)
+   for (loopcount = 0; loopcount < 100; loopcount++)
    {
        exec sql fetch from cur into :id, :d, :val;
        if (sqlca.sqlcode)
@@ -50,7 +50,7 @@ main(void)
    exec sql close cur;
 
    exec sql open cur;
-   while (1)
+   for (loopcount = 0; loopcount < 100; loopcount++)
    {
        exec sql fetch from cur into :id, :d, :val;
        if (sqlca.sqlcode)
@@ -76,7 +76,7 @@ main(void)
 
    exec sql declare cur1 cursor for select id, d, d from nantest2;
    exec sql open cur1;
-   while (1)
+   for (loopcount = 0; loopcount < 100; loopcount++)
    {
        exec sql fetch from cur1 into :id, :num, :val;
        if (sqlca.sqlcode)
index 31c3ab7a56ec8f796405553409343082b862d812..d3d9305da5b92ba6360a853a381f81f7e7d23a9c 100644 (file)
@@ -50,7 +50,7 @@ static void test(void) {
   EXEC SQL WHENEVER NOT FOUND DO BREAK;
 
   i = 0;
-  while (1)
+  while (i < 100)
   {
    EXEC SQL FETCH cur1 INTO :item1:ind1;
    printf("item[%d] = %d\n", i, ind1 ? -1 : item1);
index b03743c991f9d97653a2de5c17620ed6b2c0ba98..c22003e30d9d45c1cb027632d4c34dbc049fd5a1 100644 (file)
@@ -66,7 +66,7 @@ main (void)
 {
    MYTYPE      *myvar;
    MYNULLTYPE  *mynullvar;
-
+   int loopcount;
    char msg[128];
 
    ECPGdebug(1, stderr);
@@ -95,7 +95,7 @@ main (void)
 
    exec sql whenever not found do break;
 
-   while (1)
+   for (loopcount = 0; loopcount < 100; loopcount++)
    {
        memset(myvar, 0, sizeof(MYTYPE));
        get_record1();
index 697a7dc81432e474850ae009f0875912bfde7bd1..423a01c16e23256f0ac5c7d2e5614ac0d5542eab 100644 (file)
@@ -35,7 +35,7 @@ exec sql end declare section;
    exec sql char *married = NULL;
    exec sql long ind_married;
    exec sql ind children;
-
+   int loopcount;
    char msg[128];
 
         ECPGdebug(1, stderr);
@@ -67,7 +67,7 @@ exec sql end declare section;
    p=&personal;
    i=&ind_personal;
    memset(i, 0, sizeof(ind_personal));
-   while (1) {
+   for (loopcount = 0; loopcount < 100; loopcount++) {
        strcpy(msg, "fetch");
        exec sql fetch cur into :p:i, :married:ind_married, :children.integer:ind_children.smallint;
        printf("%8.8s", personal.name.arr);
index 2a925a3c54ffa6a1f9dfff63f87632d6605cbfae..146afecbbba5c63b42c61442e336e182616d0a04 100644 (file)
@@ -13,7 +13,7 @@ int main(void)
        float sal;
        float comm;
    } emp;
-
+   int loopcount;
    char msg[128];
    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.*/
    exec sql whenever sqlerror do continue;
 
-   while (1)
+   for (loopcount = 0; loopcount < 100; loopcount++)
    {
        exec sql fetch c into :emp;
        /* The employees with non-NULL commissions will be displayed. */
index aade678efbef51603aa0f677089c4a2ac0e43f01..8a5d07994ab027cfb92a0116796b219983aab5e1 100644 (file)
@@ -7,7 +7,7 @@ EXEC SQL INCLUDE ../regression;
 int main() {
   EXEC SQL BEGIN DECLARE SECTION;
     char str[25];
-    int i, count=1;
+    int i, count=1, loopcount;
   EXEC SQL END DECLARE SECTION;
 
   ECPGdebug(1, stderr);
@@ -28,7 +28,7 @@ int main() {
   EXEC SQL OPEN C;
 
   EXEC SQL WHENEVER NOT FOUND DO BREAK;
-  while (1) {
+  for (loopcount = 0; loopcount < 100; loopcount++) {
    EXEC SQL FETCH 1 IN C INTO :i, :str;
    printf("%d: %s\n", i, str);
   }
@@ -46,7 +46,7 @@ int main() {
   EXEC SQL OPEN D using 1;
 
   EXEC SQL WHENEVER NOT FOUND DO BREAK;
-  while (1) {
+  for (loopcount = 0; loopcount < 100; loopcount++) {
    EXEC SQL FETCH 1 IN D INTO :i, :str;
    printf("%d: %s\n", i, str);
   }
index 9dd997323cc720f64b367af5661c940576e5b0e0..83efb034840005539dca025c30a0d13a3dfbe537 100644 (file)
@@ -7,7 +7,7 @@ EXEC SQL INCLUDE ../regression;
 int main() {
   EXEC SQL BEGIN DECLARE SECTION;
     char var[25];
-    int i;
+    int i, loopcount;
   EXEC SQL END DECLARE SECTION;
 
   ECPGdebug(1, stderr);
@@ -46,7 +46,7 @@ int main() {
 
   EXEC SQL WHENEVER NOT FOUND DO BREAK;
 
-  while (true)
+  for (loopcount = 0; loopcount < 100; loopcount++)
   {
    EXEC SQL FETCH C INTO :i, :var;
    printf("value: %d %s\n", i, var);