Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mosquitto_passwd backup file #2877

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Fix mosquitto_passwd backup file
Signed-off-by: Han Cen <[email protected]>
  • Loading branch information
chamburr committed Aug 19, 2023
commit 5b7bd6d8c1d53c147c1dd073221a9d8545a8fd02
4 changes: 2 additions & 2 deletions apps/mosquitto_passwd/mosquitto_passwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,13 +629,13 @@ int main(int argc, char *argv[])
return 1;
}

backup_file = malloc((size_t)strlen(password_file)+strlen(".backup.XXXXXX"));
backup_file = malloc((size_t)strlen(password_file)+strlen(".backup.XXXXXX")+1);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: pull the size out to a separate variable so you don't need to repeat the calculation below.

if(!backup_file){
fprintf(stderr, "Error: Out of memory.\n");
free(password_file);
return 1;
}
snprintf(backup_file, strlen(password_file)+5, "%s.backup.XXXXXX", password_file);
snprintf(backup_file, strlen(password_file)+strlen(".backup.XXXXXX")+1, "%s.backup.XXXXXX", password_file);
free(password_file);
password_file = NULL;

Expand Down