Skip to content

Commit

Permalink
lib: Ensure pwd_buf is always freed in write_ssh_keys
Browse files Browse the repository at this point in the history
Prior to this change, a NULL pw_dir would result in pwd_buf being leaked after
write_ssh_keys is called. Granted, it's a minor leak, and only potential, but
should still be fixed regardless.

Signed-off-by: Ikey Doherty <[email protected]>
  • Loading branch information
Ikey Doherty authored and ahkok committed Jul 27, 2016
1 parent bc5f756 commit 574c759
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ bool write_ssh_keys(const GString* data, const gchar* username) {
GString* ssh_keys = NULL;
struct passwd pwd;
struct passwd* pwd_result;
char* pwd_buf;
char* pwd_buf = NULL;
long int pwd_bufsize;
struct stat st;

Expand Down Expand Up @@ -322,6 +322,8 @@ bool write_ssh_keys(const GString* data, const gchar* username) {
LOG(MOD "Cannot change the owner and group of %s.\n", auth_keys_file);
return false;
}
} else {
free(pwd_buf);
}

return true;
Expand Down

0 comments on commit 574c759

Please sign in to comment.