]> git.alsa-project.org Git - alsa-utils.git/commitdiff
BAT: Use dynamic temp file
authorLu, Han <han.lu@intel.com>
Tue, 20 Oct 2015 08:45:48 +0000 (16:45 +0800)
committerTakashi Iwai <tiwai@suse.de>
Tue, 20 Oct 2015 09:06:24 +0000 (11:06 +0200)
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>
bat/bat.c
bat/common.h

index de32a6dc6a327e43cd3f96b2322cf2e60ecf933a..56cfaf6ffecc4b9e2649d8946f5010402e14472e 100644 (file)
--- a/bat/bat.c
+++ b/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;
 }
index e6ff7f1d246eb39c27056b0297141f384dfdc933..c04452db70b0f8ea3079ac71969844bc30c976cc 100644 (file)
@@ -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)