Module Name: src Committed By: riastradh Date: Tue Jun 1 21:08:48 UTC 2021
Modified Files: src/usr.bin/audio/record: record.c Log Message: audiorecord(1): Handle read(2) return value gracefully. To generate a diff of this commit: cvs rdiff -u -r1.54 -r1.55 src/usr.bin/audio/record/record.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/audio/record/record.c diff -u src/usr.bin/audio/record/record.c:1.54 src/usr.bin/audio/record/record.c:1.55 --- src/usr.bin/audio/record/record.c:1.54 Wed Aug 5 06:54:39 2015 +++ src/usr.bin/audio/record/record.c Tue Jun 1 21:08:48 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: record.c,v 1.54 2015/08/05 06:54:39 mrg Exp $ */ +/* $NetBSD: record.c,v 1.55 2021/06/01 21:08:48 riastradh Exp $ */ /* * Copyright (c) 1999, 2002, 2003, 2005, 2010 Matthew R. Green @@ -32,7 +32,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: record.c,v 1.54 2015/08/05 06:54:39 mrg Exp $"); +__RCSID("$NetBSD: record.c,v 1.55 2021/06/01 21:08:48 riastradh Exp $"); #endif @@ -81,6 +81,7 @@ main(int argc, char *argv[]) { u_char *buffer; size_t len, bufsize = 0; + ssize_t nread; int ch, no_time_limit = 1; const char *defdevice = _PATH_SOUND; @@ -337,8 +338,12 @@ main(int argc, char *argv[]) (void)gettimeofday(&start_time, NULL); while (no_time_limit || timeleft(&start_time, &record_time)) { - if ((size_t)read(audiofd, buffer, bufsize) != bufsize) + if ((nread = read(audiofd, buffer, bufsize)) == -1) err(1, "read failed"); + if (nread == 0) + errx(1, "read eof"); + if ((size_t)nread != bufsize) + errx(1, "invalid read"); if (conv_func) (*conv_func)(buffer, bufsize); if ((size_t)write(ti.outfd, buffer, bufsize) != bufsize)