From 943cf10a0c3072bc2e0d3c49e53856c2a1d271b6 Mon Sep 17 00:00:00 2001 From: motodiary Date: Tue, 28 May 2024 09:48:46 +0800 Subject: [PATCH] fix some error,add pgsql_escape_str function --- ...-error-add-pgsql_escape_str-function.patch | 160 ++++++++++++++++++ slurm.spec | 6 +- 2 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 0031-fix-some-error-add-pgsql_escape_str-function.patch diff --git a/0031-fix-some-error-add-pgsql_escape_str-function.patch b/0031-fix-some-error-add-pgsql_escape_str-function.patch new file mode 100644 index 0000000..9e626b1 --- /dev/null +++ b/0031-fix-some-error-add-pgsql_escape_str-function.patch @@ -0,0 +1,160 @@ +From 4b8ba870c5812906721849f6fa7d40289ab2762d Mon Sep 17 00:00:00 2001 +From: motodiary +Date: Tue, 28 May 2024 09:46:30 +0800 +Subject: [PATCH] fix some error,add pgsql_escape_str function + +--- + src/database/pgsql_common.c | 28 +++++++++++++++++-- + src/database/pgsql_common.h | 1 + + .../pgsql/accounting_storage_pgsql.c | 6 ++-- + .../accounting_storage/pgsql/as_pgsql_assoc.c | 12 ++++---- + .../pgsql/as_pgsql_cluster.c | 2 +- + 5 files changed, 37 insertions(+), 12 deletions(-) + +diff --git a/src/database/pgsql_common.c b/src/database/pgsql_common.c +index c2f29d6..03d2bf0 100755 +--- a/src/database/pgsql_common.c ++++ b/src/database/pgsql_common.c +@@ -81,6 +81,28 @@ extern char *pgsql_handle_quotes(char *str) + return copy; + } + ++extern char *pgsql_escape_str(char *str) ++{ ++ debug4("%s org str %s", __func__, str); ++ char *dup, *copy = NULL; ++ int len = 0; ++ if (!str || !(len = strlen(str))) { ++ return NULL; ++ } ++ ++ /* make a buffer 2 times the size just to be safe */ ++ copy = dup = xmalloc((2 * len) + 1); ++ if (copy) ++ do { ++ if (*str == '\'') { ++ *dup++ = '\''; ++ } ++ } while ((*dup++ = *str++)); ++ debug4("%s result str %s", __func__, copy); ++ ++ return copy; ++} ++ + static void _pgsql_remove_quotes(char* str) { + int len = 0; + if (!str || !(len = strlen(str))) { +@@ -1561,8 +1583,10 @@ extern void pgsql_free_result(pgsql_res_t** result_ptr) + if(result->rows!=NULL && result->sNumCols>0 && result->sNumRows>0){ + for(int i=0; isNumRows; i++){ + for(int j=0; jsNumCols; j++){ +- xfree(result->rows[i][j]); +- result->rows[i][j] = NULL; ++ if (result->rows[i]) { ++ xfree(result->rows[i][j]); ++ result->rows[i][j] = NULL; ++ } + } + if(result->rows[i]){ + free(result->rows[i]); +diff --git a/src/database/pgsql_common.h b/src/database/pgsql_common.h +index f828fe7..f8360ed 100755 +--- a/src/database/pgsql_common.h ++++ b/src/database/pgsql_common.h +@@ -142,6 +142,7 @@ typedef struct { + } while (0) + + extern char *pgsql_handle_quotes(char *str); ++extern char *pgsql_escape_str(char *str); + + extern pgsql_conn_t *create_pgsql_conn(int conn_num, bool rollback, + char *cluster_name); +diff --git a/src/plugins/accounting_storage/pgsql/accounting_storage_pgsql.c b/src/plugins/accounting_storage/pgsql/accounting_storage_pgsql.c +index e079226..1d4a2bb 100755 +--- a/src/plugins/accounting_storage/pgsql/accounting_storage_pgsql.c ++++ b/src/plugins/accounting_storage/pgsql/accounting_storage_pgsql.c +@@ -272,12 +272,12 @@ static bool _check_jobs_before_remove(pgsql_conn_t *pgsql_conn, + query = xstrdup_printf( + "select distinct %s " + "from %s_%s as t0 " ++ "JOIN %s_%s as t2 ON t0.id_assoc=t2.id_assoc " + "JOIN %s_%s as t1 ON t1.lft between t2.lft and t2.rgt AND (%s) " +- "JOIN %s_%s as t2 ON t0.id_assoc=t1.id_assoc " + "where t0.time_end=0 AND t0.state<%d;", + object, cluster_name, job_table, + cluster_name, assoc_table, +- assoc_char, cluster_name, assoc_table, ++ cluster_name, assoc_table, assoc_char, + JOB_COMPLETE); + + xfree(object); +@@ -2245,7 +2245,7 @@ extern int remove_common(pgsql_conn_t *pgsql_conn, + while ((row = pgsql_fetch_row(result))) { + slurmdb_assoc_rec_t *rem_assoc = NULL; + if (loc_assoc_char) +- xstrcat(loc_assoc_char, " || "); ++ xstrcat(loc_assoc_char, " OR "); + xstrfmtcat(loc_assoc_char, "id_assoc=%s", row[0]); + + rem_assoc = xmalloc(sizeof(slurmdb_assoc_rec_t)); +diff --git a/src/plugins/accounting_storage/pgsql/as_pgsql_assoc.c b/src/plugins/accounting_storage/pgsql/as_pgsql_assoc.c +index c92c07c..1f98dd5 100755 +--- a/src/plugins/accounting_storage/pgsql/as_pgsql_assoc.c ++++ b/src/plugins/accounting_storage/pgsql/as_pgsql_assoc.c +@@ -2630,7 +2630,7 @@ extern int as_pgsql_add_assocs(pgsql_conn_t *pgsql_conn, uint32_t uid, + xstrcat(cols, ", \"user\""); + xstrfmtcat(vals, ", '%s'", object->user); + xstrfmtcat(update, " AND \"user\"='%s'", object->user); +- xstrfmtcat(extra, ", user='%s'", object->user); // it in a string, don't add quotes ++ xstrfmtcat(extra, ", \"user\"='%s'", object->user); + + /* We need to give a partition whether it be + * '' or the actual partition name given +@@ -2640,7 +2640,7 @@ extern int as_pgsql_add_assocs(pgsql_conn_t *pgsql_conn, uint32_t uid, + xstrcat(cols, ", \"partition\""); + xstrfmtcat(vals, ", '%s'", part); + xstrfmtcat(update, " AND \"partition\"='%s'", part); +- xstrfmtcat(extra, ", partition='%s'", part); // it in a string, don't add quotes ++ xstrfmtcat(extra, ", \"partition\"='%s'", part); + if (!added_user_list) + added_user_list = list_create(NULL); + if (!list_find_first(added_user_list, +@@ -2853,10 +2853,10 @@ extern int as_pgsql_add_assocs(pgsql_conn_t *pgsql_conn, uint32_t uid, + } + + xstrfmtcat(query, +- "update \"%s_%s\" set deleted=0, " ++ "update \"%s_%s\" set deleted=0" + //"id_assoc=LAST_INSERT_ID(id_assoc)%s %s;", +- "id_assoc = currval(pg_get_serial_sequence('%s_%s', 'id_assoc')) %s %s;", +- object->cluster, assoc_table, object->cluster, assoc_table, ++ " %s %s;", ++ object->cluster, assoc_table, + extra, update); + } + pgsql_free_result(&result); +@@ -2926,7 +2926,7 @@ extern int as_pgsql_add_assocs(pgsql_conn_t *pgsql_conn, uint32_t uid, + + if (xstrcmp(object->cluster, tmp_cluster_name)) { + /* we always have a ', ' as the first 2 chars */ +- tmp_extra = pgsql_handle_quotes(extra+2); ++ tmp_extra = pgsql_escape_str(extra+2); + if (txn_query) + xstrfmtcat(txn_query, + ", (%ld, %d, 'id_assoc=%d', " +diff --git a/src/plugins/accounting_storage/pgsql/as_pgsql_cluster.c b/src/plugins/accounting_storage/pgsql/as_pgsql_cluster.c +index 971ec31..adc7601 100755 +--- a/src/plugins/accounting_storage/pgsql/as_pgsql_cluster.c ++++ b/src/plugins/accounting_storage/pgsql/as_pgsql_cluster.c +@@ -366,7 +366,7 @@ extern int as_pgsql_add_clusters(pgsql_conn_t *pgsql_conn, uint32_t uid, + xstrfmtcat(query, + "INSERT INTO \"%s_%s\" (%s, lft, rgt) " + "VALUES (%s, 1, 2) " +- "ON CONFLICT (id_assoc) DO UPDATE SET deleted=0, " ++ "ON CONFLICT (\"user\", acct, \"partition\") DO UPDATE SET deleted=0, " + "id_assoc=currval(pg_get_serial_sequence('%s_%s', 'id_assoc'))%s;", + object->name, assoc_table, cols, vals, object->name, assoc_table, extra); + xfree(cols); +-- +2.33.0 + diff --git a/slurm.spec b/slurm.spec index 08c474e..b6dab7c 100644 --- a/slurm.spec +++ b/slurm.spec @@ -1,6 +1,6 @@ Name: slurm Version: 21.08.8 -%define rel 33 +%define rel 34 Release: %{rel}%{?dist} Summary: Slurm Workload Manager @@ -46,6 +46,7 @@ Patch27: 0027-Adjusting-procedures.patch Patch28: 0028-modify-the-field-type-of-info-in-txn_table.patch Patch29: 0029-add-partition-default-value-in-job_table.patch Patch30: 0030-Modify-the-alias-after-EXCLUDED-in-SQL-to-field-name.patch +Patch31: 0031-fix-some-error-add-pgsql_escape_str-function.patch # build options .rpmmacros options change to default action # ==================== ==================== ======================== @@ -738,6 +739,9 @@ rm -rf %{buildroot} %systemd_postun_with_restart slurmdbd.service %changelog +* Tue May 28 2024 Xing Liu - 21.08.8-34 +- fix some error,add pgsql_escape_str function + * Mon May 27 2024 Xing Liu - 21.08.8-33 - Modify the alias after EXCLUDED in SQL to field name -- Gitee