Fix uninitialized variable in error case in pool_do_auth().
authorTatsuo Ishii <ishii@postgresql.org>
Sun, 17 Nov 2013 04:44:48 +0000 (13:44 +0900)
committerTatsuo Ishii <ishii@postgresql.org>
Sun, 17 Nov 2013 04:49:12 +0000 (13:49 +0900)
If there's no valid backend, pgpool will return garbage pid to
frontend in auth phase. Actually because no backend is available,
frontend will be disconnected later on. So this is not harmless.
Per Coverity report "1127331 Uninitialized scalar variable".

pool_auth.c

index ff457a090362b7bf913a38e19414604f72163aef..71a79aed367a944fa645785eb76c17b480eedbbc 100644 (file)
@@ -347,6 +347,7 @@ from pool_read_message_length and recheck the pg_hba.conf settings.");
         * OK, read pid and secret key
         */
        sp = MASTER_CONNECTION(cp)->sp;
+       pid = -1;
 
        for (i=0;i<NUM_BACKENDS;i++)
        {
@@ -379,14 +380,12 @@ from pool_read_message_length and recheck the pg_hba.conf settings.");
                }
        }
 
-#ifdef NOT_USED
-       sp = MASTER_CONNECTION(cp)->sp;
-       cp->info->major = sp->major;
-       cp->info->minor = sp->minor;
-       strncpy(cp->info->database, sp->database, sizeof(cp->info->database) - 1);
-       strncpy(cp->info->user, sp->user, sizeof(cp->info->user) - 1);
-       cp->info->counter = 1;
-#endif
+       if (pid == -1)
+       {
+               pool_error("pool_do_auth: all backends are down");
+               return -1;
+       }
+
        return pool_send_backend_key_data(frontend, pid, key, protoMajor);
 }