Without these changes, dc can undergo segfaults in a variety of
situations (list of cases that segfault, one for changed line):
1. echo 'e(5)' | bc -lc | dc
2. echo 'la sa sa sa' | dc
3. echo '5p' > a.dc; dc a.dc
---
 dc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/dc.c b/dc.c
index 8017c58..bc5f417 100644
--- a/dc.c
+++ b/dc.c
@@ -1406,6 +1406,7 @@ pop(void)
        v = *stack;
        free(stack);
        stack = v.next;
+       v.next = NULL;
 
        return v;
 }
@@ -2057,6 +2058,7 @@ eval(void)
        case 's':
                rp = lookup(regname());
                freeval(rp->val);
+               rp->val.type = NVAL;
                rp->val = pop();
                break;
        case 'l':
@@ -2169,7 +2171,6 @@ dc(char *fname)
        while (moreinput())
                eval();
 
-       fclose(fp);
        free(input);
        input = NULL;
 }
-- 
2.52.0


Reply via email to