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.96) (envelope-from ) id 1wRm0J-002gLt-2E for pgsql-hackers@arkaria.postgresql.org; Tue, 26 May 2026 07:15:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wRm0H-003ctG-1e for pgsql-hackers@arkaria.postgresql.org; Tue, 26 May 2026 07:15:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wRm0H-003ct8-0d for pgsql-hackers@lists.postgresql.org; Tue, 26 May 2026 07:15:06 +0000 Received: from mail-dy1-x132b.google.com ([2607:f8b0:4864:20::132b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wRm0F-00000001Tpt-3rTr for pgsql-hackers@postgresql.org; Tue, 26 May 2026 07:15:05 +0000 Received: by mail-dy1-x132b.google.com with SMTP id 5a478bee46e88-2ef2a1cc06dso1137571eec.0 for ; Tue, 26 May 2026 00:15:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779779701; x=1780384501; darn=postgresql.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=Yvbhgujr3ScDSRWmlnbgmiocH+uCBdrEsGiIsYXc89U=; b=inhxePRbYcJ4dmtMOPEET6wZmKBm+q71Xu1MvgvdicLBmH8uy9dDGK1IcVGdTGLszT 40Zmja32XB9NxyLSl2svLfbEeg5VhHZS/vh8xpLVV9vEDDyVJqL0M/1dZjQthtY6h9NU uU17QLRIqupKP/7x8EKwMIgwzBSx7DihsqcDiKrQJe+LQb5e8k1E85ezs5SRHhXBVkf5 WEbhpwN7CmK3RYfjACObF+HQrrpGvfZourqgZ/wA9sAYN5y8TJhl9HUvWvkIxAhZwggf /D1P8jHRuKSU1sXI05dqTYQQpJOTEaa4uot3vMF5d+tuYJG+uj/L9zzxvFSs7qFVcmdl 0DjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779779701; x=1780384501; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Yvbhgujr3ScDSRWmlnbgmiocH+uCBdrEsGiIsYXc89U=; b=l0iT76OyiMdmT30uNjvoEtnSeYTRtKVe1aHY6glrmV6unEjuPMUQQjlJgVKZXwhbGJ mFMSKx4lI3I+h8gPQJJ7widkz8xrVY/c5tPuRGeu1e3ZoA16STlmwyYj5zgRCgkNY477 S8dIuzNMHFXq0ARvSRXmatY+8zD+KId2DhH7Kcza3WFJ9FFPKWR8OmoCAqM+E3Zx720p /pWRsPqE1LBn3d3CXDt1moKP9chg3E5pD3LV3FmxDAX4dl33dzJpYl48lAUQf6mnlkGa NdJ1nYSpQHQlKGov2rAKy/T6NFIDEoQPY1180D5UAQOm8Fv4G+b2XIl7QtTIUOXfCtg+ ztsQ== X-Forwarded-Encrypted: i=1; AFNElJ963S8nNZm0dSaLqNIEWx6GgASihJWHHiOAS8ZxVARBEsYk8fKC8mZ50cOFXaMgs4e/34PS9f8/QutUm2wv@postgresql.org X-Gm-Message-State: AOJu0YysazaQhcqOBRjiYGr5n+c2omd2tBIz9rsVevCk4USwQVRKFNbJ FV0mONea3E+oJYkb4EbijwpfFJFVQ4wL/Z7GxLtC9nPOvXmJXgARybd8 X-Gm-Gg: Acq92OGlbFp2vfxwA//qAYdEui58nTHIQIMBd2LBivljBnMK2sdlBTqgdWpjU88L8al 5f0/JIe/7a6LghUJFWP50qDHwzKP1B2DSWmeOuqSuBCXaYJkHqHQPq+JQ47G5/brNUpMqaMUjbC dgYE1s5T6JqVfAmORL+chUwySttge47o3qNvmt0pS4xflA8KTvWjFAKtilU8UL5WDGzBuA09Yx0 kFmvDUDWwgSToeWgM3/e5RIVt+sXc7T2cAV/WuJ+mue9xG+FHeiZsm3OL9XmigDEE+U+qoYS5tC 1reP5MeE5O2d5rYCyf4GvQhiJtiQKxXMq5IJhoEbVUpQrs77CoBF0/C+PtUxB1i8QzQIrDYBTf6 zAqnEeotrWK7THtm/+hRKEMJKoWuVwsZSKJ6l3zTQqqN3Naxf8zJ4Ulk2hyYN88Ndh6HJ9M8p6/ rmtkt6iA5eErbRko/kT6XiPrjo1QjfKQ== X-Received: by 2002:a05:693c:68cc:b0:304:641b:12fd with SMTP id 5a478bee46e88-304641b14d2mr3725504eec.27.1779779700846; Tue, 26 May 2026 00:15:00 -0700 (PDT) Received: from smtpclient.apple ([64.32.14.230]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-304535ae870sm9657185eec.19.2026.05.26.00.14.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 May 2026 00:14:59 -0700 (PDT) From: Chao Li Message-Id: <83AF10FE-7655-43DF-A302-3CAC796B572F@gmail.com> Content-Type: multipart/mixed; boundary="Apple-Mail=_DA07ABE3-07C9-4063-AA92-71EB81B51BE9" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.600.51.1.1\)) Subject: Re: Avoid leaking system path from pg_available_extensions Date: Tue, 26 May 2026 15:14:25 +0800 In-Reply-To: <87c8f8ac-614b-4679-afc7-f591b76c8ff7@gmail.com> Cc: Jim Jones , PostgreSQL-development , Andrew Dunstan To: Matheus Alcantara References: <357C774A-ECE9-4455-B641-315205D4D9A1@gmail.com> <96203151-6929-4d88-85a0-d552ee258a24@gmail.com> <87c8f8ac-614b-4679-afc7-f591b76c8ff7@gmail.com> X-Mailer: Apple Mail (2.3864.600.51.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_DA07ABE3-07C9-4063-AA92-71EB81B51BE9 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On May 22, 2026, at 23:40, Matheus Alcantara = wrote: >=20 > On 22/05/26 04:25, Jim Jones wrote: >> On 21/05/2026 17:12, Matheus Alcantara wrote: >>> I've reproduced the issue and the fix looks correct to me. >> same here, +1 >=20 > Thank you for also testing. >=20 >> I was wondering if creating a constant for it would be, stylistically >> speaking, a cleaner solution. For instance: >> #define EXTENSION_SYSTEM_MACRO "$system" >> I realize that it's used only inside = get_extension_control_directories() >> but since it is even mentioned in the docs, I guess it wouldn't be a = bad >> idea. >=20 > I'm not against it but I don't think that it's necessary since as you = mention, only get_extension_control_directories() use. >=20 > -- > Matheus Alcantara > EDB: https://www.enterprisedb.com In theory, I=E2=80=99m not against the idea either. In practice, there = are many hard-coded strings in the source tree, and I=E2=80=99m not sure = where the right place would be to define this macro. Since this string is only used in get_extension_control_directories(), = and now it is used three times, I defined it at the beginning of the = function and undefined it at the end. Let=E2=80=99s see if there are any = objections to that. Please see the attached v2. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/ --Apple-Mail=_DA07ABE3-07C9-4063-AA92-71EB81B51BE9 Content-Disposition: attachment; filename=v2-0001-Avoid-leaking-system-path-from-pg_available_exten.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v2-0001-Avoid-leaking-system-path-from-pg_available_exten.patch" Content-Transfer-Encoding: quoted-printable =46rom=20eaf271a14944df7df87601827f5f5e4909e38c33=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20"Chao=20Li=20(Evan)"=20=0A= Date:=20Wed,=2020=20May=202026=2008:49:15=20+0800=0ASubject:=20[PATCH=20= v2]=20Avoid=20leaking=20system=20path=20from=20pg_available_extensions=0A= =0AThe=20documentation=20says=20that=20when=20extension_control_path=20= is=20set=20to=20an=0Aempty=20string,=20the=20default=20'$system'=20path=20= is=20still=20assumed.=20=20However,=0A= get_extension_control_directories()=20added=20the=20system=20extension=20= directory=0Awith=20a=20NULL=20macro=20in=20that=20case.=20=20As=20a=20= result,=20pg_available_extensions=0Acould=20expose=20the=20expanded=20= system=20directory=20path=20instead=20of=20reporting=0A'$system'=20as=20= the=20location.=0A=0ARecord=20the=20implicitly-added=20system=20= directory=20with=20the=20'$system'=20macro,=20so=0A= pg_available_extensions=20reports=20the=20documented=20symbolic=20= location=20and=20does=0Anot=20leak=20the=20actual=20system=20path.=0A=0A= Update=20the=20extension_control_path=20TAP=20test=20to=20check=20the=20= reported=20location=0Adirectly.=0A=0AAuthor:=20Chao=20Li=20= =0AReviewed-by:=20Lu=20Feng=20=0A= Reviewed-by:=20Matheus=20Alcantara=20=0A= Reviewed-by:=20Jim=20Jones=20=0ADiscussion:=20= https://postgr.es/m/357C774A-ECE9-4455-B641-315205D4D9A1@gmail.com=0A---=0A= =20src/backend/commands/extension.c=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20|=208=20+++++---=0A=20= .../test_extensions/t/001_extension_control_path.pl=20=20=20=20=20=20=20= |=206=20+++---=0A=202=20files=20changed,=208=20insertions(+),=206=20= deletions(-)=0A=0Adiff=20--git=20a/src/backend/commands/extension.c=20= b/src/backend/commands/extension.c=0Aindex=20a330b5fd6ce..d073585c421=20= 100644=0A---=20a/src/backend/commands/extension.c=0A+++=20= b/src/backend/commands/extension.c=0A@@=20-513,6=20+513,7=20@@=20= is_extension_script_filename(const=20char=20*filename)=0A=20static=20= List=20*=0A=20get_extension_control_directories(void)=0A=20{=0A+#define=20= EXTENSION_SYSTEM_MACRO=20=20"$system"=0A=20=09char=09=09= sharepath[MAXPGPATH];=0A=20=09char=09=20=20=20*system_dir;=0A=20=09char=09= =20=20=20*ecp;=0A@@=20-526,7=20+527,7=20@@=20= get_extension_control_directories(void)=0A=20=09{=0A=20=09=09= ExtensionLocation=20*location=20=3D=20palloc_object(ExtensionLocation);=0A= =20=0A-=09=09location->macro=20=3D=20NULL;=0A+=09=09location->macro=20=3D=20= pstrdup(EXTENSION_SYSTEM_MACRO);=0A=20=09=09location->loc=20=3D=20= system_dir;=0A=20=09=09paths=20=3D=20lappend(paths,=20location);=0A=20=09= }=0A@@=20-556,10=20+557,10=20@@=20= get_extension_control_directories(void)=0A=20=09=09=09=20*=20Substitute=20= the=20path=20macro=20if=20needed=20or=20append=20"extension"=0A=20=09=09=09= =20*=20suffix=20if=20it=20is=20a=20custom=20extension=20control=20path.=0A= =20=09=09=09=20*/=0A-=09=09=09if=20(strcmp(piece,=20"$system")=20=3D=3D=20= 0)=0A+=09=09=09if=20(strcmp(piece,=20EXTENSION_SYSTEM_MACRO)=20=3D=3D=20= 0)=0A=20=09=09=09{=0A=20=09=09=09=09location->macro=20=3D=20= pstrdup(piece);=0A-=09=09=09=09mangled=20=3D=20= substitute_path_macro(piece,=20"$system",=20system_dir);=0A+=09=09=09=09= mangled=20=3D=20substitute_path_macro(piece,=20EXTENSION_SYSTEM_MACRO,=20= system_dir);=0A=20=09=09=09}=0A=20=09=09=09else=0A=20=09=09=09{=0A@@=20= -582,6=20+583,7=20@@=20get_extension_control_directories(void)=0A=20=09}=0A= =20=0A=20=09return=20paths;=0A+#undef=20EXTENSION_SYSTEM_MACRO=0A=20}=0A=20= =0A=20/*=0Adiff=20--git=20= a/src/test/modules/test_extensions/t/001_extension_control_path.pl=20= b/src/test/modules/test_extensions/t/001_extension_control_path.pl=0A= index=20c1cec0dc622..4a013a7da4b=20100644=0A---=20= a/src/test/modules/test_extensions/t/001_extension_control_path.pl=0A+++=20= b/src/test/modules/test_extensions/t/001_extension_control_path.pl=0A@@=20= -109,10=20+109,10=20@@=20is($ret,=20"t",=0A=20=09"\$system=20extension=20= is=20shown=20correctly=20in=20pg_available_extensions");=0A=20=0A=20$ret=20= =3D=20$node->safe_psql('postgres',=0A-=09"set=20extension_control_path=20= =3D=20'';=20select=20count(*)=20>=200=20as=20ok=20from=20= pg_available_extensions=20where=20name=20=3D=20'plpgsql'"=0A+=09"set=20= extension_control_path=20=3D=20'';=20select=20location=20from=20= pg_available_extensions=20where=20name=20=3D=20'plpgsql'"=0A=20);=0A= -is($ret,=20"t",=0A-=09"\$system=20extension=20is=20shown=20correctly=20= in=20pg_available_extensions=20with=20empty=20extension_control_path"=0A= +is($ret,=20"\$system",=0A+=09"\$system=20location=20is=20shown=20= correctly=20in=20pg_available_extensions=20with=20empty=20= extension_control_path"=0A=20);=0A=20=0A=20#=20Test=20with=20an=20= extension=20that=20does=20not=20exists=0A--=20=0A2.50.1=20(Apple=20= Git-155)=0A=0A= --Apple-Mail=_DA07ABE3-07C9-4063-AA92-71EB81B51BE9--