Skip to content

Commit

Permalink
knc: fix a couple of memory leaks.
Browse files Browse the repository at this point in the history
One of these can be remotely triggered during the authentication
phase which leads to a remote DoS possibility.

Pointed out by: Imre Rad <radimre83@gmail.com>
  • Loading branch information
Roland C. Dowdeswell committed Sep 28, 2017
1 parent c78303f commit f237f3e
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions bin/gssstdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,13 @@ gstd_accept(int fd, char **display_creds, char **export_name, char **mech)
&in, GSS_C_NO_CHANNEL_BINDINGS, &client, &mech_oid, &out, NULL,
NULL, NULL);

gss_release_buffer(&min, &in);

if (out.length && write_packet(fd, &out)) {
gss_release_buffer(&min, &out);
return NULL;
}
gss_release_buffer(&min, &out);

GSTD_GSS_ERROR(maj, min, NULL, "gss_accept_sec_context");

Expand Down Expand Up @@ -473,7 +476,7 @@ read_packet(int fd, gss_buffer_t buf, int timeout, int first)
return -2;

LOG(LOG_ERR, ("%s", strerror(errno)));
return -1;
goto bail;
}

if (ret == 0) { /* EOF */
Expand All @@ -486,7 +489,7 @@ read_packet(int fd, gss_buffer_t buf, int timeout, int first)
* a protocol error.
*/
LOG(LOG_INFO, ("EOF reading packet len"));
return -1;
goto bail;
}

len_buf_pos += ret;
Expand All @@ -506,28 +509,29 @@ read_packet(int fd, gss_buffer_t buf, int timeout, int first)
*/
if (len > GSTD_MAXPACKETCONTENTS + 512) {
LOG(LOG_ERR, ("ridiculous length, %ld", len));
return -1;
goto bail;
}

if (!tmpbuf) {
if ((tmpbuf = malloc(len)) == NULL) {
LOG(LOG_CRIT, ("malloc failure, %ld bytes", len));
return -1;
goto bail;
}
}

ret = timed_read(fd, tmpbuf + tmpbuf_pos, len - tmpbuf_pos, timeout);
if (ret == -1) {

if (errno == EINTR || errno == EAGAIN)
return -2;

LOG(LOG_ERR, ("%s", strerror(errno)));
return -1;
goto bail;
}

if (ret == 0) {
LOG(LOG_ERR, ("EOF while reading packet (len=%d)", len));
return -1;
goto bail;
}

tmpbuf_pos += ret;
Expand All @@ -543,6 +547,12 @@ read_packet(int fd, gss_buffer_t buf, int timeout, int first)
}

return -2;

bail:
free(tmpbuf);
tmpbuf = NULL;

return -1;
}

static int
Expand Down

0 comments on commit f237f3e

Please sign in to comment.