Fix segfault in per_node_error_log() on armhf architecture.
authorTatsuo Ishii <ishii@postgresql.org>
Tue, 19 Jun 2018 01:10:33 +0000 (10:10 +0900)
committerTatsuo Ishii <ishii@postgresql.org>
Tue, 19 Jun 2018 01:22:12 +0000 (10:22 +0900)
pool_extract_error_message() incorrectly returns 255 (in decimal) on
the architecture when previous message was not an error or a notice
message. In this case per_node_error_log() happily calls ereport since
the return value from pool_extract_error_message() is greater than
0. Unfortunately the message string returned by
pool_extract_error_message() points to garbage memory in this case, a
segfault occurs.

The fix gives per_node_error_log() a guard against the bug of
pool_extract_error_message(). Moreover, the change is more consistent
with other places where pool_extract_error_message() is called.

Fix for pool_extract_error_message() will come later on.

See:
https://github.com/pgpool/pgpool2/issues/14
for more detailed discussion.

Problem reported and patch by Christian Ehrhardt.

src/protocol/pool_proto_modules.c

index f8a435e9a972d2c3ce7eb647883daec93f031e4c..91e37aa0bdab96a35da105ee298d851a42fa530a 100644 (file)
@@ -3139,7 +3139,7 @@ void per_node_error_log(POOL_CONNECTION_POOL *backend, int node_id, char *query,
        POOL_CONNECTION_POOL_SLOT *slot = backend->slots[node_id];
        char *message;
 
-       if (pool_extract_error_message(true, CONNECTION(backend, node_id), MAJOR(backend), true, &message) > 0)
+       if (pool_extract_error_message(true, CONNECTION(backend, node_id), MAJOR(backend), true, &message) == 1)
        {
                ereport(LOG,
                        (errmsg("%s: DB node id: %d backend pid: %d statement: \"%s\" message: \"%s\"",