ref: 9901fd6c4799ae204e3d395348b03cec488b9a82
parent: cc2776de8d2bb45ca1727f84f74d4517947585c9
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Wed Jul 22 15:15:51 EDT 2015
kernel: make sure the swap device has a reasonable capacity in setswapchan()
--- a/sys/src/9/port/swap.c
+++ b/sys/src/9/port/swap.c
@@ -396,11 +396,13 @@
Dir d;
int n;
+ if(waserror()){+ cclose(c);
+ nexterror();
+ }
if(swapimage.c != nil) {- if(swapalloc.free != conf.nswap){- cclose(c);
+ if(swapalloc.free != conf.nswap)
error(Einuse);
- }
cclose(swapimage.c);
swapimage.c = nil;
}
@@ -411,11 +413,10 @@
*/
if(devtab[c->type]->dc != L'M'){n = devtab[c->type]->stat(c, dirbuf, sizeof dirbuf);
- if(n <= 0){- cclose(c);
+ if(n <= 0 || convM2D(dirbuf, n, &d, nil) == 0)
error("stat failed in setswapchan");- }
- convM2D(dirbuf, n, &d, nil);
+ if(d.length < conf.nswppo*BY2PG)
+ error("swap device too small"); if(d.length < conf.nswap*BY2PG){conf.nswap = d.length/BY2PG;
swapalloc.top = &swapalloc.swmap[conf.nswap];
@@ -424,4 +425,5 @@
}
c->flag &= ~CCACHE;
swapimage.c = c;
+ poperror();
}
--
⑨