diff options
author | Lu, Han <han.lu@intel.com> | 2015-10-20 16:45:48 +0800 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2015-10-20 11:06:24 +0200 |
commit | 2abee9c5b40977073ca02ce963f97c991f24708c (patch) | |
tree | 2582e266890f30ed7b8af1bd4f5f5eb55e637901 | |
parent | 5a48606d940c9676309b766592f84fb64e1da73d (diff) | |
download | alsa-utils-2abee9c5b40977073ca02ce963f97c991f24708c.tar.gz |
BAT: Use dynamic temp file
Use dynamic temp file instead of fixed temp file to store recorded
wav data, for better security.
Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r-- | bat/bat.c | 23 | ||||
-rw-r--r-- | bat/common.h | 2 |
2 files changed, 21 insertions, 4 deletions
@@ -450,6 +450,7 @@ static int validate_options(struct bat *bat) static int bat_init(struct bat *bat) { int err = 0; + char name[] = TEMP_RECORD_FILE_NAME; /* Determine logging to a file or stdout and stderr */ if (bat->logarg) { @@ -472,10 +473,23 @@ static int bat_init(struct bat *bat) } /* Determine capture file */ - if (bat->local) + if (bat->local) { bat->capture.file = bat->playback.file; - else - bat->capture.file = TEMP_RECORD_FILE_NAME; + } else { + /* create temp file for sound record and analysis */ + err = mkstemp(name); + if (err == -1) { + fprintf(bat->err, _("Fail to create record file: %d\n"), + -errno); + return -errno; + } + /* store file name which is dynamically created */ + bat->capture.file = strdup(name); + if (bat->capture.file == NULL) + return -errno; + /* close temp file */ + close(err); + } /* Initial for playback */ if (bat->playback.file == NULL) { @@ -585,8 +599,11 @@ analyze: err = analyze_capture(&bat); out: fprintf(bat.log, _("\nReturn value is %d\n"), err); + if (bat.logarg) fclose(bat.log); + if (!bat.local) + free(bat.capture.file); return err; } diff --git a/bat/common.h b/bat/common.h index e6ff7f1..c04452d 100644 --- a/bat/common.h +++ b/bat/common.h @@ -15,7 +15,7 @@ #include <alsa/asoundlib.h> -#define TEMP_RECORD_FILE_NAME "/tmp/bat.wav" +#define TEMP_RECORD_FILE_NAME "/tmp/bat.wav.XXXXXX" #define OPT_BASE 300 #define OPT_LOG (OPT_BASE + 1) |