Skip to content

Commit

Permalink
Handle some unchecked malloc() calls. Closes eclipse-mosquitto#1.
Browse files Browse the repository at this point in the history
Thanks to Markus Elfring.
  • Loading branch information
ralight committed Mar 13, 2016
1 parent fda0cb3 commit 35c4d3d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
================
Expand Down
12 changes: 12 additions & 0 deletions client/client_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand Down

0 comments on commit 35c4d3d

Please sign in to comment.