On Tue, Jun 14, 2022 at 09:52:52AM +0900, Kyotaro Horiguchi wrote: > At Tue, 14 Jun 2022 09:48:26 +0900 (JST), Kyotaro Horiguchi > <horikyota....@gmail.com> wrote in >> Yeah, I feel so and it is what I wondered about recently when I saw >> some complete error messages. Is that because of the length of the >> subject? > > And I found that it is alrady done. Thanks!
I have noticed this thread and 4e54d23 as a result this morning. If you want to spread this style more, wouldn't it be better to do that in all the places of pg_upgrade where we store paths to files? I can see six code paths with log_opts.basedir that could do the same, as of the attached. The hardcoded file names have various lengths, and some of them are quite long making the generated paths more exposed to being cut in the middle. -- Michael
diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index ace7387eda..e1dc031c24 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -704,12 +704,15 @@ check_proper_datallowconn(ClusterInfo *cluster) FILE *script = NULL; char output_path[MAXPGPATH]; bool found = false; + int len; prep_status("Checking database connection settings"); - snprintf(output_path, sizeof(output_path), "%s/%s", - log_opts.basedir, - "databases_with_datallowconn_false.txt"); + len = snprintf(output_path, sizeof(output_path), "%s/%s", + log_opts.basedir, + "databases_with_datallowconn_false.txt"); + if (len >= sizeof(output_path)) + pg_fatal("directory path for new cluster is too long\n"); conn_template1 = connectToServer(cluster, "template1"); @@ -823,6 +826,7 @@ check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster) FILE *script = NULL; bool found = false; char output_path[MAXPGPATH]; + int len; prep_status("Checking for contrib/isn with bigint-passing mismatch"); @@ -834,9 +838,11 @@ check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster) return; } - snprintf(output_path, sizeof(output_path), "%s/%s", - log_opts.basedir, - "contrib_isn_and_int8_pass_by_value.txt"); + len = snprintf(output_path, sizeof(output_path), "%s/%s", + log_opts.basedir, + "contrib_isn_and_int8_pass_by_value.txt"); + if (len >= sizeof(output_path)) + pg_fatal("directory path for new cluster is too long\n"); for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++) { @@ -909,12 +915,15 @@ check_for_user_defined_postfix_ops(ClusterInfo *cluster) FILE *script = NULL; bool found = false; char output_path[MAXPGPATH]; + int len; prep_status("Checking for user-defined postfix operators"); - snprintf(output_path, sizeof(output_path), "%s/%s", - log_opts.basedir, - "postfix_ops.txt"); + len = snprintf(output_path, sizeof(output_path), "%s/%s", + log_opts.basedir, + "postfix_ops.txt"); + if (len >= sizeof(output_path)) + pg_fatal("directory path for new cluster is too long\n"); /* Find any user defined postfix operators */ for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++) @@ -1009,12 +1018,15 @@ check_for_tables_with_oids(ClusterInfo *cluster) FILE *script = NULL; bool found = false; char output_path[MAXPGPATH]; + int len; prep_status("Checking for tables WITH OIDS"); - snprintf(output_path, sizeof(output_path), "%s/%s", - log_opts.basedir, - "tables_with_oids.txt"); + len = snprintf(output_path, sizeof(output_path), "%s/%s", + log_opts.basedir, + "tables_with_oids.txt"); + if (len >= sizeof(output_path)) + pg_fatal("directory path for new cluster is too long\n"); /* Find any tables declared WITH OIDS */ for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++) @@ -1265,12 +1277,15 @@ check_for_user_defined_encoding_conversions(ClusterInfo *cluster) FILE *script = NULL; bool found = false; char output_path[MAXPGPATH]; + int len; prep_status("Checking for user-defined encoding conversions"); - snprintf(output_path, sizeof(output_path), "%s/%s", - log_opts.basedir, - "encoding_conversions.txt"); + len = snprintf(output_path, sizeof(output_path), "%s/%s", + log_opts.basedir, + "encoding_conversions.txt"); + if (len >= sizeof(output_path)) + pg_fatal("directory path for new cluster is too long\n"); /* Find any user defined encoding conversions */ for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++) diff --git a/src/bin/pg_upgrade/function.c b/src/bin/pg_upgrade/function.c index ea785df771..4f65726ed9 100644 --- a/src/bin/pg_upgrade/function.c +++ b/src/bin/pg_upgrade/function.c @@ -125,11 +125,14 @@ check_loadable_libraries(void) FILE *script = NULL; bool found = false; char output_path[MAXPGPATH]; + int len; prep_status("Checking for presence of required libraries"); - snprintf(output_path, sizeof(output_path), "%s/%s", - log_opts.basedir, "loadable_libraries.txt"); + len = snprintf(output_path, sizeof(output_path), "%s/%s", + log_opts.basedir, "loadable_libraries.txt"); + if (len >= sizeof(output_path)) + pg_fatal("directory path for new cluster is too long\n"); /* * Now we want to sort the library names into order. This avoids multiple
signature.asc
Description: PGP signature