summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Ratchov <ratchov@cvs.openbsd.org>2012-11-02 11:08:33 +0000
committerAlexandre Ratchov <ratchov@cvs.openbsd.org>2012-11-02 11:08:33 +0000
commited6bbb6e94a52bd5426d7592a9be357c204e0de5 (patch)
treec177baec413462f19e15cfd86cb30ac81d34adb4
parentfb533b779e3fecc5418fedc3e2d127f9e7e6390b (diff)
Initialize wav structure enough for wav_close() to work in the error
code path. Fixes crashes when wav_close() is called on uninitialized wav structure. With help from Remco <remco at d-compu.dyndns.org>, thanks!
-rw-r--r--usr.bin/aucat/wav.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/usr.bin/aucat/wav.c b/usr.bin/aucat/wav.c
index 97044f6f44e..0534c6913cd 100644
--- a/usr.bin/aucat/wav.c
+++ b/usr.bin/aucat/wav.c
@@ -796,7 +796,11 @@ wav_new_in(struct fileops *ops, struct dev *dev,
close(fd);
return NULL;
}
+ f->mode = mode;
f->pstate = WAV_CFG;
+ f->endpos = f->startpos = 0;
+ f->next = wav_list;
+ wav_list = f;
if (hdr == HDR_WAV) {
if (!wav_readhdr(f->pipe.fd, par,
&f->startpos, &f->rbytes, &f->map)) {
@@ -805,7 +809,6 @@ wav_new_in(struct fileops *ops, struct dev *dev,
}
f->endpos = f->startpos + f->rbytes;
} else {
- f->startpos = 0;
f->endpos = pipe_endpos(&f->pipe.file);
if (f->endpos > 0) {
if (!pipe_seek(&f->pipe.file, 0)) {
@@ -846,8 +849,6 @@ wav_new_in(struct fileops *ops, struct dev *dev,
dbg_puts("\n");
}
#endif
- f->next = wav_list;
- wav_list = f;
return f;
}
@@ -881,7 +882,11 @@ wav_new_out(struct fileops *ops, struct dev *dev,
close(fd);
return NULL;
}
+ f->mode = mode;
f->pstate = WAV_CFG;
+ f->endpos = f->startpos = 0;
+ f->next = wav_list;
+ wav_list = f;
if (hdr == HDR_WAV) {
par->le = 1;
par->sig = (par->bits <= 8) ? 0 : 1;
@@ -892,14 +897,11 @@ wav_new_out(struct fileops *ops, struct dev *dev,
}
f->wbytes = WAV_DATAMAX;
f->endpos = f->startpos;
- } else {
+ } else
f->wbytes = -1;
- f->startpos = f->endpos = 0;
- }
f->dev = dev;
f->mmc = mmc;
f->join = join;
- f->mode = mode;
f->hpar = *par;
f->hdr = hdr;
f->xrun = xrun;