From patchwork Thu Sep 7 13:41:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 75452 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CD6DE3856DF8 for ; Thu, 7 Sep 2023 13:41:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CD6DE3856DF8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1694094117; bh=q6qUM05LNEsNdkagSnA20GNGP5uz9e4Tx4LrfxRN9R8=; h=To:Cc:Subject:References:Date:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Help:List-Subscribe:From: Reply-To:From; b=oK9FbAq8nFQfhq+QTXiYDfkxpR9GunY6I9dOUVBBRaurvIyHRPbhGac4WpLXk9AlZ c3osXDDc+u6UYG+67Ke4BMp6ljHteiav8kDu5+9hIMw+i+VfLl8XApkviiOshiW1rh XqDa8tDXYmSH5I1qZUMHUdxWBuhoqj4DkPzZmddk= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 1F8883858D1E for ; Thu, 7 Sep 2023 13:41:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1F8883858D1E Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-412-mxEltowqNNK_hJ0W35t2-w-1; Thu, 07 Sep 2023 09:41:49 -0400 X-MC-Unique: mxEltowqNNK_hJ0W35t2-w-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-649fac91500so17351166d6.1 for ; Thu, 07 Sep 2023 06:41:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694094109; x=1694698909; h=mime-version:user-agent:message-id:in-reply-to:date:references :organization:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q6qUM05LNEsNdkagSnA20GNGP5uz9e4Tx4LrfxRN9R8=; b=YsFaR4PyBKdNpzKrFjUYhMAXWDVebOEvTDosMMX4uwxQtieQeAgrykiuFHPbo7Qai7 mhbc10tGisiVirK1GH8FVtzLWNmCZFHDcAek430Voh305adV4TbT5w+OnCWT/Oen3WSX dWGBF1ZEm8Gh10e6D/iorJFMNkP5Xa+CwrLsqwirWbhfOo01YxPsITI3TEhbPBcRm1fw 53wETh7DFyxPgjKGc7JhjGodXfBHlOTCSfrYniRRkUnNhnBU5XDV7M8JGtk6QuX5lbvg Bq8yH7n+boA1CoJrsrCUu9D4/ODD+kf4QkhYua64VRqtaRXd+nSYyortDvPU4fhOdeSd hIkA== X-Gm-Message-State: AOJu0YwhxXqgOHeZcEFmypwDS/JH2tubS0ZDslMCcBlJP9MpwQcx3FvM Xr14IwdafRM8AOjXYW3LdLmz84omep9qILGGluXPrQBAAZIdVCc/8GeAlBuEyzaqYbwARTDj+aA lvEWNTT3FPqJbTs2YlKO8AQmPWxAm X-Received: by 2002:a0c:f24e:0:b0:64f:3c70:349a with SMTP id z14-20020a0cf24e000000b0064f3c70349amr3703332qvl.19.1694094108714; Thu, 07 Sep 2023 06:41:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFTaTJcY3cmRPkpfmld2sRQ0aqxjraC8h96J/FhMKOcg3jO8D5xmH6MDjdUgmyKi+bDdbv9AA== X-Received: by 2002:a0c:f24e:0:b0:64f:3c70:349a with SMTP id z14-20020a0cf24e000000b0064f3c70349amr3703309qvl.19.1694094108450; Thu, 07 Sep 2023 06:41:48 -0700 (PDT) Received: from localhost ([88.120.130.27]) by smtp.gmail.com with ESMTPSA id t25-20020a0cb719000000b0064f7150fadcsm6435480qvd.4.2023.09.07.06.41.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 06:41:48 -0700 (PDT) Received: by localhost (Postfix, from userid 1000) id 716E3B4FD2; Thu, 7 Sep 2023 15:41:46 +0200 (CEST) To: Dodji Seketeli Cc: libabigail@sourceware.org Subject: [PATCH 08/16] abipkgdiff: Avoid comparing binaries that are outside of the package Organization: Red Hat / France References: <87il8mglc1.fsf@redhat.com> X-Operating-System: CentOS Stream release 9 X-URL: http://www.redhat.com Date: Thu, 07 Sep 2023 15:41:46 +0200 In-Reply-To: <87il8mglc1.fsf@redhat.com> (Dodji Seketeli's message of "Thu, 07 Sep 2023 15:32:46 +0200") Message-ID: <87il8mf6cl.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: Dodji Seketeli via Libabigail From: Dodji Seketeli Reply-To: Dodji Seketeli Errors-To: libabigail-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libabigail" Hello, Some symlinks in some RPMs resolve to binaries outside of the package. In those cases, avoid considering them. * src/abg-tools-utils.cc (maybe_get_symlink_target_file_path): Do not require that the file path points to a symlink. A file path can point to a file that is not a symlink and yet the whole path can be in parent directory that is a symlink. In this case, realpath will correctly resolve to the correct target file. * tools/abipkgdiff.cc (maybe_update_package_content): A path to a binary that is not inside the RPM (because a symlink resolved to a file outside of the RPM) should not be added to the set of binaries to be analyzed. * tests/data/test-diff-pkg/symlink-dir-test1-report1.txt: Add new test file. * tests/data/test-diff-pkg-ctf/symlink-dir-test1-report1.txt: Likewise. * tests/data/Makefile.am: Add new test file to source distribution. * tests/test-diff-pkg.cc (in_out_specs): for the data/test-diff-pkg/symlink-dir-test1/dir{1,2}/symlinks test, the root dir of the package is data/test-diff-pkg/symlink-dir-test1/dir{1,2}. Use that to test that the symlinks are properly handled. Also, use the data/test-diff-pkg/symlink-dir-test1/dir{1,2}/symlinks as a root of an alternative package for which the symlinks resolve outside the package, under data/test-diff-pkg/symlink-dir-test1/dir{1,2}/targets. In this later case, the symlinked files should be ignored in the comparison. Likewise for data/test-diff-pkg-ctf/symlink-dir-test1/dir1/symlinks. Signed-off-by: Dodji Seketeli Applied to master. --- src/abg-tools-utils.cc | 3 -- tests/data/Makefile.am | 2 ++ .../symlink-dir-test1-report1.txt | 0 .../symlink-dir-test1-report1.txt | 0 tests/test-diff-pkg.cc | 32 ++++++++++++++++--- tools/abipkgdiff.cc | 25 ++++++++++++--- 6 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 tests/data/test-diff-pkg-ctf/symlink-dir-test1-report1.txt create mode 100644 tests/data/test-diff-pkg/symlink-dir-test1-report1.txt diff --git a/src/abg-tools-utils.cc b/src/abg-tools-utils.cc index e7155846..08d50347 100644 --- a/src/abg-tools-utils.cc +++ b/src/abg-tools-utils.cc @@ -723,9 +723,6 @@ maybe_get_symlink_target_file_path(const string& file_path, if (!get_stat(file_path, &st)) return false; - if (!S_ISLNK(st.st_mode)) - return false; - char *link_target_path = realpath(file_path.c_str(), NULL); if (!link_target_path) return false; diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index 03361fab..b3434da5 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -2055,6 +2055,7 @@ test-diff-pkg/dirpkg-3-report-1.txt \ test-diff-pkg/dirpkg-3-report-2.txt \ test-diff-pkg/dirpkg-3.suppr \ test-diff-pkg/symlink-dir-test1-report0.txt \ +test-diff-pkg/symlink-dir-test1-report1.txt \ test-diff-pkg/symlink-dir-test1/dir1/symlinks/foo.o \ test-diff-pkg/symlink-dir-test1/dir1/symlinks/libfoo.so \ test-diff-pkg/symlink-dir-test1/dir1/targets/foo.c \ @@ -2300,6 +2301,7 @@ test-diff-pkg-ctf/cracklib-2.9.6-15-ol8u0.x86_64.rpm \ test-diff-pkg-ctf/isl-debuginfo-0.16.1-6.x86_64.rpm \ test-diff-pkg-ctf/tarpkg-1-dir1.tar.gz \ test-diff-pkg-ctf/symlink-dir-test1-report0.txt \ +test-diff-pkg-ctf/symlink-dir-test1-report1.txt \ \ test-fedabipkgdiff/dbus-glib-0.104-3.fc23.x86_64.rpm \ test-fedabipkgdiff/dbus-glib-debuginfo-0.104-3.fc23.x86_64.rpm \ diff --git a/tests/data/test-diff-pkg-ctf/symlink-dir-test1-report1.txt b/tests/data/test-diff-pkg-ctf/symlink-dir-test1-report1.txt new file mode 100644 index 00000000..e69de29b diff --git a/tests/data/test-diff-pkg/symlink-dir-test1-report1.txt b/tests/data/test-diff-pkg/symlink-dir-test1-report1.txt new file mode 100644 index 00000000..e69de29b diff --git a/tests/test-diff-pkg.cc b/tests/test-diff-pkg.cc index 99dc381d..fbfa50d3 100644 --- a/tests/test-diff-pkg.cc +++ b/tests/test-diff-pkg.cc @@ -149,6 +149,18 @@ static InOutSpec in_out_specs[] = "data/test-diff-pkg/dirpkg-3-report-2.txt", "output/test-diff-pkg/dirpkg-3-report-2.txt" }, + { + "data/test-diff-pkg/symlink-dir-test1/dir1", + "data/test-diff-pkg/symlink-dir-test1/dir2", + "--no-default-suppression ", + "", + "", + "", + "", + "", + "data/test-diff-pkg/symlink-dir-test1-report0.txt", + "output/test-diff-pkg/symlink-dir-test1-report0.txt" + }, { "data/test-diff-pkg/symlink-dir-test1/dir1/symlinks", "data/test-diff-pkg/symlink-dir-test1/dir2/symlinks", @@ -158,8 +170,8 @@ static InOutSpec in_out_specs[] = "", "", "", - "data/test-diff-pkg/symlink-dir-test1-report0.txt ", - "output/test-diff-pkg/symlink-dir-test1-report0.txt " + "data/test-diff-pkg/symlink-dir-test1-report1.txt", + "output/test-diff-pkg/symlink-dir-test1-report1.txt" }, #if WITH_TAR { @@ -864,6 +876,18 @@ static InOutSpec in_out_specs[] = "data/test-diff-pkg-ctf/dirpkg-3-report-2.txt", "output/test-diff-pkg-ctf/dirpkg-3-report-2.txt" }, + { + "data/test-diff-pkg-ctf/symlink-dir-test1/dir1", + "data/test-diff-pkg-ctf/symlink-dir-test1/dir2", + "--ctf --no-default-suppression ", + "", + "", + "", + "", + "", + "data/test-diff-pkg-ctf/symlink-dir-test1-report0.txt", + "output/test-diff-pkg-ctf/symlink-dir-test1-report0.txt" + }, { "data/test-diff-pkg-ctf/symlink-dir-test1/dir1/symlinks", "data/test-diff-pkg-ctf/symlink-dir-test1/dir2/symlinks", @@ -873,8 +897,8 @@ static InOutSpec in_out_specs[] = "", "", "", - "data/test-diff-pkg-ctf/symlink-dir-test1-report0.txt ", - "output/test-diff-pkg-ctf/symlink-dir-test1-report0.txt " + "data/test-diff-pkg-ctf/symlink-dir-test1-report1.txt", + "output/test-diff-pkg-ctf/symlink-dir-test1-report1.txt" }, #if WITH_TAR { diff --git a/tools/abipkgdiff.cc b/tools/abipkgdiff.cc index 5ab5c22c..3a601075 100644 --- a/tools/abipkgdiff.cc +++ b/tools/abipkgdiff.cc @@ -2323,14 +2323,20 @@ typedef shared_ptr self_compare_task_sptr; /// function only looks for a file name which name is the same as the /// value of this parameter. /// +/// @param parent_dir_name the name of the directory that the file +/// name denoted by @p entry should belong to. If it doesn't (because +/// it's a symlink that resolves to a file outside of that directory) +/// then the vector of paths of is not updated. +/// /// @param paths out parameter. This is the set of meaningful paths /// of the current directory tree being analyzed. These paths are /// those that are going to be involved in ABI comparison. static void -maybe_update_package_content(const FTSENT *entry, - options &opts, - const string& file_name_to_look_for, - unordered_set& paths) +maybe_update_package_content(const FTSENT* entry, + options& opts, + const string& file_name_to_look_for, + const string& parent_dir_name, + unordered_set& paths) { if (entry == NULL || (entry->fts_info != FTS_F && entry->fts_info != FTS_SL) @@ -2340,6 +2346,15 @@ maybe_update_package_content(const FTSENT *entry, string path = entry->fts_path; maybe_get_symlink_target_file_path(path, path); + string parent_dir = parent_dir_name; + maybe_get_symlink_target_file_path(parent_dir, parent_dir); + + if (!parent_dir_name.empty()) + { + string s; + if (!string_suffix(path, parent_dir, s)) + return; + } if (!file_name_to_look_for.empty()) { @@ -2391,7 +2406,7 @@ get_interesting_files_under_dir(const string dir, FTSENT *entry; unordered_set files; while ((entry = fts_read(file_hierarchy))) - maybe_update_package_content(entry, opts, file_name_to_look_for, files); + maybe_update_package_content(entry, opts, file_name_to_look_for, dir, files); for (unordered_set::const_iterator i = files.begin(); i != files.end();