aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew J. Schorr <aschorr@telemetry-investments.com>2017-11-25 13:33:00 -0500
committerAndrew J. Schorr <aschorr@telemetry-investments.com>2017-11-25 13:33:00 -0500
commit6f3e075b3ad1e6cd5b3268fce65c768340b00a5b (patch)
treed9da26f73ba60392074c49dd907c9ceff17676e1
parent03caf83ac9d2862ca72daa5d18f2af27d68db1d4 (diff)
downloadegawk-6f3e075b3ad1e6cd5b3268fce65c768340b00a5b.tar.gz
egawk-6f3e075b3ad1e6cd5b3268fce65c768340b00a5b.tar.bz2
egawk-6f3e075b3ad1e6cd5b3268fce65c768340b00a5b.zip
Fix potential field corruption when $0 is set from the debugger.
-rw-r--r--ChangeLog6
-rw-r--r--debug.c5
2 files changed, 9 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 3ab99ab4..3255d8e8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-11-25 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * debug.c (do_set_var): As in interpret.h (Op_store_field), we should
+ call the assign function before unref to give it a chance to copy
+ any non-malloced $n string values before freeing $0.
+
2017-11-14 Andrew J. Schorr <aschorr@telemetry-investments.com>
* mpfr.c (get_rnd_mode): Fix MPFR_RNDA comment.
diff --git a/debug.c b/debug.c
index 9a022669..3e76ae61 100644
--- a/debug.c
+++ b/debug.c
@@ -1299,10 +1299,11 @@ do_set_var(CMDARG *arg, int cmd ATTRIBUTE_UNUSED)
arg = arg->next;
val = arg->a_node;
lhs = get_field(field_num, &assign);
- unref(*lhs);
- *lhs = dupnode(val);
if (assign)
+ /* call assign to copy fields before unref frees $0 */
assign();
+ unref(*lhs);
+ *lhs = dupnode(val);
print_field(field_num);
}
break;