From 35c4d3d59a34c0dfebe1b447a352be1e1d9a6e1c Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sun, 13 Mar 2016 19:07:28 +0000 Subject: [PATCH] Handle some unchecked malloc() calls. Closes #1. Thanks to Markus Elfring. --- ChangeLog.txt | 2 ++ client/client_shared.c | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index d804e4cc..17a43d0f 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -15,6 +15,8 @@ Client library: - Fix the case where a message received just before the keepalive timer expired would cause the client to miss the keepalive timer. +Clients: +- Handle some unchecked malloc() calls. Closes #1. 1.4.8 - 20160214 ================ diff --git a/client/client_shared.c b/client/client_shared.c index 7a1fe0df..cecc5ab5 100644 --- a/client/client_shared.c +++ b/client/client_shared.c @@ -115,6 +115,10 @@ int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char * if(env){ len = strlen(env) + strlen("/mosquitto_pub") + 1; loc = malloc(len); + if(!loc){ + fprintf(stderr, "Error: Out of memory.\n"); + return 1; + } if(pub_or_sub == CLIENT_PUB){ snprintf(loc, len, "%s/mosquitto_pub", env); }else{ @@ -126,6 +130,10 @@ int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char * if(env){ len = strlen(env) + strlen("/.config/mosquitto_pub") + 1; loc = malloc(len); + if(!loc){ + fprintf(stderr, "Error: Out of memory.\n"); + return 1; + } if(pub_or_sub == CLIENT_PUB){ snprintf(loc, len, "%s/.config/mosquitto_pub", env); }else{ @@ -142,6 +150,10 @@ int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char * if(rc > 0 && rc < 1024){ len = strlen(env) + strlen("\\mosquitto_pub.conf") + 1; loc = malloc(len); + if(!loc){ + fprintf(stderr, "Error: Out of memory.\n"); + return 1; + } if(pub_or_sub == CLIENT_PUB){ snprintf(loc, len, "%s\\mosquitto_pub.conf", env); }else{