Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uWoC8-001j5Q-4L for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Jul 2025 03:31:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uWoC5-009rDQ-Ur for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Jul 2025 03:31:34 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uWoC5-009rDG-H1 for pgsql-hackers@lists.postgresql.org; Wed, 02 Jul 2025 03:31:34 +0000 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uWoC4-0054GA-1K for pgsql-hackers@lists.postgresql.org; Wed, 02 Jul 2025 03:31:33 +0000 Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-ae360b6249fso807163866b.1 for ; Tue, 01 Jul 2025 20:31:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751427089; x=1752031889; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=xCCmswlubuY1ZGFNJpV53mbWsEWKBswKEYUD3Lz+7S0=; b=m06Cn68PrreuPycGrWt1eLNxLQte2QK7LZ7jP/34PE+sjFn1NCmqGwv2sBCsGnBVuD cWMfqzt6bS4eY6a8OwBAQmyXrHXVF0D5ZtoUJoYYXRI91e95XaTCE7nWh/eO/EcpcT5C guanWMgj8qdjSFe9hdHcI4RQ+yyAyElJwUohzxA4nG4Wmu7HBwC8Xez6eIvkXOVsSmco 9isub85ZKKjzS/mmQH/cJpMQN8ajiBvRnTGp98uLAgr7smQ4tjDBl+6oDBGp3+NuES4o xC4Fv9HpXVucp4WI/RcvHyREx7ax92n0XbSj9yyLwJbVISTZlJ2he4OgWDdBMzdoP5Lt pLSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751427089; x=1752031889; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xCCmswlubuY1ZGFNJpV53mbWsEWKBswKEYUD3Lz+7S0=; b=sGrxey1v+gVEn49LP07q/UNWdMi0hb7HjqRJDzJwN19mFfg0XOk+ocuaunWxm25qr0 EaP4rp9E1hrx9TzU+IevJ0Zkqq/j990Th49pVASgJayAYCPEWrTArSwraHU9YyX1m7Ch D6MWHyjkYSQ3LBaI/Lglcwh9XeTR+eVMeTmz0KoqxrIupJUiISYo+UYQ6LZcoyhZvUzT xOKWOTKsTTeK4nP+ME4omhwNhzE1/1fxx53Uf4Yw4219kI38TFfoKPIzbMcswS6LZZmI 7IHioesMacmvIpH9DkdLbxpyequfEo65nmgbCW5KTFl3l3uyWrrH6Sju8mfmj/Nj8nmN AJhw== X-Gm-Message-State: AOJu0Yyzjv5Nyyf9ZyLepFdDFFZgr3CqsCoiPQQhcHW6Hj8mO7h0EQPE sPXIA5YR43X7n+yKEKIZ8Bww/9+0GfaENDqgWeBp0eMZbdr01pb+a6ymGdZQp3ZfguFD9K3msLH iWq1C1L0Gva4cjvJwwT2EKzJkhDqumUY= X-Gm-Gg: ASbGncs0OjcxeeKqmMPE3GfcRN2wYKeMZsfs1WbPM7mXh6V3qrrzHzcUH5zIU3cAxGS ki751pKeKkKxu+0DiZWTWK7JQrhMd8r/gOS44nEB3ovZBKtQlcNxU8VTH1gyEz1pgLukpiyIoUV 9v6wHtibwqU/3H5DVe6aETRVb5YfceFB5ILK35rqazBKYavmo+J/KLTXnb0WuXMG9I1/9aFL90Z XLl X-Google-Smtp-Source: AGHT+IH1hFadItSNr5uN5IzT+5C6dggWgsNOoflk+OqBuF6fZTuI/wAr8r3HFALBtEkr3psdvlt++klKMSwgs7T189w= X-Received: by 2002:a17:907:9451:b0:ae0:cf2e:7ea4 with SMTP id a640c23a62f3a-ae3c2d546b2mr112507066b.40.1751427089110; Tue, 01 Jul 2025 20:31:29 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jianghua Yang Date: Tue, 1 Jul 2025 20:30:53 -0700 X-Gm-Features: Ac12FXyvJaGZ9BK8Bg-GSJNridOnQ4zhaRrNTPS1aTzOrCbdZdQue-UTZkxt4rc Message-ID: Subject: Re: [PATCH] initdb: Treat empty -U argument as unset username To: "David G. Johnston" Cc: pgsql-hackers@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000007f1be70638e9e5b8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000007f1be70638e9e5b8 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable git show 8e673801262c66af4a54837f63ff596407835c20 effective_user =3D get_id(); - if (strlen(username) =3D=3D 0) + if (!username) username =3D effective_user; The previous code already intended to treat a missing username as falling back to the system user. The check was changed from strlen(username) =3D=3D 0 to !username, but this inadvertently stopped handling the empty-string case. This patch restores the original intent and makes the behavior consistent. David G. Johnston =E4=BA=8E2025=E5=B9=B47=E6= =9C=881=E6=97=A5=E5=91=A8=E4=BA=8C 20:12=E5=86=99=E9=81=93=EF=BC=9A > On Tue, Jul 1, 2025 at 7:56=E2=80=AFPM Jianghua Yang = wrote: > >> Let me know if this approach seems reasonable or if you=E2=80=99d prefer= we >> explicitly reject empty usernames with an error instead. >> >> > I'd rather we reject the ambiguous input. > > David J. > > --0000000000007f1be70638e9e5b8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

git show 8e673801262c66af4= a54837f63ff596407835c20


=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0effective_user = =3D get_id();

- =C2=A0 =C2=A0 =C2=A0 if (strlen(username) =3D=3D= 0)

+ =C2=A0 =C2=A0 =C2=A0 if (!username)

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <= /span>username =3D effective_user;


The previ= ous code already intended to treat a missing username as falling back to th= e system user.=C2=A0
The check was changed from strlen(username) = =3D=3D 0 to !username, but this inadvertently stopped h= andling the empty-string case. This patch restores the original intent and = makes the behavior consistent.

David G. Johnston= <david.g.johnston@gmail.c= om> =E4=BA=8E2025=E5=B9=B47=E6=9C=881=E6=97=A5=E5=91=A8=E4=BA=8C 20:= 12=E5=86=99=E9=81=93=EF=BC=9A
On Tue, Jul 1, 2025 at 7:56=E2=80=AFPM Jiang= hua Yang <yjhjstz= @gmail.com> wrote:
Let me know = if this approach seems reasonable or if you=E2=80=99d prefer we explicitly = reject empty usernames with an error instead.


I'd rather we reject the ambiguous=C2=A0input.
<= br>
David J.

--0000000000007f1be70638e9e5b8--