mirror of
https://github.com/alsa-project/alsa-utils
synced 2024-11-10 03:15:41 +01:00
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>
This commit is contained in:
parent
5a48606d94
commit
2abee9c5b4
2 changed files with 21 additions and 4 deletions
23
bat/bat.c
23
bat/bat.c
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue