summaryrefslogtreecommitdiff
path: root/usr/src/cmd/audio
diff options
context:
space:
mode:
authorGarrett D'Amore <gdamore@opensolaris.org>2009-05-07 21:11:42 -0700
committerGarrett D'Amore <gdamore@opensolaris.org>2009-05-07 21:11:42 -0700
commit4ed98f3fa765891f0c6f97beb9a86d42084747d5 (patch)
tree73c3ae158b6f51713dcbb2521f3e3978c8322499 /usr/src/cmd/audio
parent82da96e4b18feec270e35a541758d6ad236566b6 (diff)
downloadillumos-joyent-4ed98f3fa765891f0c6f97beb9a86d42084747d5.tar.gz
6837441 mixerctl incorrectly checks return value from open()
Diffstat (limited to 'usr/src/cmd/audio')
-rw-r--r--usr/src/cmd/audio/mixerctl/mixerctl.c26
1 files changed, 9 insertions, 17 deletions
diff --git a/usr/src/cmd/audio/mixerctl/mixerctl.c b/usr/src/cmd/audio/mixerctl/mixerctl.c
index 2449003649..ae57ac0eee 100644
--- a/usr/src/cmd/audio/mixerctl/mixerctl.c
+++ b/usr/src/cmd/audio/mixerctl/mixerctl.c
@@ -33,7 +33,6 @@
#include <stdarg.h>
#include <stddef.h>
#include <sys/types.h>
-#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <ctype.h>
@@ -731,22 +730,11 @@ mixers_save(mlist_t *mlistp, char *sstr, int ovopt, int vopt)
FILE *sfp;
int fp;
int retval;
- struct stat sbuf;
+ int mode;
- if (stat(sstr, &sbuf) == 0) {
- if (!ovopt) {
- warn(_("Would over write existing file [%s]\n"), sstr);
- return (EINVAL);
- } else {
- if (unlink(sstr)) {
- retval = errno;
- perror(_("Failed to unlink existing file"));
- return (retval);
- }
- }
- }
+ mode = O_WRONLY | O_CREAT | (ovopt ? O_TRUNC : O_EXCL);
- if ((fp = open(sstr, O_WRONLY|O_CREAT|O_EXCL, 0666)) == 0) {
+ if ((fp = open(sstr, mode, 0666)) < 0) {
retval = errno;
perror(_("Failed to create file"));
return (retval);
@@ -1127,8 +1115,12 @@ main(int argc, char **argv)
} else if ((strcmp(dstr, "/dev/audio") == 0) ||
(strcmp(dstr, "/dev/audioctl") == 0) ||
(strcmp(dstr, "/dev/dsp") == 0)) {
- /* "default" device, read the link */
- if (readlink(dstr, scratch, sizeof (scratch)) >= 0) {
+ /*
+ * "default" device, read the link,
+ * ensuring NULL termination.
+ */
+ if (readlink(dstr, scratch, MAXPATHLEN) >= 0) {
+ scratch[MAXPATHLEN] = 0;
if ((s = strchr(scratch, '/')) != NULL) {
num = atoi(s + 1);
}