From owner-dev-commits-src-all@freebsd.org Mon Feb 8 13:35:11 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 3ED3E532BCE; Mon, 8 Feb 2021 13:35:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DZ6TW1Gmpz3jcB; Mon, 8 Feb 2021 13:35:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1E590183BC; Mon, 8 Feb 2021 13:35:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 118DZBcB024912; Mon, 8 Feb 2021 13:35:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 118DZB5F024911; Mon, 8 Feb 2021 13:35:11 GMT (envelope-from git) Date: Mon, 8 Feb 2021 13:35:11 GMT Message-Id: <202102081335.118DZB5F024911@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Lutz Donnerhacke Subject: git: 45d75e3ac3fb - main - netgraph/ng_base: Allow larger BINARY2ASCII conversions MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: donner X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 45d75e3ac3fb5bf8230ca28dc09b48c6e5ed7a4f Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Feb 2021 13:35:11 -0000 The branch main has been updated by donner: URL: https://cgit.FreeBSD.org/src/commit/?id=45d75e3ac3fb5bf8230ca28dc09b48c6e5ed7a4f commit 45d75e3ac3fb5bf8230ca28dc09b48c6e5ed7a4f Author: Lutz Donnerhacke AuthorDate: 2021-02-07 21:07:34 +0000 Commit: Lutz Donnerhacke CommitDate: 2021-02-08 13:31:58 +0000 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 --- sys/netgraph/ng_base.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/sys/netgraph/ng_base.c b/sys/netgraph/ng_base.c index 6ab39421b255..63bc251f52f9 100644 --- a/sys/netgraph/ng_base.c +++ b/sys/netgraph/ng_base.c @@ -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; }