1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-17 10:26:15 +00:00

netgraph/ng_base: Allow larger BINARY2ASCII conversions

Allocate the necessary memory for the conversion dynamically starting
with a value which is sufficient for almost all normal cases.

PR:		187835
Reviewed by:	kp
Differential Revision: https://reviews.freebsd.org/D23840
This commit is contained in:
Lutz Donnerhacke 2021-02-07 22:07:34 +01:00
parent fb8c2f743a
commit 45d75e3ac3

View File

@ -2771,7 +2771,7 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
case NGM_BINARY2ASCII:
{
int bufSize = 20 * 1024; /* XXX hard coded constant */
int bufSize = 1024;
const struct ng_parse_type *argstype;
const struct ng_cmdlist *c;
struct ng_mesg *binary, *ascii;
@ -2785,7 +2785,7 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
error = EINVAL;
break;
}
retry_b2a:
/* Get a response message with lots of room */
NG_MKRESPONSE(resp, msg, sizeof(*ascii) + bufSize, M_NOWAIT);
if (resp == NULL) {
@ -2827,9 +2827,13 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
if (argstype == NULL) {
*ascii->data = '\0';
} else {
if ((error = ng_unparse(argstype,
(u_char *)binary->data,
ascii->data, bufSize)) != 0) {
error = ng_unparse(argstype, (u_char *)binary->data,
ascii->data, bufSize);
if (error == ERANGE) {
NG_FREE_MSG(resp);
bufSize *= 2;
goto retry_b2a;
} else if (error) {
NG_FREE_MSG(resp);
break;
}