]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - afs.c
Fix a use-after-free bug in para_server.
[paraslash.git] / afs.c
diff --git a/afs.c b/afs.c
index c410854c1129a91a811d21101886276aae731a2e..3d0d2d77c4b24ac712f4ebc4d3bfff058414fb55 100644 (file)
--- a/afs.c
+++ b/afs.c
@@ -684,12 +684,12 @@ static int open_afs_tables(void)
                        continue;
                PARA_ERROR_LOG("%s init: %s\n", afs_tables[i].name,
                        PARA_STRERROR(-ret));
+               break;
        }
        if (ret >= 0)
                return ret;
-       do
-               afs_tables[i].close();
-       while (i--);
+       while (i)
+               afs_tables[--i].close();
        return ret;
 }
 
@@ -709,6 +709,9 @@ static void signal_pre_select(struct sched *s, struct task *t)
 static void signal_post_select(struct sched *s, struct task *t)
 {
        struct signal_task *st = t->private_data;
+       t->ret = -E_AFS_PARENT_DIED;
+       if (getppid() == 1)
+               goto err;
        t->ret = 1;
        if (!FD_ISSET(st->fd, &s->rfds))
                return;
@@ -719,10 +722,14 @@ static void signal_post_select(struct sched *s, struct task *t)
        if (st->signum == SIGHUP) {
                close_afs_tables();
                t->ret = open_afs_tables();
+               /* FIXME: Restore current mood or playlist */
+               if (t->ret < 0)
+                       goto err;
                return;
        }
-       PARA_NOTICE_LOG("caught signal %d\n", st->signum);
        t->ret = -E_AFS_SIGNAL;
+err:
+       PARA_NOTICE_LOG("%s\n", PARA_STRERROR(-t->ret));
        unregister_tasks();
 }