]> granicus.if.org Git - pgbouncer/commitdiff
Fix some scan-build warnings
authorPeter Eisentraut <peter@eisentraut.org>
Wed, 16 Oct 2019 21:23:10 +0000 (23:23 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Wed, 16 Oct 2019 21:23:10 +0000 (23:23 +0200)
src/admin.c
src/objects.c
src/sbuf.c
src/scram.c

index 4f11f202ecc5b411f32ea02943dd51018bb109f8..6cc38d69cc1571254532b6f035dbd4c4969375ad 100644 (file)
@@ -1610,7 +1610,6 @@ void admin_pause_done(void)
                if (!admin->wait_for_response)
                        continue;
 
-               res = false;
                switch (cf_pause_mode) {
                case P_PAUSE:
                        res = admin_ready(admin, "PAUSE");
@@ -1621,9 +1620,11 @@ void admin_pause_done(void)
                default:
                        if (count_paused_databases() > 0)
                                res = admin_ready(admin, "PAUSE");
-                       else
+                       else {
                                /* FIXME */
                                fatal("admin_pause_done: bad state");
+                               res = false;
+                       }
                }
 
                if (!res)
index 19d89afad008eef87d3495cc11764bda21804e5e..4878fa19bb96da5d60db59c476a3b114fbca3d5a 100644 (file)
@@ -870,9 +870,8 @@ void disconnect_server(PgSocket *server, bool notify, const char *reason, ...)
 
        /* notify server and close connection */
        if (send_term && notify) {
-               if (!sbuf_answer(&server->sbuf, pkt_term, sizeof(pkt_term)))
-                       /* ignore result */
-                       notify = false;
+               bool _ignore = sbuf_answer(&server->sbuf, pkt_term, sizeof(pkt_term));
+               (void) _ignore;
        }
 
        if (server->dns_token) {
index fdc78620358ea8ab7c6945e14c64582b3cb1de2d..6361b5c72d304b62aa7a92e10bbb4de6b308c78a 100644 (file)
@@ -715,13 +715,16 @@ try_more:
 
        /* avoid spending too much time on single socket */
        if (cf_sbuf_loopcnt > 0 && loopcnt >= cf_sbuf_loopcnt) {
+               bool _ignore;
+
                log_debug("loopcnt full");
                /*
                 * sbuf_process_pending() avoids some data if buffer is full,
                 * but as we exit processing loop here, we need to retry
                 * after resync to process all data. (result is ignored)
                 */
-               ok = sbuf_process_pending(sbuf);
+               _ignore = sbuf_process_pending(sbuf);
+               (void) _ignore;
 
                sbuf_wait_for_data_forced(sbuf);
                return;
index d4e0abf1765e3f36ff1633cc07471286f4fa3268..7347cb897389c2a1798db893f5508068f6fe78c0 100644 (file)
@@ -225,6 +225,8 @@ static bool parse_scram_verifier(const char *verifier, int *iterations, char **s
        if (decoded_len < 0)
                goto invalid_verifier;
        *salt = strdup(salt_str);
+       if (!*salt)
+               goto invalid_verifier;
 
        /*
         * Decode StoredKey and ServerKey.
@@ -253,6 +255,7 @@ invalid_verifier:
        free(decoded_stored_buf);
        free(decoded_server_buf);
        free(v);
+       free(*salt);
        *salt = NULL;
        return false;
 }
@@ -332,7 +335,7 @@ char *build_client_final_message(ScramState *scram_state,
        size_t len;
        uint8_t client_proof[SCRAM_KEY_LEN];
 
-       len = snprintf(buf, sizeof(buf), "c=biws,r=%s", server_nonce);
+       snprintf(buf, sizeof(buf), "c=biws,r=%s", server_nonce);
 
        scram_state->client_final_message_without_proof = strdup(buf);
        if (scram_state->client_final_message_without_proof == NULL)
@@ -566,6 +569,7 @@ bool read_client_first_message(PgSocket *client, char *input,
 {
        char *client_first_message_bare = NULL;
        char *client_nonce = NULL;
+       char *client_nonce_copy = NULL;
 
        *cbind_flag_p = *input;
        switch (*input) {
@@ -624,22 +628,25 @@ bool read_client_first_message(PgSocket *client, char *input,
                slog_error(client, "non-printable characters in SCRAM nonce");
                goto failed;
        }
-       client_nonce = strdup(client_nonce);
-       if (client_nonce == NULL)
+       client_nonce_copy = strdup(client_nonce);
+       if (client_nonce_copy == NULL)
                goto failed;
 
        /*
         * There can be any number of optional extensions after this.  We don't
         * support any extensions, so ignore them.
         */
-       while (*input != '\0')
-               read_any_attr(client, &input, NULL);
+       while (*input != '\0') {
+               if (!read_any_attr(client, &input, NULL))
+                       goto failed;
+       }
 
        *client_first_message_bare_p = client_first_message_bare;
-       *client_nonce_p = client_nonce;
+       *client_nonce_p = client_nonce_copy;
        return true;
 failed:
        free(client_first_message_bare);
+       free(client_nonce_copy);
        return false;
 }
 
@@ -652,6 +659,7 @@ bool read_client_final_message(PgSocket *client, const uint8_t *raw_input, char
        char *channel_binding;
        char *client_final_nonce;
        char *proof_start;
+       char *value;
        char *encoded_proof;
        char *proof = NULL;
        int prooflen;
@@ -678,14 +686,16 @@ bool read_client_final_message(PgSocket *client, const uint8_t *raw_input, char
        do
        {
                proof_start = input - 1;
-               encoded_proof = read_any_attr(client, &input, &attr);
-       } while (attr != 'p');
+               value = read_any_attr(client, &input, &attr);
+       } while (value && attr != 'p');
 
-       if (!encoded_proof) {
+       if (!value) {
                slog_error(client, "could not read proof");
                goto failed;
        }
 
+       encoded_proof = value;
+
        proof = malloc(pg_b64_dec_len(strlen(encoded_proof)));
        if (proof == NULL) {
                slog_error(client, "could not decode proof");