From 620974ba042b20e43bcac9cf22b11f25181fa763 Mon Sep 17 00:00:00 2001 From: Dan Farina Date: Wed, 22 Dec 2010 19:00:21 -0800 Subject: [PATCH] Fix unsafe string handling It looks like the old code would overflow in some cases. Signed-off-by: Dan Farina --- repmgr.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/repmgr.c b/repmgr.c index b9336011..9fc2c7ba 100644 --- a/repmgr.c +++ b/repmgr.c @@ -1217,9 +1217,20 @@ do_standby_follow(void) * before closing the connection because we will need them to * recreate the recovery.conf file */ - host = malloc(20); + + /* + * Copy the hostname to the 'host' global variable from the master + * connection. + */ + { + char *pqhost = PQhost(master_conn); + const int host_buf_sz = strlen(pqhost); + + host = malloc(host_buf_sz + 1); + xsnprintf(host, host_buf_sz, "%s", pqhost); + } + masterport = malloc(10); - strcpy(host, PQhost(master_conn)); strcpy(masterport, PQport(master_conn)); PQfinish(master_conn);