Skip to content

Commit

Permalink
avoid useless strcpy (fix #440)
Browse files Browse the repository at this point in the history
  • Loading branch information
yrutschle committed May 11, 2024
1 parent de7351f commit 684374f
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions systemd-sslh-generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static const char
"PartOf=sslh@%s.socket\n";

static char *resolve_listen(const char *hostname, const char *port) {
char *conn = malloc(strlen(hostname) + strlen(port) + 2);
char *conn = calloc(1, strlen(hostname) + strlen(port) + 2);

This comment has been minimized.

Copy link
@stokito

stokito May 11, 2024

Contributor

The calloc is used for arrays, but here the malloc was more appropriare.

This comment has been minimized.

Copy link
@yrutschle

yrutschle May 11, 2024

Author Owner

ah, I thought you wanted zeroes for security.
It's the same, in the end :-)

This comment has been minimized.

Copy link
@stokito

stokito May 11, 2024

Contributor

Sorry for confusing you, there was another place where list of structs was createdby malloc with multiplication to sizeof

This comment has been minimized.

Copy link
@stokito

stokito May 11, 2024

Contributor

Line 79:
*listen = malloc(len * sizeof(**listen));

Anyway, that's a minor thing so nevermind

CHECK_ALLOC(conn, "malloc")
strcpy(conn, hostname);
strcat(conn, ":");
Expand Down Expand Up @@ -86,12 +86,7 @@ static int get_listen_from_conf(const char *filename, char **listen[]) {
config_setting_source_line(addr));
return -1;
} else {
char *resolved_listen = resolve_listen(hostname, port);

(*listen)[i] = malloc(strlen(resolved_listen));
CHECK_ALLOC((*listen)[i], "malloc");
strcpy((*listen)[i], resolved_listen);
free(resolved_listen);
(*listen)[i] = resolve_listen(hostname, port);
}
}
}
Expand Down

0 comments on commit 684374f

Please sign in to comment.