From 5ef42547c3c55a0d743ea3fabe165ce3bcc3d3c8 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Tue, 23 Jul 2013 17:38:32 -0400 Subject: [PATCH] Check for NULL result from strdup Per Coverity Scan --- src/interfaces/libpq/fe-secure.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c index 174cf426f0..a6a09cd1ab 100644 --- a/src/interfaces/libpq/fe-secure.c +++ b/src/interfaces/libpq/fe-secure.c @@ -1131,7 +1131,17 @@ initialize_SSL(PGconn *conn) { /* Colon, but not in second character, treat as engine:key */ char *engine_str = strdup(conn->sslkey); - char *engine_colon = strchr(engine_str, ':'); + char *engine_colon; + + if (engine_str == NULL) + { + printfPQExpBuffer(&conn->errorMessage, + libpq_gettext("out of memory\n")); + return -1; + } + + /* cannot return NULL because we already checked before strdup */ + engine_colon = strchr(engine_str, ':'); *engine_colon = '\0'; /* engine_str now has engine name */ engine_colon++; /* engine_colon now has key name */ -- 2.40.0