Skip to content

Commit ec9ca4f

Browse files
committed
Bound agent signature copies
Treat *sigSz as the caller-provided capacity, raise WS_BUFFER_E if the agent response is larger, and clear the size on failure to avoid buffer overruns.
1 parent 06fe99b commit ec9ca4f

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/agent.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,13 +1823,25 @@ int wolfSSH_AGENT_SignRequest(WOLFSSH* ssh,
18231823
ret = WS_AGENT_NO_KEY_E;
18241824
}
18251825
else {
1826-
WMEMCPY(sig, ssh->agent->msg, ssh->agent->msgSz);
1827-
*sigSz = ssh->agent->msgSz;
1826+
word32 maxSigSz = *sigSz;
1827+
1828+
if (ssh->agent->msgSz > maxSigSz) {
1829+
WLOG(WS_LOG_AGENT,
1830+
"agent signature too large for caller buffer");
1831+
ret = WS_BUFFER_E;
1832+
}
1833+
else {
1834+
WMEMCPY(sig, ssh->agent->msg, ssh->agent->msgSz);
1835+
*sigSz = ssh->agent->msgSz;
1836+
}
18281837
}
18291838
}
18301839
else ret = WS_AGENT_NO_KEY_E;
18311840
}
18321841

1842+
if (ret != WS_SUCCESS && sigSz != NULL)
1843+
*sigSz = 0;
1844+
18331845
if (agent != NULL) {
18341846
agent->msg = NULL;
18351847
agent->msgSz = 0;

0 commit comments

Comments
 (0)