Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j2CS7-0004iG-2R for pgsql-hackers@arkaria.postgresql.org; Thu, 13 Feb 2020 11:14:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j2CS5-0003CC-Rk for pgsql-hackers@arkaria.postgresql.org; Thu, 13 Feb 2020 11:14:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j2CS5-0003C5-Do for pgsql-hackers@lists.postgresql.org; Thu, 13 Feb 2020 11:14:37 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1j2CS2-0003Py-Ik for pgsql-hackers@postgresql.org; Thu, 13 Feb 2020 11:14:37 +0000 Received: by mail-wr1-x430.google.com with SMTP id w12so6167747wrt.2 for ; Thu, 13 Feb 2020 03:14:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=from:to:subject:mime-version:date:message-id; bh=a47XBnjBNta7YlRD+7Ox6LujXqVmsdRZkbhD+VNRtuo=; b=tinQ084FThnjgjNMZs33wigHTfhN9HCHLfxDqqSlRIrP7eatgxbX3+L2FfewrgtG/4 vx635yLDjdVImmHkUUmk3BjlyACa9poGZ2ljJPU3lDVXVh/OUZwyohkoA0RGuzt2AK7s E3MqoyBT4qVB5L9zu4N2lxQwA/4lQVLjOTZflS79Vt1dAPD79yJisNH0Htyzhg1I9N+8 vPML2FG48aW2G1Jjg9z3OZTaeQZnPqiBVIPtFwCgD7wUFewpIaFEhaK4Fk56SHOE0jL7 /Oj2JrUgCxKJRzj/qjvqd3Gz8uJogrsMWYJ98cxidBNHLx1EgxsVYGfjHzOLrmFBRfXH cirw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:mime-version:date:message-id; bh=a47XBnjBNta7YlRD+7Ox6LujXqVmsdRZkbhD+VNRtuo=; b=Dh8jzL2SAVhFFVQw7Ad19j7XX7l38EWsywQ0AeDeGI+5Swk4+HwkqpdqQhur+WURT+ GDL1qSQqz6V8fnMvXyoIXWLCDlFLbF53dhonunlDngtw5Y7RF49sW7/NX91duKyR9EhT 8XgjT+tlLAOx+hu3DJrXjj6bLK0+/fvAiDA5Je6U7/4WB8bBKCyZxpqP4fTNPRvgXap2 f3odJxoiLEPlXtZxgXxNAckFhgjAB6uUPuqBGNTfK0eDkeGez/gHcUobd5quYbTNEqUB ppFsSwmUbqdT2Bu2D73ds4LY6pfTmbl43rVsuoUSWjwonJZH+sRFkxjqJ7QSUshMQxRm sttA== X-Gm-Message-State: APjAAAVHtOrrFfdUZnobaIyz7g4W0buMjb6/J0inH4bIxTQg44mDEGZo 3lzDqjharTbnVJNL/wKhmH6dkEpwBu4= X-Google-Smtp-Source: APXvYqzOXD4HP9YlYdPoCkGnknYkDIkF9GSD7BK9b4l/DqAjbWW5i1PZVKpk4OIuETd84tiLtN2irw== X-Received: by 2002:adf:ef8b:: with SMTP id d11mr20355697wro.45.1581592473005; Thu, 13 Feb 2020 03:14:33 -0800 (PST) Received: from antos ([77.87.240.5]) by smtp.gmail.com with ESMTPSA id u14sm2397641wrm.51.2020.02.13.03.14.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2020 03:14:32 -0800 (PST) From: Antonin Houska To: pgsql-hackers@postgresql.org Subject: Dead code in adminpack X-Mailer: MH-E 8.6+git; nmh 1.7; GNU Emacs 26.3.50 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Date: Thu, 13 Feb 2020 12:15:39 +0100 Message-ID: <32663.1581592539@antos> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --=-=-= Content-Type: text/plain I've noticed that convert_and_check_filename() is always passed false for the "logAllowed" argument - someone probably forgot to remove the argument when it was decided that log files are no longer accepted. If the argument was removed, the function would become a bit simpler, see the patch. -- Antonin Houska Web: https://www.cybertec-postgresql.com --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=adminpack_dead_code.patch diff --git a/contrib/adminpack/adminpack.c b/contrib/adminpack/adminpack.c index 29b46aea3e..f33cc6e532 100644 --- a/contrib/adminpack/adminpack.c +++ b/contrib/adminpack/adminpack.c @@ -69,10 +69,10 @@ typedef struct * Convert a "text" filename argument to C string, and check it's allowable. * * Filename may be absolute or relative to the DataDir, but we only allow - * absolute paths that match DataDir or Log_directory. + * absolute paths that match DataDir. */ static char * -convert_and_check_filename(text *arg, bool logAllowed) +convert_and_check_filename(text *arg) { char *filename = text_to_cstring(arg); @@ -99,9 +99,7 @@ convert_and_check_filename(text *arg, bool logAllowed) * Allow absolute paths if within DataDir or Log_directory, even * though Log_directory might be outside DataDir. */ - if (!path_is_prefix_of_path(DataDir, filename) && - (!logAllowed || !is_absolute_path(Log_directory) || - !path_is_prefix_of_path(Log_directory, filename))) + if (!path_is_prefix_of_path(DataDir, filename)) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), errmsg("absolute path not allowed"))); @@ -185,7 +183,7 @@ pg_file_write_internal(text *file, text *data, bool replace) char *filename; int64 count = 0; - filename = convert_and_check_filename(file, false); + filename = convert_and_check_filename(file); if (!replace) { @@ -228,7 +226,7 @@ pg_file_sync(PG_FUNCTION_ARGS) char *filename; struct stat fst; - filename = convert_and_check_filename(PG_GETARG_TEXT_PP(0), false); + filename = convert_and_check_filename(PG_GETARG_TEXT_PP(0)); if (stat(filename, &fst) < 0) ereport(ERROR, @@ -319,13 +317,13 @@ pg_file_rename_internal(text *file1, text *file2, text *file3) *fn3; int rc; - fn1 = convert_and_check_filename(file1, false); - fn2 = convert_and_check_filename(file2, false); + fn1 = convert_and_check_filename(file1); + fn2 = convert_and_check_filename(file2); if (file3 == NULL) fn3 = NULL; else - fn3 = convert_and_check_filename(file3, false); + fn3 = convert_and_check_filename(file3); if (access(fn1, W_OK) < 0) { @@ -411,7 +409,7 @@ pg_file_unlink(PG_FUNCTION_ARGS) requireSuperuser(); - filename = convert_and_check_filename(PG_GETARG_TEXT_PP(0), false); + filename = convert_and_check_filename(PG_GETARG_TEXT_PP(0)); if (access(filename, W_OK) < 0) { @@ -449,7 +447,7 @@ pg_file_unlink_v1_1(PG_FUNCTION_ARGS) { char *filename; - filename = convert_and_check_filename(PG_GETARG_TEXT_PP(0), false); + filename = convert_and_check_filename(PG_GETARG_TEXT_PP(0)); if (access(filename, W_OK) < 0) { --=-=-=--