diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2015-07-22 19:15:51 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2015-07-22 19:15:51 +0200 |
commit | 8db5af02d80f906e5bb81db43b010ace1e03f2d1 (patch) | |
tree | 7f77089c987b3f15548e85d07a5c198dc552b194 | |
parent | 47bb311d39f0cdd38067a31b51ec619af7584e56 (diff) |
kernel: make sure the swap device has a reasonable capacity in setswapchan()
-rw-r--r-- | sys/src/9/port/swap.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/sys/src/9/port/swap.c b/sys/src/9/port/swap.c index f2966449b..c5e249732 100644 --- a/sys/src/9/port/swap.c +++ b/sys/src/9/port/swap.c @@ -396,11 +396,13 @@ setswapchan(Chan *c) 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 @@ setswapchan(Chan *c) */ 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 @@ setswapchan(Chan *c) } c->flag &= ~CCACHE; swapimage.c = c; + poperror(); } |