From patchwork Mon Jul 14 16:04:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avinal Kumar X-Patchwork-Id: 116255 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 6C6F83857BBF for ; Mon, 14 Jul 2025 16:14:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C6F83857BBF Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=m2iPaNuI X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id CF6323858D37 for ; Mon, 14 Jul 2025 16:13:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CF6323858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CF6323858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1752509613; cv=none; b=f55F8RKolArHV/22x3B6Szlh8j0HgWCsyo4t9aXKeyEtJyZwcq2UXr0cn1MwIMiQ+Yid27xhEsabVijGR2j3KnDMiwvcXmfYV5rA5SXrOs5H+eUhXDmVmsoF23GWTEKGsb+9Q0kZK64VYuljHrTWLYjJkqxGbV92g711u8Ny7Ys= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1752509613; c=relaxed/simple; bh=f6xwyu/QqdXhhcOMRaRa5PW9gexxnXqi2RwhPapI2ic=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=rSlNvf3jRw0iQ9sezCvWAYFTdeCb+eE+5rgwGC5dkpO1a5EDU7vtjfmp8+MrkkklVSX7GN02xusNCzK3BGpV/KNj3a9ttLs99pykvmWHxvN+vRQHZIKLWjirleZF74V7HaRdeyn70genq3OsQ3iximPN4HWMKjT7nJsr0Egz9m8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CF6323858D37 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-7425bd5a83aso3809909b3a.0 for ; Mon, 14 Jul 2025 09:13:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752509611; x=1753114411; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=4fsPbcvT+xw1Gnn2BIqRyfe1FGAfdYHJuwHeL+ol7L0=; b=m2iPaNuIZkU3ql740bsxxTALuoQBZQsuGoXTsZIfccHgNthPNjDqmYLGjTRhzI33DH WvcQBonSPvXl/n0iYKewpiwrQTdKp76LNYwZWuzBh/jHpozFnrOGWf6pwxCAGk2hR5kM 1OmsgBTcf1zTqebOIoZyInYVfbOl2NIcXBcQ+61Hky4vSv7UhkrUXrSJb+7/Eum37tBe U4+mBF8UEJkZpLqkLNoY5xV4CJCKmQLfAgmJ9TJeQO9eJPJ7jieM8qaKOFyxMLfQ4UrJ rE1WyiUUYrJAQJxxsxKsyCYhNaGfkyFp5gNvFeLS9VXsRo/0PhWGI9d5HwjrItSo+jq/ Ijiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752509611; x=1753114411; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4fsPbcvT+xw1Gnn2BIq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id d2e1a72fcca58-74ee03a2206mr18793506b3a.1.1752509611216; Mon, 14 Jul 2025 09:13:31 -0700 (PDT) Received: from spacetime.neon-universe.ts.net ([49.207.202.232]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74eb9f8bd3bsm11086481b3a.149.2025.07.14.09.13.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 09:13:30 -0700 (PDT) From: Avinal Kumar To: libc-alpha@sourceware.org Cc: john.frankish@outlook.com, arjun@redhat.com, Adhemerval Zanella Netto Subject: [PATCH v2] iconv: Fix iconv functions not following symlinks [BZ #32339] Date: Mon, 14 Jul 2025 21:34:27 +0530 Message-ID: <20250714161305.2746056-1-avinal.xlvii@gmail.com> X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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: 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 On some file systems iconv do not follow symlinks. This happens because read_conf_file() function's directory traversal loop reject symbolic links and then lstat64() call do not follow symlinks. This commit fixes the directory traversal loop to accept symbolic links and then follow the link using stat64(). The test works by creating a temporary directory and placing a symbolic link inside it that points to a configuration file. It then runs iconvconfig on this directory. The test passes if iconvconfig successfully follows the symlink and generates the cache correctly, confirming that the directory traversal logic now properly handles symbolic links. Signed-off-by: Avinal Kumar Co-authored-by: Adhemerval Zanella Netto Reviewed-by: Adhemerval Zanella --- It took some time and help to figure out how to cleanly apply the patches, there were some whitespace issues and my first time going though a series. Thanks Arjun for the help :) I tested it with and without the patch and I think it is good for now. Thank you Adhemerval for the tests. --- iconv/Makefile | 6 +++++ iconv/gconv_parseconfdir.h | 8 ++++--- iconv/tst-iconvconfig.sh | 48 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 3 deletions(-) create mode 100755 iconv/tst-iconvconfig.sh diff --git a/iconv/Makefile b/iconv/Makefile index 9a94a41ba4..3ed30dc89b 100644 --- a/iconv/Makefile +++ b/iconv/Makefile @@ -85,6 +85,7 @@ tests-special += \ $(objpfx)tst-iconv_prog-buffer-tiny.out \ $(objpfx)tst-iconv_prog-buffer.out \ $(objpfx)tst-iconv_prog.out \ + $(objpfx)tst-iconvconfig.out \ $(objpfx)tst-translit-mchar.out \ # tests-special endif @@ -164,3 +165,8 @@ $(objpfx)tst-iconv_prog-buffer-large.out: \ tst-iconv_prog-buffer.sh $(objpfx)iconv_prog $(BASH) $< $(common-objdir) '$(run-program-prefix)' '' '22' > $@; \ $(evaluate-test) + +$(objpfx)tst-iconvconfig.out: tst-iconvconfig.sh $(objpfx)iconvconfig + $(BASH) $< $(common-objdir) '$(test-wrapper-env)' \ + '$(run-program-env)' > $@; \ + $(evaluate-test) diff --git a/iconv/gconv_parseconfdir.h b/iconv/gconv_parseconfdir.h index a7ebfd80cc..31f8f1c421 100644 --- a/iconv/gconv_parseconfdir.h +++ b/iconv/gconv_parseconfdir.h @@ -33,9 +33,10 @@ # define closedir __closedir # define mempcpy __mempcpy # define struct_stat64 struct __stat64_t64 -# define lstat64 __lstat64_time64 +# define stat64_impl __stat64_time64 # define feof_unlocked __feof_unlocked #else +# define stat64_impl stat64 # define struct_stat64 struct stat64 #endif @@ -151,7 +152,8 @@ gconv_parseconfdir (const char *prefix, const char *dir, size_t dir_len) struct dirent64 *ent; while ((ent = readdir64 (confdir)) != NULL) { - if (ent->d_type != DT_REG && ent->d_type != DT_UNKNOWN) + if (ent->d_type != DT_REG && ent->d_type != DT_UNKNOWN + && ent->d_type != DT_LNK) continue; size_t len = strlen (ent->d_name); @@ -166,7 +168,7 @@ gconv_parseconfdir (const char *prefix, const char *dir, size_t dir_len) continue; if (ent->d_type != DT_UNKNOWN - || (lstat64 (conf, &st) != -1 && S_ISREG (st.st_mode))) + || (stat64_impl (conf, &st) != -1 && S_ISREG (st.st_mode))) found |= read_conf_file (conf, dir, dir_len); free (conf); diff --git a/iconv/tst-iconvconfig.sh b/iconv/tst-iconvconfig.sh new file mode 100755 index 0000000000..0b16b17f0d --- /dev/null +++ b/iconv/tst-iconvconfig.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# Check if iconvconfig correctly handle config links (BZ 32339) +# Copyright (C) 2025 Free Software Foundation, Inc. +# This file is part of the GNU C Library. + +# The GNU C Library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. + +# The GNU C Library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. + +# You should have received a copy of the GNU Lesser General Public +# License along with the GNU C Library; if not, see +# . + +set -e + +build_dir=$1 +test_wrapper_env="$2" +run_program_env="$3" + +# We have to have some directories in the library path. +LIBPATH=$build_dir:$build_dir/iconvdata + +ICONVCONFIG=" +$build_dir/elf/ld.so --library-path $LIBPATH $build_dir/iconv/iconvconfig +" + +ICONVCONFIG="$test_wrapper_env $run_program_env $ICONVCONFIG" + +TIMEOUTFACTOR=${TIMEOUTFACTOR:-1} + +tmpdir=$(mktemp -d $build_dir/iconv/tst-iconvconfig.XXXXXX) +#trap 'rm -fr $tmpdir' 0 1 2 3 15 EXIT + +touch $tmpdir/gconv-modules-extra.conf +mkdir $tmpdir/gconv-modules.d +cd $tmpdir/gconv-modules.d && ln -s ../gconv-modules-extra.conf . && cd - + +$ICONVCONFIG --nostdlib $tmpdir -o $tmpdir/gconv-modules.cache + +[ ! -e $tmpdir/tmpdir/gconv-modules.cache ] || exit 1 + +exit 0