Skip to content

Commit 7cbd944

Browse files
committed
Fix some minor resource leaks in PerformRadiusTransaction().
Failure to free serveraddrs pointed out by Coverity, failure to close socket noted by code-reading. These bugs seem to be quite old, but given the low probability of taking these error-exit paths and the minimal consequences of the leaks (since the process would presumably exit shortly anyway), it doesn't seem worth back-patching. Michael Paquier and Tom Lane
1 parent d77f014 commit 7cbd944

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/backend/libpq/auth.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -2793,6 +2793,7 @@ PerformRadiusTransaction(char *server, char *secret, char *portstr, char *identi
27932793
{
27942794
ereport(LOG,
27952795
(errmsg("could not generate random encryption vector")));
2796+
pg_freeaddrinfo_all(hint.ai_family, serveraddrs);
27962797
return STATUS_ERROR;
27972798
}
27982799
packet->id = packet->vector[0];
@@ -2827,6 +2828,7 @@ PerformRadiusTransaction(char *server, char *secret, char *portstr, char *identi
28272828
ereport(LOG,
28282829
(errmsg("could not perform MD5 encryption of password")));
28292830
pfree(cryptvector);
2831+
pg_freeaddrinfo_all(hint.ai_family, serveraddrs);
28302832
return STATUS_ERROR;
28312833
}
28322834

@@ -2842,7 +2844,7 @@ PerformRadiusTransaction(char *server, char *secret, char *portstr, char *identi
28422844

28432845
radius_add_attribute(packet, RADIUS_PASSWORD, encryptedpassword, encryptedpasswordlen);
28442846

2845-
/* Length need to be in network order on the wire */
2847+
/* Length needs to be in network order on the wire */
28462848
packetlength = packet->length;
28472849
packet->length = htons(packet->length);
28482850

@@ -2868,6 +2870,7 @@ PerformRadiusTransaction(char *server, char *secret, char *portstr, char *identi
28682870
localaddr.sin_addr.s_addr = INADDR_ANY;
28692871
addrsize = sizeof(struct sockaddr_in);
28702872
#endif
2873+
28712874
if (bind(sock, (struct sockaddr *) & localaddr, addrsize))
28722875
{
28732876
ereport(LOG,
@@ -2964,6 +2967,7 @@ PerformRadiusTransaction(char *server, char *secret, char *portstr, char *identi
29642967
{
29652968
ereport(LOG,
29662969
(errmsg("could not read RADIUS response: %m")));
2970+
closesocket(sock);
29672971
return STATUS_ERROR;
29682972
}
29692973

0 commit comments

Comments
 (0)