get_home(): use snprintf instead of insecure sprintf
@@ -447,13 +447,15 @@ valid_output_type (const char *filename) {
char *
get_user_config (void) {
char *user_home = NULL, *path = NULL;
+ size_t len;
user_home = getenv ("HOME");
if (user_home == NULL)
return NULL;
- path = xmalloc (snprintf (NULL, 0, "%s/.goaccessrc", user_home) + 1);
- sprintf (path, "%s/.goaccessrc", user_home);
+ len = snprintf (NULL, 0, "%s/.goaccessrc", user_home) + 1;
+ path = xmalloc (len);
+ snprintf (path, len, "%s/.goaccessrc", user_home);
return path;
}
