summaryrefslogtreecommitdiff
path: root/usr.sbin/btrace/map.c
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2023-08-13 09:48:28 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2023-08-13 09:48:28 +0000
commit629f08239188f31271860d30a7896862efecc33e (patch)
treefd17ca05424ccc7b408247291f44352b13137223 /usr.sbin/btrace/map.c
parent0fd75a66226d20b255e371aeb2f61d077776a60f (diff)
Prevent user-after/double free in map insertion.
Freeing arguments tied to statements is not an option because rules are parsed multiple times. Always make a copy of them if they are assigned to a key in a map.
Diffstat (limited to 'usr.sbin/btrace/map.c')
-rw-r--r--usr.sbin/btrace/map.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/usr.sbin/btrace/map.c b/usr.sbin/btrace/map.c
index be416e226e8..ab773dbd807 100644
--- a/usr.sbin/btrace/map.c
+++ b/usr.sbin/btrace/map.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: map.c,v 1.21 2023/06/27 14:17:00 claudio Exp $ */
+/* $OpenBSD: map.c,v 1.22 2023/08/13 09:48:27 mpi Exp $ */
/*
* Copyright (c) 2020 Martin Pieuchot <mpi@openbsd.org>
@@ -134,10 +134,10 @@ map_insert(struct map *map, const char *key, struct bt_arg *bval,
mep = mget(map, key);
switch (bval->ba_type) {
case B_AT_STR:
- case B_AT_LONG:
free(mep->mval);
- mep->mval = bval;
+ mep->mval = ba_new(ba2str(bval, dtev), B_AT_LONG);
break;
+ case B_AT_LONG:
case B_AT_BI_PID:
case B_AT_BI_TID:
case B_AT_BI_CPU: