]> git.lizzy.rs Git - plan9front.git/commitdiff
devsd: check return value of ifc->enable(), don't leak unit name/user strings
authorcinap_lenrek <cinap_lenrek@felloff.net>
Sun, 26 Mar 2017 14:45:34 +0000 (16:45 +0200)
committercinap_lenrek <cinap_lenrek@felloff.net>
Sun, 26 Mar 2017 14:45:34 +0000 (16:45 +0200)
sys/src/9/port/devsd.c

index 18684b3d770b13bcfbe0402515f1431e17186e51..dd1feeedf46d4f355a3e6e2a1562c9f9d747b122 100644 (file)
@@ -293,30 +293,31 @@ sdgetunit(SDev* sdev, int subno)
                        qunlock(&sdev->unitlock);
                        return nil;
                }
+
                if((unit = malloc(sizeof(SDunit))) == nil){
                        qunlock(&sdev->unitlock);
                        return nil;
                }
                sdev->unitflg[subno] = 1;
-
                snprint(buf, sizeof buf, "%s%x", sdev->name, subno);
                kstrdup(&unit->name, buf);
                kstrdup(&unit->user, eve);
                unit->perm = 0555;
                unit->subno = subno;
                unit->dev = sdev;
-
+       
                if(sdev->enabled == 0 && sdev->ifc->enable)
-                       sdev->ifc->enable(sdev);
-               sdev->enabled = 1;
+                       sdev->enabled = sdev->ifc->enable(sdev);
 
                /*
                 * No need to lock anything here as this is only
                 * called before the unit is made available in the
                 * sdunit[] array.
                 */
-               if(unit->dev->ifc->verify(unit) == 0){
+               if(sdev->enabled == 0 || unit->dev->ifc->verify(unit) == 0){
                        qunlock(&sdev->unitlock);
+                       free(unit->name);
+                       free(unit->user);
                        free(unit);
                        return nil;
                }