]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Fix com_init() in case arguments are given.
authorAndre Noll <maan@systemlinux.org>
Sat, 11 Jul 2009 19:01:27 +0000 (21:01 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 11 Jul 2009 19:01:27 +0000 (21:01 +0200)
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
aft.c
attribute.c
blob.c

diff --git a/afs.c b/afs.c
index 72e2490e671fb4b5898bddea96cc922a1c435c25..ccda7cdaaa4e211b696d4e898f08c7c2520ab3ef 100644 (file)
--- 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 20fa3a96a4ccf1139d6d369ae8ff5764103e7822..00e38d76b65aed7805aca16d363e7a8a92610525 100644 (file)
--- 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;
index 30c12f1ca133a0caa98ac581ca1fc31aaf5c4909..df66c9d08de75f1013d6bc3befbe31bfc8022f8a 100644 (file)
@@ -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 dbabba224ded1d96e8d8175b42181d3221df6e52..92332272970d48bda5fa073cb4acf7c7792415ad 100644 (file)
--- 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;\