summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2015-08-01 20:12:34 +0000
committerguenther <guenther@openbsd.org>2015-08-01 20:12:34 +0000
commitdd911d11fb704dfeead7b6fad59ae67d4d6a7b0f (patch)
tree6f2146777e6d52f85e0b9ba8dfc28cbc0d65e1a3
parentFix a potential out-of-bounds read found via address-sanitizer while (diff)
downloadwireguard-openbsd-dd911d11fb704dfeead7b6fad59ae67d4d6a7b0f.tar.xz
wireguard-openbsd-dd911d11fb704dfeead7b6fad59ae67d4d6a7b0f.zip
Fix free() of uninitialized variable introduced in previous commit.
Eliminate the goto that I tripped on. problem noted by Mark Latimer (mark.latimer (at) gmail.com) ok miod@ millert@
-rw-r--r--sys/kern/kern_ktrace.c28
1 files changed, 12 insertions, 16 deletions
diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c
index 2e839f66e6a..aedc96f77fc 100644
--- a/sys/kern/kern_ktrace.c
+++ b/sys/kern/kern_ktrace.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_ktrace.c,v 1.74 2015/07/19 04:45:25 guenther Exp $ */
+/* $OpenBSD: kern_ktrace.c,v 1.75 2015/08/01 20:12:34 guenther Exp $ */
/* $NetBSD: kern_ktrace.c,v 1.23 1996/02/09 18:59:36 christos Exp $ */
/*
@@ -361,21 +361,17 @@ ktruser(struct proc *p, const char *id, const void *addr, size_t len)
ktrinitheader(&kth, p, KTR_USER);
memset(ktp.ktr_id, 0, KTR_USER_MAXIDLEN);
error = copyinstr(id, ktp.ktr_id, KTR_USER_MAXIDLEN, NULL);
- if (error)
- goto out;
-
- if (len > sizeof(stkbuf))
- memp = malloc(len, M_TEMP, M_WAITOK);
- else
- memp = stkbuf;
- error = copyin(addr, memp, len);
- if (error)
- goto out;
-
- ktrwrite2(p, &kth, &ktp, sizeof(ktp), memp, len);
-out:
- if (memp != stkbuf)
- free(memp, M_TEMP, len);
+ if (error == 0) {
+ if (len > sizeof(stkbuf))
+ memp = malloc(len, M_TEMP, M_WAITOK);
+ else
+ memp = stkbuf;
+ error = copyin(addr, memp, len);
+ if (error == 0)
+ ktrwrite2(p, &kth, &ktp, sizeof(ktp), memp, len);
+ if (memp != stkbuf)
+ free(memp, M_TEMP, len);
+ }
atomic_clearbits_int(&p->p_flag, P_INKTR);
return (error);
}