{"id":2219428,"url":"http://patchwork.ozlabs.org/api/patches/2219428/?format=json","web_url":"http://patchwork.ozlabs.org/project/glibc/patch/xnse9c7wji.fsf@greed.delorie.com/","project":{"id":41,"url":"http://patchwork.ozlabs.org/api/projects/41/?format=json","name":"GNU C Library","link_name":"glibc","list_id":"libc-alpha.sourceware.org","list_email":"libc-alpha@sourceware.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<xnse9c7wji.fsf@greed.delorie.com>","list_archive_url":null,"date":"2026-04-02T23:49:21","name":"[v1] nss: fix __get_default_domain logic","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"b20cee6a34aa784e533bd66bb2a11e21f1dd3449","submitter":{"id":4388,"url":"http://patchwork.ozlabs.org/api/people/4388/?format=json","name":"DJ Delorie","email":"dj@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/glibc/patch/xnse9c7wji.fsf@greed.delorie.com/mbox/","series":[{"id":498567,"url":"http://patchwork.ozlabs.org/api/series/498567/?format=json","web_url":"http://patchwork.ozlabs.org/project/glibc/list/?series=498567","date":"2026-04-02T23:49:21","name":"[v1] nss: fix __get_default_domain logic","version":1,"mbox":"http://patchwork.ozlabs.org/series/498567/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2219428/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2219428/checks/","tags":{},"related":[],"headers":{"Return-Path":"<libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":["incoming@patchwork.ozlabs.org","libc-alpha@sourceware.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","libc-alpha@sourceware.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=Ayex7aEq;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org\n (client-ip=38.145.34.32; helo=vm01.sourceware.org;\n envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (1024-bit key,\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=Ayex7aEq","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","server2.sourceware.org;\n arc=none smtp.remote-ip=170.10.129.124"],"Received":["from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fmz9f4PlKz1xtJ\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 03 Apr 2026 10:49:58 +1100 (AEDT)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 33E314BA23D9\n\tfor <incoming@patchwork.ozlabs.org>; Thu,  2 Apr 2026 23:49:56 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by sourceware.org (Postfix) with ESMTP id 770774BA23C3\n for <libc-alpha@sourceware.org>; Thu,  2 Apr 2026 23:49:33 +0000 (GMT)","from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-317-wo0XgHbJPK27WlgwRP5zQw-1; Thu,\n 02 Apr 2026 19:49:31 -0400","from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id 07D7D1800769\n for <libc-alpha@sourceware.org>; Thu,  2 Apr 2026 23:49:28 +0000 (UTC)","from greed.delorie.com (unknown [10.22.88.34])\n by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with\n ESMTPS\n id B7E12180075F\n for <libc-alpha@sourceware.org>; Thu,  2 Apr 2026 23:49:27 +0000 (UTC)","from greed.delorie.com.redhat.com (localhost [127.0.0.1])\n by greed.delorie.com (8.16.1/8.16.1) with ESMTP id 632NnLJD2750529\n for <libc-alpha@sourceware.org>; Thu, 2 Apr 2026 19:49:21 -0400"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 33E314BA23D9","OpenDKIM Filter v2.11.0 sourceware.org 770774BA23C3"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 770774BA23C3","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 770774BA23C3","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775173773; cv=none;\n b=RAOV+0KQdNjrJQD/ssT0HI1qi/Gop1EeiqlU7ozMBzIXCqJHjfJ2gNsKhxdrSx+lhQeZIuWNhiT4cFOrs9VL5BRKZssvxvij8+7mNUievmrJZOHEeOcj4GquJsSBxq9Lkv36D/P+4qgknbbGmBW9L29oI8gIIIdgHAXpZSliPPo=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1775173773; c=relaxed/simple;\n bh=L7DHp8aqIBriN8ujLoaeVkIOKTteA0UShxXWxKvcfjs=;\n h=DKIM-Signature:Date:Message-Id:From:To:Subject;\n b=sKuDhJ6xwgRXKk9EybZjOPZPGem/oDyYR7QoJnFx5ekuOA/8k30EO7RApRiFGWcQArHE3ZI/mwXgogBJtAhjhT/buJrWhxxQkjTezdfG3L8nhyrNpfPgCtEj7cW9ixkglWJW/S8HGRTjShts8BGhEGxMYiNIOoER1Y7YEVtGNWo=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1775173773;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:content-type:content-type;\n bh=8UqR9wP+5WFtgcfXzJQpUS4ECFeM6Xcy8uNMrTleqjQ=;\n b=Ayex7aEqN//wSfS/EZ0nMsWBNwm/Coai1XjoJDM3k8QR99lrLAdiAGwCVONE57UERTCS2x\n 8OWY/kx/HMFly7NSWDFY44PV9Q6XVtsxdqsNFJ997m6Q0VzcIKZKeo7RLX5+8VJ4ezY9QC\n AWKe1riZwTa3pBy6YJgnnZv39rulMZM=","X-MC-Unique":"wo0XgHbJPK27WlgwRP5zQw-1","X-Mimecast-MFC-AGG-ID":"wo0XgHbJPK27WlgwRP5zQw_1775173771","Date":"Thu, 02 Apr 2026 19:49:21 -0400","Message-Id":"<xnse9c7wji.fsf@greed.delorie.com>","From":"DJ Delorie <dj@redhat.com>","To":"libc-alpha@sourceware.org","Subject":"[PATCH v1] nss: fix __get_default_domain logic","X-Scanned-By":"MIMEDefang 3.4.1 on 10.30.177.111","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"PkebjgYbkCqqpG9CS-buUnFXdwr4oeiK5y59XkYjhEY_1775173771","X-Mimecast-Originator":"redhat.com","content-type":"text/plain; charset=\"US-ASCII\"; x-default=true","X-BeenThere":"libc-alpha@sourceware.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Libc-alpha mailing list <libc-alpha.sourceware.org>","List-Unsubscribe":"<https://sourceware.org/mailman/options/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe>","List-Archive":"<https://sourceware.org/pipermail/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-request@sourceware.org?subject=help>","List-Subscribe":"<https://sourceware.org/mailman/listinfo/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=subscribe>","Errors-To":"libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org"},"content":"Florian provided the fix, I did the testcase.  This bug presents\nitself by affecting various ldap-related queries behind nss_compat,\nwhich makes it very difficult to reproduce in our testsuite, so this\ntest is limited to testing the broken function itself.  Since that\nfunction isn't exposed directly, I chose to just link that object to\nthe test case and test it directly.\n\n    nss: fix __get_default_domain logic\n    \n    Fix logic bug in __nss_get_default_domain that prevents\n    proper initialization.\n    \n    Because this function is not exposed, the test case must link\n    against the object directly.\n    \n    Co-authored-by: Florian Weimer <fweimer@redhat.com>","diff":"diff --git a/nss/Makefile b/nss/Makefile\nindex 1c48bd0876..54389ced0e 100644\n--- a/nss/Makefile\n+++ b/nss/Makefile\n@@ -317,6 +317,7 @@ tests := \\\n   test-netdb \\\n   test-rpcent \\\n   testgrp \\\n+  tst-default-domain \\\n   tst-fgetsgent_r \\\n   tst-getaddrinfo \\\n   tst-getaddrinfo2 \\\n@@ -515,6 +516,8 @@ endif\n $(objpfx)tst-nss-files-alias-leak.out: $(objpfx)libnss_files.so\n $(objpfx)tst-nss-files-alias-truncated.out: $(objpfx)libnss_files.so\n \n+$(objpfx)tst-default-domain: $(objpfx)nisdomain.os\n+\n tst-nss-gai-hv2-canonname-ENV = \\\n \t\tMALLOC_TRACE=$(objpfx)tst-nss-gai-hv2-canonname.mtrace \\\n \t\tLD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so\ndiff --git a/nss/nss_compat/nisdomain.c b/nss/nss_compat/nisdomain.c\nindex e7a776b539..e98ad69f44 100644\n--- a/nss/nss_compat/nisdomain.c\n+++ b/nss/nss_compat/nisdomain.c\n@@ -36,7 +36,7 @@ __nss_get_default_domain (char **outdomain)\n \n   __libc_lock_lock (domainname_lock);\n \n-  if (domainname[0] != '\\0')\n+  if (domainname[0] == '\\0')\n     {\n       if (getdomainname (domainname, MAXDOMAINNAMELEN) < 0)\n \tresult = errno;\ndiff --git a/nss/tst-default-domain.c b/nss/tst-default-domain.c\nnew file mode 100644\nindex 0000000000..2fa9153d88\n--- /dev/null\n+++ b/nss/tst-default-domain.c\n@@ -0,0 +1,123 @@\n+/* Basic test of __nss_get_default_domain\n+   Copyright (C) 2026 Free Software Foundation, Inc.\n+   This file is part of the GNU C Library.\n+\n+   The GNU C Library is free software; you can redistribute it and/or\n+   modify it under the terms of the GNU Lesser General Public\n+   License as published by the Free Software Foundation; either\n+   version 2.1 of the License, or (at your option) any later version.\n+\n+   The GNU C Library is distributed in the hope that it will be useful,\n+   but WITHOUT ANY WARRANTY; without even the implied warranty of\n+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+   Lesser General Public License for more details.\n+\n+   You should have received a copy of the GNU Lesser General Public\n+   License along with the GNU C Library; if not, see\n+   <https://www.gnu.org/licenses/>.  */\n+\n+#include <unistd.h>\n+#include <string.h>\n+#include <dlfcn.h>\n+\n+#include \"nss_compat/nisdomain.h\"\n+\n+#include <support/test-driver.h>\n+#include <support/support.h>\n+#include <support/namespace.h>\n+#include <support/check.h>\n+\n+char unset_domain[] = \"unset_domain\";\n+char new_domain[] = \"new_domain\";\n+\n+/* This function checks the __nss_get_default_domain() function in\n+   nss_compat/nssdomain.c.  Because this is an internal function to\n+   libnss_compat.so, the Makefile will link that object to this test\n+   case directly.  */\n+\n+static int\n+do_test (void)\n+{\n+  char *domain_name;\n+  char buf[1024];\n+\n+  /* We need to be in a network namespace so we can change the domain\n+     name without interfering with the host system.  */\n+  support_become_root ();\n+  support_enter_network_namespace ();\n+  if (!support_in_uts_namespace ())\n+    return EXIT_UNSUPPORTED;\n+\n+  /* First pass: set an empty domain and make sure it's returned\n+     correctly.  This should not be cached.  */\n+\n+  /* Set the domain name to a known value.  */\n+  TEST_VERIFY (setdomainname (\"\", 0) == 0);\n+\n+  /* Make sure it got set.  */\n+  TEST_VERIFY (getdomainname (buf, sizeof(buf)) == 0);\n+  TEST_COMPARE_STRING (buf, \"\");\n+\n+  /* Set this to a known \"unknown\" value so we can detect if it's not\n+     changed.  */\n+  domain_name = unset_domain;\n+\n+  /* This is the function we're testing.  */\n+  TEST_VERIFY (__nss_get_default_domain (& domain_name) == 0);\n+\n+  /* Make sure the correct domain name is returned.  */\n+  TEST_VERIFY (domain_name != NULL);\n+  TEST_COMPARE_STRING (domain_name, \"\");\n+\n+  /* Second pass: set a non-empty domain and make sure it's returned\n+     correctly.  This works because the empty domain is not\n+     cached.  */\n+\n+  /* Set the domain name to a known value.  */\n+  TEST_VERIFY (setdomainname (new_domain, strlen (new_domain)) == 0);\n+\n+  /* Make sure it got set.  */\n+  TEST_VERIFY (getdomainname (buf, sizeof(buf)) == 0);\n+  TEST_COMPARE_STRING (buf, new_domain);\n+\n+  /* Set this to a known \"unknown\" value so we can detect if it's not\n+     changed.  */\n+  domain_name = unset_domain;\n+\n+  /* This is the function we're testing.  */\n+  TEST_VERIFY (__nss_get_default_domain (& domain_name) == 0);\n+\n+  /* Make sure the correct domain name is returned.  */\n+  TEST_VERIFY (domain_name != NULL);\n+  TEST_COMPARE_STRING (domain_name, new_domain);\n+\n+  /* The function caches the name, so check it twice.  */\n+  TEST_VERIFY (__nss_get_default_domain (& domain_name) == 0);\n+\n+  TEST_VERIFY (domain_name != NULL);\n+  TEST_COMPARE_STRING (domain_name, new_domain);\n+\n+  /* Third pass: set an empty domain again but expect the cached\n+     value.  */\n+\n+  /* Set the domain name to a known value.  */\n+  TEST_VERIFY (setdomainname (\"\", 0) == 0);\n+\n+  /* Make sure it got set.  */\n+  TEST_VERIFY (getdomainname (buf, sizeof(buf)) == 0);\n+  TEST_COMPARE_STRING (buf, \"\");\n+\n+  /* Set this to a known \"unknown\" value so we can detect if it's not\n+     changed.  */\n+  domain_name = unset_domain;\n+\n+  /* This is the function we're testing.  */\n+  TEST_VERIFY (__nss_get_default_domain (& domain_name) == 0);\n+\n+  TEST_VERIFY (domain_name != NULL);\n+  TEST_COMPARE_STRING (domain_name, new_domain);\n+\n+  return 0;\n+}\n+\n+#include <support/test-driver.c>\n","prefixes":["v1"]}