Permalink
Browse files

Handle some unchecked malloc() calls. Closes #1.

Thanks to Markus Elfring.
1 parent fda0cb3 commit 35c4d3d59a34c0dfebe1b447a352be1e1d9a6e1c @ralight ralight committed Mar 13, 2016
Showing with 14 additions and 0 deletions.
  1. +2 −0 ChangeLog.txt
  2. +12 −0 client/client_shared.c
View
@@ -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
================
@@ -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{

0 comments on commit 35c4d3d

Please sign in to comment.