pt-tls-client: Don't store PT-TLS message on stack
Basically the same as the previous commit.
This commit is contained in:
@@ -358,11 +358,18 @@ static bool authenticate(private_pt_tls_client_t *this)
|
|||||||
*/
|
*/
|
||||||
static bool assess(private_pt_tls_client_t *this, tls_t *tnccs)
|
static bool assess(private_pt_tls_client_t *this, tls_t *tnccs)
|
||||||
{
|
{
|
||||||
|
const size_t max_buflen = PT_TLS_MAX_MESSAGE_LEN;
|
||||||
|
char *buf;
|
||||||
|
|
||||||
|
buf = malloc(max_buflen);
|
||||||
|
if (!buf)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
while (TRUE)
|
while (TRUE)
|
||||||
{
|
{
|
||||||
size_t msglen;
|
size_t msglen, buflen = max_buflen;
|
||||||
size_t buflen = PT_TLS_MAX_MESSAGE_LEN;
|
|
||||||
char buf[buflen];
|
|
||||||
bio_reader_t *reader;
|
bio_reader_t *reader;
|
||||||
uint32_t vendor, type, identifier;
|
uint32_t vendor, type, identifier;
|
||||||
chunk_t data;
|
chunk_t data;
|
||||||
@@ -370,26 +377,27 @@ static bool assess(private_pt_tls_client_t *this, tls_t *tnccs)
|
|||||||
switch (tnccs->build(tnccs, buf, &buflen, &msglen))
|
switch (tnccs->build(tnccs, buf, &buflen, &msglen))
|
||||||
{
|
{
|
||||||
case SUCCESS:
|
case SUCCESS:
|
||||||
|
free(buf);
|
||||||
return tnccs->is_complete(tnccs);
|
return tnccs->is_complete(tnccs);
|
||||||
case ALREADY_DONE:
|
case ALREADY_DONE:
|
||||||
data = chunk_create(buf, buflen);
|
data = chunk_create(buf, buflen);
|
||||||
if (!pt_tls_write(this->tls, PT_TLS_PB_TNC_BATCH,
|
if (!pt_tls_write(this->tls, PT_TLS_PB_TNC_BATCH,
|
||||||
this->identifier++, data))
|
this->identifier++, data))
|
||||||
{
|
{
|
||||||
return FALSE;
|
goto failed;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case INVALID_STATE:
|
case INVALID_STATE:
|
||||||
break;
|
break;
|
||||||
case FAILED:
|
case FAILED:
|
||||||
default:
|
default:
|
||||||
return FALSE;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
reader = pt_tls_read(this->tls, &vendor, &type, &identifier);
|
reader = pt_tls_read(this->tls, &vendor, &type, &identifier);
|
||||||
if (!reader)
|
if (!reader)
|
||||||
{
|
{
|
||||||
return FALSE;
|
goto failed;
|
||||||
}
|
}
|
||||||
if (vendor == 0)
|
if (vendor == 0)
|
||||||
{
|
{
|
||||||
@@ -397,24 +405,25 @@ static bool assess(private_pt_tls_client_t *this, tls_t *tnccs)
|
|||||||
{
|
{
|
||||||
DBG1(DBG_TNC, "received PT-TLS error");
|
DBG1(DBG_TNC, "received PT-TLS error");
|
||||||
reader->destroy(reader);
|
reader->destroy(reader);
|
||||||
return FALSE;
|
goto failed;
|
||||||
}
|
}
|
||||||
if (type != PT_TLS_PB_TNC_BATCH)
|
if (type != PT_TLS_PB_TNC_BATCH)
|
||||||
{
|
{
|
||||||
DBG1(DBG_TNC, "unexpected PT-TLS message: %d", type);
|
DBG1(DBG_TNC, "unexpected PT-TLS message: %d", type);
|
||||||
reader->destroy(reader);
|
reader->destroy(reader);
|
||||||
return FALSE;
|
goto failed;
|
||||||
}
|
}
|
||||||
data = reader->peek(reader);
|
data = reader->peek(reader);
|
||||||
switch (tnccs->process(tnccs, data.ptr, data.len))
|
switch (tnccs->process(tnccs, data.ptr, data.len))
|
||||||
{
|
{
|
||||||
case SUCCESS:
|
case SUCCESS:
|
||||||
reader->destroy(reader);
|
reader->destroy(reader);
|
||||||
|
free(buf);
|
||||||
return tnccs->is_complete(tnccs);
|
return tnccs->is_complete(tnccs);
|
||||||
case FAILED:
|
case FAILED:
|
||||||
default:
|
default:
|
||||||
reader->destroy(reader);
|
reader->destroy(reader);
|
||||||
return FALSE;
|
goto failed;
|
||||||
case NEED_MORE:
|
case NEED_MORE:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -425,6 +434,10 @@ static bool assess(private_pt_tls_client_t *this, tls_t *tnccs)
|
|||||||
}
|
}
|
||||||
reader->destroy(reader);
|
reader->destroy(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
failed:
|
||||||
|
free(buf);
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
METHOD(pt_tls_client_t, run_assessment, status_t,
|
METHOD(pt_tls_client_t, run_assessment, status_t,
|
||||||
|
|||||||
Reference in New Issue
Block a user