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 1uWxtM-003zU6-0h for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Jul 2025 13:52:52 +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 1uWxtK-001CDS-2S for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Jul 2025 13:52:50 +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 1uWxtJ-001CBU-Kh for pgsql-hackers@lists.postgresql.org; Wed, 02 Jul 2025 13:52:50 +0000 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uWxtI-005A2I-0J for pgsql-hackers@lists.postgresql.org; Wed, 02 Jul 2025 13:52:49 +0000 Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-60c3aafae23so17018340a12.1 for ; Wed, 02 Jul 2025 06:52:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751464367; x=1752069167; 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=jslu4+B9lsPBSyCCz50ph/sXS2tnXBqC7ZQ7Ujw5jJ4=; b=DheNB+LMyNxmsJxEbjgB+84NimM0RtIRVT5+vPKXUr5Kp+pPr/ghIDdUGhYeIZWrWv KB6bheM/7Fel2m44d0mcHiJU9seM/xcSRxZX7jYS8pOzY+ox57k2tnXENQbedNhIojlp XBqOCHznIuwd5TYYgyYUfed+vwNRV6lq7pzM5OirYDy5yRD9q9KDKLtqaTNkij7VS78/ 3PekTUn004UVL/ULDqzGDtBRQM1RtAG15LPALidEHwg8HAvtTXP6Bl9ms7hRJvLOEC7d Dmf7NhFHYMCj6ipk/XrBYnXrB6ehoGtrQyVBzR8HJslm0VqtG1REQ7psizewtNYFK4m3 Y52Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751464367; x=1752069167; 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=jslu4+B9lsPBSyCCz50ph/sXS2tnXBqC7ZQ7Ujw5jJ4=; b=G7QBvdV4bOB2dwBKmK7U0TM+/mP+VFA5/cSk2FUIwBYFOKlMnYT1kFUSm+bjnNcEYK FTg+LJOfdktV5MXxkwVtwx3oIBDqSidt1CfRU9Yl0P6RiuK/bUijChoS1ZYRC4JUIt5N A1YJw1eu9zNHDEOmMBkcfssYwKQjThxZMwuqOBrguBN31n7c79dAWbWw9w74F0/HKZ6k haicrkNDmSz/gXged7q0BIsNw/oLST5LItN5q1tTHXP8l9cDOmHi50SsdxlKcb1OcCMz niZTkz/SBkCMjNPWz7uvcZm84wqi7xkjZY5Qg2QHHusR6pf5Gq57/6ZTP3Gdud0WiLts NC9w== X-Forwarded-Encrypted: i=1; AJvYcCUb/sEwLq8Y5YJ4qi14OnhzyceBEJebUVNS27f7XfyoZfACEiygOTi8JGfeQv2gEa1easRnmn3s8PbKNYoF@lists.postgresql.org X-Gm-Message-State: AOJu0Yx0D0us4413okZUcUEo12BJI4CKqjga7w9s4L73PETxEeLFDXzq xhBMLhvz5J5vGtbFTcTxK7ISpgOp5HF+o3IO5UVW02w2uGw5ubh2edU0SlV4vtAmNTBEfCt4SV8 woLyPL/ScCfq7qoBRtdBmsGXUyCEEauw= X-Gm-Gg: ASbGncvtov7blXDiZLHOCvIvsHlfeKRRbqSmwpT9HcmnDRfm9GSXSf8CX5PnBmPm2U3 09iRataVdegAIMqrixz9IK/7QT0Nf9Hxi6iMcUpKoXdYQvebadMuo2OMv3+uf8VVEJIFl8uLqMU ou0swf4kdPjhE6cT84jbc7CozHClVVRXT0sZIa0z+6pa4FM4uIUE7M5FZPsi5wsfMC4jarfdJHy gjR X-Google-Smtp-Source: AGHT+IGhOlcwzhfyMYhixDS1c/1dt/poztMlAph5OhujMnS7Mx+x4cFQTo3hBduN9V4unmDQtULWK3wyXVcz9/QGMQw= X-Received: by 2002:a17:906:7953:b0:ad8:91e4:a92b with SMTP id a640c23a62f3a-ae3c3a21363mr299481066b.30.1751464366215; Wed, 02 Jul 2025 06:52:46 -0700 (PDT) MIME-Version: 1.0 References: <0231C713-50C8-4BE5-B7C8-106F57A79655@yesql.se> In-Reply-To: <0231C713-50C8-4BE5-B7C8-106F57A79655@yesql.se> From: Jianghua Yang Date: Wed, 2 Jul 2025 06:52:09 -0700 X-Gm-Features: Ac12FXx_MbDE0s7MHNU89w0BDLctKIDhJtnooxUrJ8T5Qti6VevHK5Jb2i_DjPM Message-ID: Subject: Re: [PATCH] initdb: Treat empty -U argument as unset username To: daniel@yesql.se Cc: Robert Treat , "David G. Johnston" , pgsql-hackers@lists.postgresql.org Content-Type: multipart/mixed; boundary="00000000000062d7630638f29395" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000062d7630638f29395 Content-Type: multipart/alternative; boundary="00000000000062d7620638f29393" --00000000000062d7620638f29393 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi hackers, Based on the suggestion that we should explicitly reject empty usernames instead of silently falling back, I=E2=80=99ve updated the patch accordingl= y. ### Changes in v2: - `initdb` now errors out immediately if the `-U` or `--username` argument is an empty string. - The error message is: superuser name must not be empty - A regression test is added to `src/bin/initdb/t/001_initdb.pl` to verify that the case `initdb -U ''` fails as expected. This approach avoids any ambiguity about whether an empty username is valid, and fails early with a clear message. It also brings consistency with existing checks, such as the one disallowing superuser names starting with `pg_`. Let me know if this looks acceptable or if further refinement is needed. Patch attached. Best regards, Jianghua Yang Daniel Gustafsson =E4=BA=8E2025=E5=B9=B47=E6=9C=882=E6=97= =A5=E5=91=A8=E4=B8=89 00:16=E5=86=99=E9=81=93=EF=BC=9A > > On 2 Jul 2025, at 06:31, Robert Treat wrote: > > > FWIW, I tend to agree with David; I feel like if a user passes in -U, > > there was probably a reason, and a good error message would be more > > useful in clarifying things rather than blindly pushing forward with > > potentially the wrong thing. > > Agreed, and it's not even clear that the previous code was intentionally > trying > to allow an empty -U. An improved error message would be a good patch > though. > > -- > Daniel Gustafsson > > --00000000000062d7620638f29393 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi hackers,

Based on the suggestion that we should = explicitly reject empty usernames instead of silently falling back, I=E2=80= =99ve updated the patch accordingly.

### Changes in v2:

- `in= itdb` now errors out immediately if the `-U` or `--username` argument is an= empty string.
- The error message is:
=C2=A0
=C2=A0 =C2=A0 =C2= =A0 superuser name must not be empty

- A regression test is added to= `src/bin/initdb/t/001_initdb.pl` to v= erify that the case `initdb -U ''` fails as expected.

This a= pproach avoids any ambiguity about whether an empty username is valid, and = fails early with a clear message. It also brings consistency with existing = checks, such as the one disallowing superuser names starting with `pg_`.
Let me know if this looks acceptable or if further refinement is neede= d.

Patch attached.

Best regards, =C2=A0
Jianghua Yang
Daniel Gustafsson <d= aniel@yesql.se> =E4=BA=8E2025=E5=B9=B47=E6=9C=882=E6=97=A5=E5=91=A8= =E4=B8=89 00:16=E5=86=99=E9=81=93=EF=BC=9A
> On 2 Jul 2025, at 06:31, Robert Treat <<= a href=3D"mailto:rob@xzilla.net" target=3D"_blank">rob@xzilla.net> w= rote:

> FWIW, I tend to agree with David; I feel like if a user passes in -U,<= br> > there was probably a reason, and a good error message would be more > useful in clarifying things rather than blindly pushing forward with > potentially the wrong thing.

Agreed, and it's not even clear that the previous code was intentionall= y trying
to allow an empty -U. An improved error message would be a good patch thoug= h.

--
Daniel Gustafsson

--00000000000062d7620638f29393-- --00000000000062d7630638f29395 Content-Type: application/octet-stream; name="0001-initdb-Reject-empty-string-for-U-username-option.patch" Content-Disposition: attachment; filename="0001-initdb-Reject-empty-string-for-U-username-option.patch" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_mcm0mogp0 RnJvbSA3NzMyNmEwMzBmZDJmZmE0YWUwMTJhYWUyODU0MGIzZDhmNWJkNGVmIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBKaWFuZ2h1YSBZYW5nIDx5amhqc3R6QGdtYWlsLmNvbT4KRGF0 ZTogV2VkLCAyIEp1bCAyMDI1IDA2OjQ4OjQ4IC0wNzAwClN1YmplY3Q6IFtQQVRDSF0gaW5pdGRi OiBSZWplY3QgZW1wdHkgc3RyaW5nIGZvciAtVS8tLXVzZXJuYW1lIG9wdGlvbgoKUHJldmlvdXNs eSwgcGFzc2luZyBhbiBlbXB0eSBzdHJpbmcgdG8gdGhlIC1VIG9yIC0tdXNlcm5hbWUgb3B0aW9u CihlLmcuLCBgaW5pdGRiIC1VICcnYCkgd291bGQgY2F1c2UgY29uZnVzaW5nIGVycm9ycyBkdXJp bmcgYm9vdHN0cmFwLAphcyBpbml0ZGIgYXR0ZW1wdGVkIHRvIGNyZWF0ZSBhIHJvbGUgd2l0aCBh biBlbXB0eSBuYW1lLgoKVGhpcyBwYXRjaCBhZGRzIGFuIGV4cGxpY2l0IGNoZWNrIGZvciBlbXB0 eSB1c2VybmFtZXMgYW5kIGV4aXRzCmltbWVkaWF0ZWx5IHdpdGggYSBjbGVhciBlcnJvciBtZXNz YWdlLgoKQSB0ZXN0IGNhc2UgaXMgYWRkZWQgdG8gdmVyaWZ5IHRoYXQgaW5pdGRiIGZhaWxzIHdo ZW4gLVUgaXMgZ2l2ZW4gYW4KZW1wdHkgc3RyaW5nLgotLS0KIHNyYy9iaW4vaW5pdGRiL2luaXRk Yi5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