shithub: sox

Download patch

ref: 383e012470f4f62436dee6c4a5ef2169329a8ab4
parent: 55a37fc705b5c65ee69084ebd8e39108721a669e
author: Ulrich Klauer <ulrich@chirlu.de>
date: Mon Dec 26 13:51:24 EST 2011

Improve syntax checking for some effects

Always report a syntax error if random characters follow after a time
value that is read with lsx_parsesamples(). A few effects (fade, silence,
synth, trim) didn't check properly; e.g.,
  sox ... trim 10oops
had been accepted (the "oops" being ignored without warning).

--- a/src/fade.c
+++ b/src/fade.c
@@ -48,6 +48,7 @@
     char t_char[2];
     int t_argno;
     size_t samples;
+    const char *n;
   --argc, ++argv;
 
     if (argc < 1 || argc > 4)
@@ -75,7 +76,8 @@
     fade->in_stop_str = lsx_malloc(strlen(argv[0])+1);
     strcpy(fade->in_stop_str,argv[0]);
     /* Do a dummy parse to see if it will fail */
-    if (lsx_parsesamples(0., fade->in_stop_str, &samples, 't') == NULL)
+    n = lsx_parsesamples(0., fade->in_stop_str, &samples, 't');
+    if (!n || *n)
       return lsx_usage(effp);
 
     fade->in_stop = samples;
@@ -90,8 +92,8 @@
             strcpy(fade->out_stop_str,argv[t_argno]);
 
             /* Do a dummy parse to see if it will fail */
-            if (lsx_parsesamples(0., fade->out_stop_str,
-                                &samples, 't') == NULL)
+            n = lsx_parsesamples(0., fade->out_stop_str, &samples, 't');
+            if (!n || *n)
               return lsx_usage(effp);
             fade->out_stop = samples;
         }
@@ -101,8 +103,8 @@
             strcpy(fade->out_start_str,argv[t_argno]);
 
             /* Do a dummy parse to see if it will fail */
-            if (lsx_parsesamples(0., fade->out_start_str,
-                                &samples, 't') == NULL)
+            n = lsx_parsesamples(0., fade->out_start_str, &samples, 't');
+            if (!n || *n)
               return lsx_usage(effp);
             fade->out_start = samples;
         }
--- a/src/silence.c
+++ b/src/silence.c
@@ -80,6 +80,7 @@
 {
     priv_t *   silence = (priv_t *) effp->priv;
     int parse_count;
+    const char *n;
   --argc, ++argv;
 
     /* check for option switches */
@@ -120,8 +121,8 @@
         silence->start_duration_str = lsx_malloc(strlen(argv[0])+1);
         strcpy(silence->start_duration_str,argv[0]);
         /* Perform a fake parse to do error checking */
-        if (lsx_parsesamples(0.,silence->start_duration_str,
-                    &silence->start_duration,'s') == NULL)
+        n = lsx_parsesamples(0.,silence->start_duration_str,&silence->start_duration,'s');
+        if (!n || *n)
           return lsx_usage(effp);
 
         parse_count = sscanf(argv[1], "%lf%c", &silence->start_threshold,
@@ -161,8 +162,8 @@
         silence->stop_duration_str = lsx_malloc(strlen(argv[0])+1);
         strcpy(silence->stop_duration_str,argv[0]);
         /* Perform a fake parse to do error checking */
-        if (lsx_parsesamples(0.,silence->stop_duration_str,
-                    &silence->stop_duration,'s') == NULL)
+        n = lsx_parsesamples(0.,silence->stop_duration_str,&silence->stop_duration,'s');
+        if (!n || *n)
           return lsx_usage(effp);
 
         parse_count = sscanf(argv[1], "%lf%c", &silence->stop_threshold,
--- a/src/synth.c
+++ b/src/synth.c
@@ -287,6 +287,7 @@
   channel_t master, * chan = &master;
   int key = INT_MAX, argn = 0;
   char dummy, * end_ptr;
+  const char *n;
   --argc, ++argv;
 
   if (argc && !strcmp(*argv, "-n")) p->no_headroom = sox_true, ++argv, --argc;
@@ -304,7 +305,8 @@
     p->length_str = lsx_malloc(strlen(argv[argn]) + 1);
     strcpy(p->length_str, argv[argn]);
     /* Do a dummy parse of to see if it will fail */
-    if (lsx_parsesamples(0., p->length_str, &p->samples_to_do, 't') == NULL)
+    n = lsx_parsesamples(0., p->length_str, &p->samples_to_do, 't');
+    if (!n || *n)
       return lsx_usage(effp);
     argn++;
   }
--- a/src/trim.c
+++ b/src/trim.c
@@ -32,6 +32,7 @@
     char *end;
     priv_t * trim = (priv_t *) effp->priv;
     size_t samples;
+    const char *n;
   --argc, ++argv;
 
     /* Do not know sample rate yet so hold off on completely parsing
@@ -47,7 +48,8 @@
             trim->end_str = lsx_malloc(strlen(end)+1);
             strcpy(trim->end_str, end);
             /* Do a dummy parse to see if it will fail */
-            if (lsx_parsesamples(0., trim->end_str, &samples, 't') == NULL)
+            n = lsx_parsesamples(0., trim->end_str, &samples, 't');
+            if (!n || *n)
               return lsx_usage(effp);
             trim->length = samples;
         case 1:
@@ -54,7 +56,8 @@
             trim->start_str = lsx_malloc(strlen(argv[0])+1);
             strcpy(trim->start_str,argv[0]);
             /* Do a dummy parse to see if it will fail */
-            if (lsx_parsesamples(0., trim->start_str, &samples, 't') == NULL)
+            n = lsx_parsesamples(0., trim->start_str, &samples, 't');
+            if (!n || *n)
               return lsx_usage(effp);
             trim->start = samples;
             break;