From: Peter Eisentraut <peter@eisentraut.org> Date: Wed, 16 Oct 2019 21:23:10 +0000 (+0200) Subject: Fix some scan-build warnings X-Git-Tag: pgbouncer_1_12_0~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=31dd9c1dd674cd8d2469f87769bf642ba0a4b400;p=pgbouncer Fix some scan-build warnings --- diff --git a/src/admin.c b/src/admin.c index 4f11f20..6cc38d6 100644 --- a/src/admin.c +++ b/src/admin.c @@ -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) diff --git a/src/objects.c b/src/objects.c index 19d89af..4878fa1 100644 --- a/src/objects.c +++ b/src/objects.c @@ -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) { diff --git a/src/sbuf.c b/src/sbuf.c index fdc7862..6361b5c 100644 --- a/src/sbuf.c +++ b/src/sbuf.c @@ -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; diff --git a/src/scram.c b/src/scram.c index d4e0abf..7347cb8 100644 --- a/src/scram.c +++ b/src/scram.c @@ -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");