From patchwork Mon Mar 27 09:53:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 66934 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 840403858C83 for ; Mon, 27 Mar 2023 09:54:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 840403858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1679910852; bh=8Hph3wVh1/ZmGTvdWb44j5MT8GN4JBQY27/hK0xlnrQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Help: List-Subscribe:From:Reply-To:From; b=cKp/bWuOhVYXNu7vv0ToaJBVkZW5HHA6RJ+V9qQr9jusyTETagInikNKXtZuU0CIC daeOGFlKh/t/qmwhZ6ueiOOvzEL8ekqUJHHUKJ7YmeV8aQlfANo8Qy7Cjt1uRPZhes cDEL1Vgj3lE1ceW73G+ukd3SJ8nGuB5q5WbqQxgQ= 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 9A02A3858CDA for ; Mon, 27 Mar 2023 09:54:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9A02A3858CDA Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-494-zKDOoMjxNn6hk9qieVMVAw-1; Mon, 27 Mar 2023 05:53:59 -0400 X-MC-Unique: zKDOoMjxNn6hk9qieVMVAw-1 Received: by mail-qt1-f198.google.com with SMTP id f2-20020ac87f02000000b003dd98d8bea0so5602804qtk.6 for ; Mon, 27 Mar 2023 02:53:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679910839; h=mime-version:user-agent:message-id:date:organization:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8Hph3wVh1/ZmGTvdWb44j5MT8GN4JBQY27/hK0xlnrQ=; b=fY1rhm33r4fStM30A/iuNMyS4e/bYoAAMro1bpsr50gldLXap61TMDqOxLYSDJ2Jav 0iPgq4wtOs9l8kxWHj4VdmbPJ/ADS/mIn7a63DQb2v9+Tzn28oHYenUnYTezu2OKoZq5 kSje/2TvuF4WdeeqG1zm+BOmcFwkPZlXNYUAyvTVIAMi236xvxSb63EJWHHEMM7ovazs PHFVQjKqktMLyaMWn4jfy1THg5DoKa7UIWdwirwBjN/N8/+JY8KB1dznwQ/SslxmTyz+ 4lY6OxeEfRtw4NGiqvcb4sxbQ4t4Mw3edi+NQVcVL1aFQfojVSaMnQcNu7iFPJnQd61z CZPg== X-Gm-Message-State: AAQBX9d8IWbPr1raJVFrEGhVQu+AZ/I2M+SPLVjqi8MVb0hgm5TToEU+ WzxEo+yMVboDf17xXqtK2tHkxPa62295xm0+Bb8MFRN9F4PNJmXrZRTDm9yt3lwnXcl64QGCyVn o0+hsEZSA2vZlNmT7QR8FLiBGrcK94XAFhCxasgkdQEJyyc4rVUXiKjJmiYc+1DsOKnS+4MgqPh Uv X-Received: by 2002:a05:6214:1304:b0:56f:52ba:ccf7 with SMTP id pn4-20020a056214130400b0056f52baccf7mr22979735qvb.14.1679910839135; Mon, 27 Mar 2023 02:53:59 -0700 (PDT) X-Google-Smtp-Source: AKy350b0ycJ7FZSIUJ2dYsGGSPjGvO6nH2tirbDzjnG4uRIEl05G6+QNMSnk/dEGWfJAo+VIdm0ChQ== X-Received: by 2002:a05:6214:1304:b0:56f:52ba:ccf7 with SMTP id pn4-20020a056214130400b0056f52baccf7mr22979717qvb.14.1679910838756; Mon, 27 Mar 2023 02:53:58 -0700 (PDT) Received: from localhost ([88.120.130.27]) by smtp.gmail.com with ESMTPSA id w10-20020a0cff0a000000b005dd8b934585sm2800242qvt.29.2023.03.27.02.53.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 02:53:58 -0700 (PDT) Received: by localhost (Postfix, from userid 1000) id BBAA3581C79; Mon, 27 Mar 2023 11:53:56 +0200 (CEST) To: libabigail@sourceware.org Subject: [PATCH, applied] Bug 29345 - abipkgdiff is confused by symlinked binaries in RPMs Organization: Red Hat / France X-Operating-System: Fedora 38 X-URL: http://www.redhat.com Date: Mon, 27 Mar 2023 11:53:56 +0200 Message-ID: <87bkkemsej.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 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_H2, 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.29 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, Note that this issue can be reproduced by doing: $ fedabipkgdiff --self-compare -a --from fc37 dx When a binary is a symlink to another one, create_maps_of_package_content doesn't realize it and considers the two binaries to be different. Later, when comes time to self compare both binaries, their abixml files (which are the same, by virtue of symlinks) might be written at the same time in different threads, creating a race condition, leading to corruption of the abixml. This patch fixes this by teaching create_maps_of_package_content to resolve symlinks so that it can detect when two files actually point to the same file. * tools/abipkgdiff.cc (create_maps_of_package_content): Resolve symlinks when mapping binaries. Don't map a binary that has already been seen. Signed-off-by: Dodji Seketeli --- tools/abipkgdiff.cc | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tools/abipkgdiff.cc b/tools/abipkgdiff.cc index 09adc837..2765284e 100644 --- a/tools/abipkgdiff.cc +++ b/tools/abipkgdiff.cc @@ -2460,6 +2460,12 @@ create_maps_of_package_content(package& package, options& opts) ++file) { elf_file_sptr e (new elf_file(*file)); + string resolved_e_path; + // The path 'e->path' might contain symlinks. Let's resolve + // them so we can see if 'e->path' has already been seen before, + // for instance. + real_path(e->path, resolved_e_path); + if (opts.compare_dso_only) { if (e->type != abigail::elf::ELF_TYPE_DSO) @@ -2514,7 +2520,13 @@ create_maps_of_package_content(package& package, options& opts) // base name. So let's consider the full path of the binary // inside the extracted directory. string key = e->name; - package.convert_path_to_unique_suffix(e->path, key); + package.convert_path_to_unique_suffix(resolved_e_path, key); + if (package.path_elf_file_sptr_map().find(key) + != package.path_elf_file_sptr_map().end()) + // 'key' has already been seen before. So we won't map it + // twice. + continue; + package.path_elf_file_sptr_map()[key] = e; if (opts.verbose) emit_prefix("abipkgdiff", cerr) @@ -2544,11 +2556,18 @@ create_maps_of_package_content(package& package, options& opts) } } - if (package.convert_path_to_unique_suffix(e->path, key)) + if (package.convert_path_to_unique_suffix(resolved_e_path, key)) { dir_name(key, key); key += string("/@soname:") + e->soname; } + + if (package.path_elf_file_sptr_map().find(key) + != package.path_elf_file_sptr_map().end()) + // 'key' has already been seen before. So we won't do itl + // twice. + continue; + package.path_elf_file_sptr_map()[key] = e; if (opts.verbose) emit_prefix("abipkgdiff", cerr)