[pacman-dev] [PATCH] libalpm: clone data on alpm_db_set_servers
Every alpm_option_set function clones the input so lets be more consistent. Also this fixes servers not being sanatized. --- lib/libalpm/db.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index 8511bb83..6ddf5461 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -139,9 +139,16 @@ alpm_list_t SYMEXPORT *alpm_db_get_servers(const alpm_db_t *db) int SYMEXPORT alpm_db_set_servers(alpm_db_t *db, alpm_list_t *servers) { + alpm_list_t *i; ASSERT(db != NULL, return -1); FREELIST(db->servers); - db->servers = servers; + for(i = servers; i; i = i->next) { + char *url = i->data; + if(alpm_db_add_server(db, url) != 0) { + return -1; + } + servers = servers->next; + } return 0; } -- 2.31.1
On 04/29/21 at 10:12pm, morganamilo wrote:
Every alpm_option_set function clones the input so lets be more consistent. Also this fixes servers not being sanatized. --- lib/libalpm/db.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index 8511bb83..6ddf5461 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -139,9 +139,16 @@ alpm_list_t SYMEXPORT *alpm_db_get_servers(const alpm_db_t *db)
int SYMEXPORT alpm_db_set_servers(alpm_db_t *db, alpm_list_t *servers) { + alpm_list_t *i; ASSERT(db != NULL, return -1); FREELIST(db->servers); - db->servers = servers; + for(i = servers; i; i = i->next) { + char *url = i->data; + if(alpm_db_add_server(db, url) != 0) { + return -1; + } + servers = servers->next;
Does nothing.
+ } return 0; }
--
Every alpm_option_set function clones the input so lets be more consistent. Also this fixes servers not being sanatized. --- v2: fix copy paste error --- lib/libalpm/db.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index 8511bb83..b8d1b157 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -139,9 +139,15 @@ alpm_list_t SYMEXPORT *alpm_db_get_servers(const alpm_db_t *db) int SYMEXPORT alpm_db_set_servers(alpm_db_t *db, alpm_list_t *servers) { + alpm_list_t *i; ASSERT(db != NULL, return -1); FREELIST(db->servers); - db->servers = servers; + for(i = servers; i; i = i->next) { + char *url = i->data; + if(alpm_db_add_server(db, url) != 0) { + return -1; + } + } return 0; } -- 2.31.1
On 30/4/21 5:59 pm, morganamilo wrote:
Every alpm_option_set function clones the input so lets be more consistent. Also this fixes servers not being sanatized.
---
v2: fix copy paste error
Need to update the documentation in alpm.h /** Sets the list of servers for the database to use. * @param db the database to set the servers * @param servers a char* list of servers. Note: the database will * take ownership of the list and it should no longer be * freed by the caller */ int alpm_db_set_servers(alpm_db_t *db, alpm_list_t *servers);
--- lib/libalpm/db.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index 8511bb83..b8d1b157 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -139,9 +139,15 @@ alpm_list_t SYMEXPORT *alpm_db_get_servers(const alpm_db_t *db)
int SYMEXPORT alpm_db_set_servers(alpm_db_t *db, alpm_list_t *servers) { + alpm_list_t *i; ASSERT(db != NULL, return -1); FREELIST(db->servers); - db->servers = servers; + for(i = servers; i; i = i->next) { + char *url = i->data; + if(alpm_db_add_server(db, url) != 0) { + return -1; + } + } return 0; }
participants (3)
-
Allan McRae
-
Andrew Gregory
-
morganamilo