Welcome to little lamb

Code » anopa » commit 191a888

Fix possible segfault

author Olivier Brunel
2018-02-25 22:59:32 UTC
committer Olivier Brunel
2018-02-25 22:59:32 UTC
parent 5d4d196e12f086abbfd1ae1fac764f2a85dd86e5

Fix possible segfault

If a service were to end and its fd_progress was closed whilst a password
input was in progress, we would close_fd_for() it before calling
end_si_password(), which would then try to work with a reset struct
progress.

So make sure when we close the fd_progress for the si_password, we call
end_si_password() to properly end things.

src/anopa/start-stop.c +16 -9

diff --git a/src/anopa/start-stop.c b/src/anopa/start-stop.c
index c1aa1c6..691dd1b 100644
--- a/src/anopa/start-stop.c
+++ b/src/anopa/start-stop.c
@@ -373,6 +373,8 @@ remove_fd_from_iop (int fd)
         }
 }
 
+static void end_si_password (void);
+
 void
 close_fd_for (int fd, int si)
 {
@@ -402,15 +404,20 @@ close_fd_for (int fd, int si)
         {
             if (aa_service (si)->pi >= 0)
             {
-                struct progress *pg;
-
-                pg = &genalloc_s (struct progress, &ga_progress)[aa_service (si)->pi];
-                if (pg->is_drawn)
-                    clear_draw ();
-                pg->si = -1;
-                pg->is_drawn = 0;
-                pg->aa_pg.sa.len = 0;
-                aa_service (si)->pi = -1;
+                if (si_password == si)
+                    end_si_password ();
+                else
+                {
+                    struct progress *pg;
+
+                    pg = &genalloc_s (struct progress, &ga_progress)[aa_service (si)->pi];
+                    if (pg->is_drawn)
+                        clear_draw ();
+                    pg->si = -1;
+                    pg->is_drawn = 0;
+                    pg->aa_pg.sa.len = 0;
+                    aa_service (si)->pi = -1;
+                }
             }
             aa_service (si)->fd_progress = -1;
         }