Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3449938rdh; Thu, 28 Sep 2023 12:00:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFmFBAvqB3WCOs+vDqsMd+RVM/kZh3xTeOm+qO1xkFcka5LjlyL7CWFjzM+/2v/kY7VFC87 X-Received: by 2002:a05:6870:b292:b0:1e0:eb36:a7ed with SMTP id c18-20020a056870b29200b001e0eb36a7edmr2261622oao.29.1695927609447; Thu, 28 Sep 2023 12:00:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695927609; cv=none; d=google.com; s=arc-20160816; b=JlCbw24FAqKKumVpgKCoWQOv5/JIrUSqwzWKOXCyb5ZJF7HaGr/nH4jXM/nZEE5wt9 tGoqG1Jxq0vQdP3n/9oGD+LO5yhYnchC4zD6LgogmMnFWXlxVrna69avC8ZxDXhKju4j ZMamjNOeF8xedetyMElZVvD8l8qmn3Ul+dwVoSp6/yf0YtUzXRtwVON0usZY3+SPD4A6 /Q5T6GcCYg+1SD03RKA8Um7mja+M/PU79F1uwaYQXU7+ZJAdW5f0MSGJhP85YCn9QGes zfAEbXyBEnaiaidphi9dxgQdP+1gAW4/XE4Kejx9xLJHc+rt2Ieg9VC9zt+wqDESLMs+ 3D8Q== 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 :message-id:date:subject:to:from:dkim-signature; bh=UZDbId/Oq6bQoYjYM1BCQT82RB8NkOnAtSqUmB0Kd0w=; fh=4lGQI6056MBa4/oovMyIYaKLn+Wz/24RGvUivMmQP8E=; b=xqy7/iUYy2grEvXaBKTNHoJJFNGjGA810Lx2aEZ8b71fboHriAscRrRw61N/FnCYqo GLRIdwez21Vq/lzi9UjJzQ6Cq7iieqZJcVoMk5CnbasDNMK+MK4qSwju17YPrllr9wJh VcQxSJInB9sxu0JSPcMbZui6ppIxl5XJzpibPr3/otI9aMXdTvWc2ruWauRNlrRg0ImL 9Zj9MAsF/MJ1G3X/pvmSQbrXtTBm6H4Kod/aNejcOsGihrTWi1/BzlmcS/WJyS9e01hk D69wLjJQiXezlp3S1B6ShKt9rnWcYJSiy+T2a/Iuz0MBWD2yzgPw6uCMyDQEIsNcSDuU MhZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=KuzB7LRI; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id l190-20020a6388c7000000b00565325c6ca6si19045074pgd.489.2023.09.28.12.00.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 12:00:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=KuzB7LRI; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 5301281441BD; Wed, 27 Sep 2023 14:40:10 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229746AbjI0VkJ (ORCPT + 99 others); Wed, 27 Sep 2023 17:40:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229458AbjI0VkI (ORCPT ); Wed, 27 Sep 2023 17:40:08 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C2C3D6 for ; Wed, 27 Sep 2023 14:40:07 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-690d8fb3b7eso10889752b3a.1 for ; Wed, 27 Sep 2023 14:40:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695850806; x=1696455606; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=UZDbId/Oq6bQoYjYM1BCQT82RB8NkOnAtSqUmB0Kd0w=; b=KuzB7LRIUHXGG9MhBkrycDv52nC+4MIva/x3XnB5upiKYQVDm/iUB3j9OnzBbSffWw TBywpKUHRWybNW++hcQot35ZjYutBOvyyTxXvP1Z4RayqgSVov++FaUMQrQtK1UHSK3a vGkgvnP1Z+VXHFFD1OwXt10+uOIm+TaWLIT8wE0ZsDMx/HrMiETbBhPMG04oWBqe1lWQ B6Csdk/H74quYJJbqMmNLKveMONY2F3X5/Uuf46sF1g49IdDN5adp3nyHiah8ESNgwZs dt1JJWfmegdGtswql7Idm3bt6natlGhaiA5GzeI2dJhoR3Ge0uMC2Pz4KclRBxAl2+6s hI7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695850806; x=1696455606; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UZDbId/Oq6bQoYjYM1BCQT82RB8NkOnAtSqUmB0Kd0w=; b=nXQmoYzQMTK1Nn/iz1S94oxY3UevhKyL3VfCWjH8rMcGoQpXcDuIQj83tTOhLiU9YP LQp/OL6xmCo/X1zAnh16MiYnlFFZn4BfzD+tQTjl7MRT+eouMwVFuDSoxf8bJnPhdYLA eEc+3RON9M8Dzg+rpAqBnZrqpkkTF35H45I7Tq3Mioa8VghSR6IIfDP9UDR6Jok5T2bM nAHaRe2KiS+WA668EswwDfYKAnDx7tt9o8Erl88AhRvdf0deRPWHhNgDfrlyY9Rbc+8C wPpJQnh7YGaeDIuQ6nU1dr+mGW2f5tU/jSvCVQ0C26ujSf2QumOkDdhwlK4Gdc+op1GU eJmg== X-Gm-Message-State: AOJu0Yy4+1otrctJcdUHg8ivCEDBzp9lzI9N+PxuSpU+l4gIrTsu/9kC 1uFjFH5nP04WfA+DvnT9YAHxRQ3onYxBalZR X-Received: by 2002:aa7:8893:0:b0:690:3a0f:4165 with SMTP id z19-20020aa78893000000b006903a0f4165mr3675217pfe.32.1695850806074; Wed, 27 Sep 2023 14:40:06 -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 s26-20020aa78d5a000000b00672ea40b8a9sm12546004pfe.170.2023.09.27.14.40.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 14:40:04 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ] bap: Fix freeing value of dbus_message_iter_get_fixed_array Date: Wed, 27 Sep 2023 14:39:51 -0700 Message-ID: <20230927214003.1873224-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Wed, 27 Sep 2023 14:40:10 -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