From 133cbbe403c850da3efdaa6dcfc0cf55145d0aa2 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sat, 11 Jul 2009 21:01:27 +0200 Subject: [PATCH] Fix com_init() in case arguments are given. As the ->name field of struct afs_table was only initialized in the afs process, com_init(), which gets forked from the server process, did not see the table names and would segfault due to a NULL pointer dereference if table names were given as arguments. Fix it by initializing the ->name fields in the definition of the afs_tables array. This bug was introduced in commit 53d503ce back in 2007... --- afs.c | 28 ++++++++++++++-------------- aft.c | 1 - attribute.c | 1 - blob.c | 1 - 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/afs.c b/afs.c index 72e2490e..ccda7cda 100644 --- a/afs.c +++ b/afs.c @@ -54,13 +54,13 @@ enum afs_table_num { }; static struct afs_table afs_tables[NUM_AFS_TABLES] = { - [TBLNUM_AUDIO_FILES] = {.init = aft_init}, - [TBLNUM_ATTRIBUTES] = {.init = attribute_init}, - [TBLNUM_SCORES] = {.init = score_init}, - [TBLNUM_MOODS] = {.init = moods_init}, - [TBLNUM_LYRICS] = {.init = lyrics_init}, - [TBLNUM_IMAGES] = {.init = images_init}, - [TBLNUM_PLAYLIST] = {.init = playlists_init}, + [TBLNUM_AUDIO_FILES] = {.init = aft_init, .name = "audio_files"}, + [TBLNUM_ATTRIBUTES] = {.init = attribute_init, .name = "attributes"}, + [TBLNUM_SCORES] = {.init = score_init, .name = "scores"}, + [TBLNUM_MOODS] = {.init = moods_init, .name = "moods"}, + [TBLNUM_LYRICS] = {.init = lyrics_init, .name = "lyrics"}, + [TBLNUM_IMAGES] = {.init = images_init, .name = "images"}, + [TBLNUM_PLAYLIST] = {.init = playlists_init, .name = "playlists"}, }; struct command_task { @@ -1072,7 +1072,7 @@ static void create_tables_callback(int fd, const struct osl_object *query) { uint32_t table_mask = *(uint32_t *)query->data; int i, ret; - char *buf; + struct para_buffer pb = {.buf = NULL}; close_afs_tables(); for (i = 0; i < NUM_AFS_TABLES; i++) { @@ -1085,15 +1085,15 @@ static void create_tables_callback(int fd, const struct osl_object *query) ret = t->create(database_dir); if (ret < 0) goto out; + para_printf(&pb, "successfully created %s table\n", t->name); } ret = open_afs_tables(); out: - if (ret >= 0) - buf = make_message("successfully created afs table(s)\n"); - else - buf = make_message("%s\n", para_strerror(-ret)); - pass_buffer_as_shm(buf, strlen(buf), &fd); - free(buf); + if (ret < 0) + para_printf(&pb, "%s\n", para_strerror(-ret)); + if (pb.buf) + pass_buffer_as_shm(pb.buf, pb.offset, &fd); + free(pb.buf); } int com_init(int fd, int argc, char * const * const argv) diff --git a/aft.c b/aft.c index 20fa3a96..00e38d76 100644 --- a/aft.c +++ b/aft.c @@ -2619,7 +2619,6 @@ static int aft_event_handler(enum afs_events event, struct para_buffer *pb, void aft_init(struct afs_table *t) { - t->name = audio_file_table_desc.name; t->open = aft_open; t->close = aft_close; t->create = aft_create; diff --git a/attribute.c b/attribute.c index 30c12f1c..df66c9d0 100644 --- a/attribute.c +++ b/attribute.c @@ -604,7 +604,6 @@ static int attribute_create(const char *dir) */ void attribute_init(struct afs_table *t) { - t->name = attribute_table_desc.name; t->open = attribute_open; t->close = attribute_close; t->create = attribute_create; diff --git a/blob.c b/blob.c index dbabba22..92332272 100644 --- a/blob.c +++ b/blob.c @@ -518,7 +518,6 @@ static int blob_open(struct osl_table **table, #define DEFINE_BLOB_INIT(table_name) \ void table_name ## _init(struct afs_table *t) \ { \ - t->name = table_name ## _table_desc.name; \ t->open = table_name ## _open; \ t->close = table_name ## _close; \ t->create = table_name ## _create;\ -- 2.39.5