Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2895869rdh; Wed, 27 Sep 2023 16:54:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFBjJiZQf1SsJ9oZMQnLO7nem9kR4OhzNF6fIuh1PiezSMaugEd+Hv+QIxAHoRpSgNR9Xl3 X-Received: by 2002:a05:6a20:6a06:b0:126:42ce:bd44 with SMTP id p6-20020a056a206a0600b0012642cebd44mr10803534pzk.17.1695858878588; Wed, 27 Sep 2023 16:54:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695858878; cv=none; d=google.com; s=arc-20160816; b=FJc/WUUlk+MhZlGZkPZUu0w2vOrg1y3PEFzPt9vv/NsuHBnCsRBqmUVIjiRuuDsSwz xbNXOd6RjLfeEETkz9wnpWjA8StTk0m4W8jdZ8I1M0KhcW56YG2bmSPAxRO1g68bqXKu 1u8cLOl1O86IijdHWpSlRASwxGfRI/oJQKOR6hfQgn8ti1UyfBAUkVfyBOHJqCsdhNLy I3xoGzuydKMezO3la94D+qGoG+Lv2F4JPRV983SgIDdPWRJO/h/9HTM5Q8BEOH6URSPU mdgP+0WfxNSTHR+KDxwORhJXMu4d+L5lbVR6qRfnnyBF/CK0oPcdIZzNl/PT9t2ivb+Q sjFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=UZDbId/Oq6bQoYjYM1BCQT82RB8NkOnAtSqUmB0Kd0w=; fh=4lGQI6056MBa4/oovMyIYaKLn+Wz/24RGvUivMmQP8E=; b=fw2hB8BGPiUTMf81z1n5fVPOrvtReEpwQXgKpQ0g1WxDERczuGL7PS4Qua5Y3AJgSM gwgqoFQmNIx55dta7MtcKNXmwBRSO/WLmAWHm1bkGZcMOhjI0l6VVIos3wwgVSPXjeP/ W4GEjxCjs91F5t1sBfweVYQWJc0/dJVUdnev88T1wBRNQEdA7NYMD5s0EjWOS3YAAwbW wgpdzbR9USuPXVLA7tGI579A8ZaxaXkJrs3XlhLW8nxHPgbk1bii6JWcjXLPg2dfvORO tMqe2ptcFHg9KHHLJpJl3ybM/E5SCikBdUJ1VGVeVdAJkZ/N6Nz7+5XZ5L1BtAmscj0v D/Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=K3OoYXie; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id u11-20020a6540cb000000b00577680ccf1bsi13966601pgp.709.2023.09.27.16.54.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 16:54:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=K3OoYXie; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 959FF804C210; Wed, 27 Sep 2023 14:54:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229886AbjI0VyU (ORCPT + 99 others); Wed, 27 Sep 2023 17:54:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229672AbjI0VyU (ORCPT ); Wed, 27 Sep 2023 17:54:20 -0400 Received: from mail-il1-x12b.google.com (mail-il1-x12b.google.com [IPv6:2607:f8b0:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A54AFB for ; Wed, 27 Sep 2023 14:54:18 -0700 (PDT) Received: by mail-il1-x12b.google.com with SMTP id e9e14a558f8ab-34fe6722847so36423875ab.1 for ; Wed, 27 Sep 2023 14:54:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695851657; x=1696456457; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=UZDbId/Oq6bQoYjYM1BCQT82RB8NkOnAtSqUmB0Kd0w=; b=K3OoYXiezlxH0q5E/nc5PlxjUJzR/SDdme+slnHrTaSvADuxUi5bwVOOJ1dFpCOc0t +I8YDdX+1k5op5se8dGbHqLJcWOIlloT0eu39WNETu4ByPxSwN6M57oqJjnhA82DIOKk ph7mo+XT9axhBjPVnql0P56KprJ83X/djonI1r6N4h1DcNOi3V1cvk+qbxu//4D+8bTM OFNLGwLJ6nDp5fH2LA1oxpkwyWMz1gGtlPMO3vPBwqIWrlJlUDijD21/HiajUL9fb03n U86nU1Ks0rYLnnraTjSY4RJqkvlQNfpSizCtfmh9VxZwIhe8nPMVYnwacJLZ9QFf+qFW oy+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695851657; x=1696456457; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UZDbId/Oq6bQoYjYM1BCQT82RB8NkOnAtSqUmB0Kd0w=; b=g6Xl/yBenatRN/EdzdVH5iarjCTGnDET9hIH8wIvWvhS/jdHSKDSGVLpEYv44kOJz8 d/uvHOcVZeSY2KDmSyLz34yVx1LiIO/hBdHDldSEWBW08EaLFEUAk8pTzK1mYtub9bBv 63UozhRxHXhswYAZ/gLwxxebQJ6X+UrZIpGiNEBDcgScVrCjMUBewBtMFnylwYpxtYfS nbVaYnXvvq8wI95JbFb7lvpp2Wfa/oMKuWFa28HWZnwBGJDx7z1wdfy7YAOvLxox2OJv iTOnXCsM3TrgQ/OWc8zAntM8xll8WWDfUoe45f0d40okfeL6N3Cqw9yn7QHGwwBLcav1 1IXg== X-Gm-Message-State: AOJu0Yx/DPFBpwKvqBpXckXSPCUgLoVNudNxPaXtO1uoQl9+4Z9zQBJL wkhW+0g3dkW5bcZlRK/YYuhNzWisdyPYG+H6 X-Received: by 2002:a05:6e02:1c07:b0:34f:20d9:74a9 with SMTP id l7-20020a056e021c0700b0034f20d974a9mr7650964ilh.11.1695851656915; Wed, 27 Sep 2023 14:54:16 -0700 (PDT) Received: from lvondent-mobl4.. (c-98-232-221-87.hsd1.or.comcast.net. [98.232.221.87]) by smtp.gmail.com with ESMTPSA id g15-20020a02cd0f000000b0042bbfe3dc42sm4225331jaq.173.2023.09.27.14.54.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 14:54:15 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v4 12/12] bap: Fix freeing value of dbus_message_iter_get_fixed_array Date: Wed, 27 Sep 2023 14:53:54 -0700 Message-ID: <20230927215354.1874835-12-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230927215354.1874835-1-luiz.dentz@gmail.com> References: <20230927215354.1874835-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 27 Sep 2023 14:54:28 -0700 (PDT) From: Luiz Augusto von Dentz The value returned by dbus_message_iter_get_fixed_array is a reference and shall not be freed: 'The returned value is by reference and should not be freed.' --- profiles/audio/bap.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c index 18872329d4ac..48a1a4f86f8d 100644 --- a/profiles/audio/bap.c +++ b/profiles/audio/bap.c @@ -365,19 +365,17 @@ static const GDBusPropertyTable ep_properties[] = { { } }; -static int parse_array(DBusMessageIter *iter, struct iovec **iov) +static int parse_array(DBusMessageIter *iter, struct iovec *iov) { DBusMessageIter array; if (!iov) return 0; - if (!(*iov)) - *iov = new0(struct iovec, 1); - dbus_message_iter_recurse(iter, &array); - dbus_message_iter_get_fixed_array(&array, &(*iov)->iov_base, - (int *)&(*iov)->iov_len); + dbus_message_iter_get_fixed_array(&array, &iov->iov_base, + (int *)&iov->iov_len); + return 0; } @@ -594,10 +592,15 @@ static int parse_bcast_qos(const char *key, int var, DBusMessageIter *iter, dbus_message_iter_get_basic(iter, &qos->bcast.timeout); } else if (!strcasecmp(key, "BCode")) { + struct iovec iov; + if (var != DBUS_TYPE_ARRAY) return -EINVAL; - parse_array(iter, &qos->bcast.bcode); + parse_array(iter, &iov); + + util_iov_free(qos->bcast.bcode, 1); + qos->bcast.bcode = util_iov_dup(&iov, 1); } else { int err; @@ -653,6 +656,9 @@ static int parse_configuration(DBusMessageIter *props, struct iovec **caps, struct bt_bap_qos *qos) { const char *key; + struct iovec iov; + + memset(&iov, 0, sizeof(iov)); while (dbus_message_iter_get_arg_type(props) == DBUS_TYPE_DICT_ENTRY) { DBusMessageIter value, entry; @@ -670,14 +676,20 @@ static int parse_configuration(DBusMessageIter *props, struct iovec **caps, if (var != DBUS_TYPE_ARRAY) goto fail; - if (parse_array(&value, caps)) + if (parse_array(&value, &iov)) goto fail; + + util_iov_free(*caps, 1); + *caps = util_iov_dup(&iov, 1); } else if (!strcasecmp(key, "Metadata")) { if (var != DBUS_TYPE_ARRAY) goto fail; - if (parse_array(&value, metadata)) + if (parse_array(&value, &iov)) goto fail; + + util_iov_free(*metadata, 1); + *metadata = util_iov_dup(&iov, 1); } else if (!strcasecmp(key, "QoS")) { if (var != DBUS_TYPE_ARRAY) goto fail; @@ -1202,6 +1214,7 @@ static void select_cb(struct bt_bap_pac *pac, int err, struct iovec *caps, goto done; } + util_iov_free(ep->caps, 1); ep->caps = util_iov_dup(caps, 1); if (metadata && metadata->iov_base && metadata->iov_len) { -- 2.41.0