Fix kernel panic on NULL pointer deref w/ certain ktrace commands, allow -c -f.
authorMatthew Dillon <dillon@apollo.backplane.com>
Thu, 12 Mar 2009 16:15:10 +0000 (09:15 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Thu, 12 Mar 2009 16:15:10 +0000 (09:15 -0700)
Fix a kernel panic on a NULL pointer dereference with certain ktrace -c
commands.

Allow the -c -f <file> combination (taken from FreeBSD).

Submitted-by: Stathis Kamperis <beket>
sys/kern/kern_ktrace.c
usr.bin/ktrace/ktrace.c

index 4ba27e6..f26cf46 100644 (file)
@@ -338,18 +338,20 @@ ktrace_clear_callback(struct proc *p, void *data)
 {
        struct ktrace_clear_info *info = data;
 
-       if (info->rootclear) {
-               if (p->p_tracenode == info->tracenode) {
-                       ktrdestroy(&p->p_tracenode);
-                       p->p_traceflag = 0;
-               }
-       } else {
-               if (p->p_tracenode->kn_vp == info->tracenode->kn_vp) {
-                       if (ktrcanset(curproc, p)) {
+       if (p->p_tracenode) {
+               if (info->rootclear) {
+                       if (p->p_tracenode == info->tracenode) {
                                ktrdestroy(&p->p_tracenode);
                                p->p_traceflag = 0;
-                       } else {
-                               info->error = EPERM;
+                       }
+               } else {
+                       if (p->p_tracenode->kn_vp == info->tracenode->kn_vp) {
+                               if (ktrcanset(curproc, p)) {
+                                       ktrdestroy(&p->p_tracenode);
+                                       p->p_traceflag = 0;
+                               } else {
+                                       info->error = EPERM;
+                               }
                        }
                }
        }
index bfc2eb9..261d4fb 100644 (file)
@@ -110,7 +110,7 @@ main(int argc, char **argv)
        argv += optind;
        argc -= optind;
        
-       if ((pidset && *argv) || (!pidset && !*argv))
+       if ((pidset && *argv) || (!pidset && clear == NOTSET && !*argv))
                usage();
                        
        if (inherit)