From patchwork Sat Nov 11 07:44:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 79610 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 19DC73858D1E for ; Sat, 11 Nov 2023 07:45:04 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id C46A63858D1E for ; Sat, 11 Nov 2023 07:44:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C46A63858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C46A63858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699688692; cv=none; b=KqCDdkfG1YIQuRjKfEeNhAGlmYj140XZC0lcWY5i00Iq/rHlYayN2RErd10vjGFDzzjhMY4IeKNs2QMUr6vSUQQLy4iqWZnobd1jw3YMfiNRU3vzGc1gTDVTNzpeYbjXcUHkO7JUZVXG+9FjlhsWWKN7PGxY5DqOd7lULSWlhPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699688692; c=relaxed/simple; bh=j9utmj8fsPQPhpLxhn4P8r+U2bN99E2hV50oFfSwhF4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Md45+C0h7J1EVP1AosdHW4aotcIyTCbsu6YIzLRWXMSbYxXj7TIjXqMNOArticwqijJP9AgTvMzQnQVl5YNLLnHc5bgUAXV3LsVWjyVzn88xfKZ2oecllKrpdZzjqxmDTlMdzCBZoTdBgg3aFG4MC2FISaCqXuvCrLymay1N5xE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699688690; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=8IpDHZEH17HqI0Bc2KHnn13je2KhDQVbfnxFTJ+b01U=; b=cmHYWlN5k7FvHAoWw8T2ejQj6U1RdrJjPo7HvvystetWiYW8lv88rCx8hdEywHp6FbGUWI C2w8Q5zw8ZMpxkOylUpHcxinRhRom+75O0DxG0EZrDrJHoyTqUsGXggVBoYAlHrqapfUKK x6gxnAVOeOU0UbXEkTFxZuGFi3XVPwc= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-163-RGisVF3-OjWVFhhIV_PSyw-1; Sat, 11 Nov 2023 02:44:48 -0500 X-MC-Unique: RGisVF3-OjWVFhhIV_PSyw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 989091C04B57 for ; Sat, 11 Nov 2023 07:44:48 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 444E240C6EB9 for ; Sat, 11 Nov 2023 07:44:48 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH v2] ldconfig: Fixes for skipping temporary files. Date: Sat, 11 Nov 2023 08:44:46 +0100 Message-ID: <87v8a83f9t.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.3 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Arguments to a memchr call were swapped, causing incorrect skipping of files. Files related to dpkg have different names: they actually end in .dpkg-new and .dpkg-tmp, not .tmp as I mistakenly assumed. Fixes commit 2aa0974d2573441bffd59 ("elf: ldconfig should skip temporary files created by package managers"). Tested on i686-linux-gnu and x86_64-linux-gnu. The new version fixes the memchr swapped arguments bug, too. Thanks, Florian --- elf/ldconfig.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) base-commit: d1dcb565a1fb5829f9476a1438c30eccc4027d04 diff --git a/elf/ldconfig.c b/elf/ldconfig.c index 02387a169c..bccd386761 100644 --- a/elf/ldconfig.c +++ b/elf/ldconfig.c @@ -661,6 +661,17 @@ struct dlib_entry struct dlib_entry *next; }; +/* Return true if the N bytes at NAME end with with the characters in + the string SUFFIX. (NAME[N + 1] does not have to be a null byte.) + Expected to be called with a string literal for SUFFIX. */ +static inline bool +endswithn (const char *name, size_t n, const char *suffix) +{ + return (n >= strlen (suffix) + && memcmp (name + n - strlen (suffix), suffix, + strlen (suffix)) == 0); +} + /* Skip some temporary DSO files. These files may be partially written and lead to ldconfig crashes when examined. */ static bool @@ -670,8 +681,7 @@ skip_dso_based_on_name (const char *name, size_t len) names like these are never really DSOs we want to look at. */ if (len >= sizeof (".#prelink#") - 1) { - if (strcmp (name + len - sizeof (".#prelink#") + 1, - ".#prelink#") == 0) + if (endswithn (name, len, ".#prelink#")) return true; if (len >= sizeof (".#prelink#.XXXXXX") - 1 && memcmp (name + len - sizeof (".#prelink#.XXXXXX") @@ -679,10 +689,11 @@ skip_dso_based_on_name (const char *name, size_t len) return true; } /* Skip temporary files created by RPM. */ - if (memchr (name, len, ';') != NULL) + if (memchr (name, ';', len) != NULL) return true; /* Skip temporary files created by dpkg. */ - if (len > 4 && memcmp (name + len - 4, ".tmp", 4) == 0) + if (endswithn (name, len, ".dpkg-new") + || endswithn (name, len, ".dpkg-tmp")) return true; return false; }