From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0991742B95; Thu, 25 May 2023 09:13:08 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 95E4640DDB; Thu, 25 May 2023 09:13:07 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 7DE7240A82 for ; Thu, 25 May 2023 09:13:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684998786; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SY/ShOL++RXestLJfDNK4O0a9MKaIgn9o3Vxu93dC7E=; b=Rj8zN83On2mQflRUel684iR1dCZeWvumH9kYNU5fIRpBs1q0HykaUhEKTD+c17eOaoQ4WY cgmDYc2eNHyGKwnIiIOzUeJ+5/N5B5q6GmFBRkSSBvnGvC6trA2FpCyapyDJTYf7+axKU9 PHE4sryQG2q35CkW/EEc2kOVPcuf7Mk= Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-548-tOvJr0dtOPmRquP1U7t2Ag-1; Thu, 25 May 2023 03:13:04 -0400 X-MC-Unique: tOvJr0dtOPmRquP1U7t2Ag-1 Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-1ae438721e2so7366395ad.2 for ; Thu, 25 May 2023 00:13:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684998783; x=1687590783; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SY/ShOL++RXestLJfDNK4O0a9MKaIgn9o3Vxu93dC7E=; b=l1LC1SotXf+lznicl5S/O9ASxpgz/mrepqWrZHLcIRXwOV9crxUEcZdLclrG9C5H1l ZUXCQae+pJweTkoaYT63hQFJzIFZxqSVfgXgNdpu2SWoc2zCFibWahEfSIGIxKqPAWaV w3Gu8tZsNoBSWls13wfNeeJppDa2YrydGe2qnt8AvXYuqfb28uKNYjU85SnNwipHJLJV gPwk4DXzjwxNf/2rITIqqd5WSt4618Dl1gdsUYMAEy/ihlECc3mA+bO8BX80WeJ6DTMc VpCOo+KqUaZEd+arZf8J+Zt8bNTLThrmd8fr/cCvZWObuRE2KQX8KD+LX3Gxh5+lt+CJ JWIw== X-Gm-Message-State: AC+VfDwgPOYXhVq6bHjtFinQ4rvaUKNIV9WdwAzwR6vJlyauyRd+YaU3 QoU6etYn/dDP4LSVgC5OzSM+wZdz9lguV//cBwxm4zuQaR24aKJ0lmKM7YH+981zmNOS+6321Xx ODbQpT+JKmhHSrCbSlcE= X-Received: by 2002:a17:902:d4c1:b0:1ac:946e:4690 with SMTP id o1-20020a170902d4c100b001ac946e4690mr802660plg.49.1684998783499; Thu, 25 May 2023 00:13:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4vpHpCotXOs7QEWINE5cWYxypOOyix7DKKsxOcSn+uXwlpWHW5PQTxyxLe5jrSNMEorO05G/ppFO265khmgKQ= X-Received: by 2002:a17:902:d4c1:b0:1ac:946e:4690 with SMTP id o1-20020a170902d4c100b001ac946e4690mr802647plg.49.1684998783178; Thu, 25 May 2023 00:13:03 -0700 (PDT) MIME-Version: 1.0 References: <20230310181836.162336-1-bruce.richardson@intel.com> <20230405160326.186921-1-bruce.richardson@intel.com> <20230405160326.186921-6-bruce.richardson@intel.com> In-Reply-To: <20230405160326.186921-6-bruce.richardson@intel.com> From: David Marchand Date: Thu, 25 May 2023 09:12:52 +0200 Message-ID: Subject: Re: [PATCH v3 5/5] telemetry: remove VLA in json string format function To: Bruce Richardson Cc: dev@dpdk.org, ciara.power@intel.com, roretzla@linux.microsoft.com, Thomas Monjalon X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Wed, Apr 5, 2023 at 6:05=E2=80=AFPM Bruce Richardson wrote: > > Since variable length arrays (VLAs) are potentially insecure and > unsupported by some compilers, rework the code to remove their use. As > with previous changes to remove VLAs in the telemetry code, this > function uses two methods to avoid modifying the buffer when adding to > it fails: > * if there are only a few characters in the buffer, save them off to > restore on failure, then use the buffer as-is, > * otherwise use malloc rather than a VLA to allocate a temporary buffer > and copy from that on success only. > > Signed-off-by: Bruce Richardson > --- > app/test/test_telemetry_json.c | 2 +- > lib/telemetry/telemetry_json.h | 19 +++++++++++++++++-- > 2 files changed, 18 insertions(+), 3 deletions(-) This change triggers a unit test failure ("interestingly" only with gcc, I can't reproduce with clang). $ ninja -C build-gcc && ./build-gcc/app/test/dpdk-test --no-huge -m 2048 --iova=3Dva -- telemetry_json_autotest ninja: Entering directory `build-gcc' ninja: no work to do. EAL: Detected CPU lcores: 16 EAL: Detected NUMA nodes: 1 EAL: Detected shared linkage of DPDK EAL: Multi-process socket /run/user/114840/dpdk/rte/mp_socket EAL: Selected IOVA mode 'VA' APP: HPET is not enabled, using TSC as default timer RTE>>telemetry_json_autotest test_basic_array: buf =3D '["meaning of life",42]', expected =3D '["meaning of life",42]' OK test_basic_obj: buf =3D '{"weddings":4,"funerals":1}', expected =3D '{"weddings":4,"funerals":1}' OK test_overflow_array: buf =3D '', expected =3D '["Arsenal","Chelsea"]' ERROR Test Failed I guess we need: diff --git a/lib/telemetry/telemetry_json.h b/lib/telemetry/telemetry_json.= h index 7999535848..7a246deacb 100644 --- a/lib/telemetry/telemetry_json.h +++ b/lib/telemetry/telemetry_json.h @@ -153,7 +153,7 @@ __json_format_str(char *buf, const int len, const char *prefix, const char *str, ret =3D __json_format_str_to_buf(tmp, len, prefix, str, suffix); if (ret > 0) - strcpy(buf, saved); + strcpy(buf, tmp); free(tmp); return ret; --=20 David Marchand