Fixed crash on FLIP vs. invalid variable names.
authorJohn Darrington <john@darrington.wattle.id.au>
Wed, 6 Apr 2016 07:38:56 +0000 (09:38 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Wed, 6 Apr 2016 07:38:56 +0000 (09:38 +0200)
FLIP would crash if the designated new names were not
valid names.  For example "TO", "BY", "" etc.

Found by zzuf.

src/language/stats/flip.c
tests/language/stats/flip.at

index 9d3b0a6346cb460484e64286f840647eddef154d..7c28d3a1da0007fe1da2a54c1dd03d221b39f5a9 100644 (file)
@@ -271,9 +271,15 @@ make_new_var (struct dictionary *dict, const char *name_)
       }
   *cp = '\0';
 
+  if (strlen (name) == 0)
+    {
+      free (name);
+      name = xstrdup ("v");
+    }
+
   /* Use the mangled name, if it is available, or add numeric
      extensions until we find one that is. */
-  if (!dict_create_var (dict, name, 0))
+  if (!id_is_plausible (name, false) || !dict_create_var (dict, name, 0))
     {
       int len = strlen (name);
       int i;
@@ -284,7 +290,7 @@ make_new_var (struct dictionary *dict, const char *name_)
           strncpy (n, name, ofs);
           sprintf (&n[ofs], "%d", i);
 
-          if (dict_create_var (dict, n, 0))
+          if (id_is_plausible (n, false) && dict_create_var (dict, n, 0))
             break;
         }
     }
index 22058f23bf8d5f1cb227036baf3385ea8610958a..cd9ee98cfa306bb48f9a2773d22f7867353a6510 100644 (file)
@@ -98,3 +98,30 @@ flip.
 AT_CHECK([pspp -O format=csv flip.sps], [1], [ignore])
 
 AT_CLEANUP
+
+
+
+AT_SETUP([FLIP with invalid variable names])
+
+AT_DATA([flip.sps], [dnl
+data list notable list /N (a3) a b c d *.
+begin data.
+""   1  2  3  4
+BY   1  2  3  4
+end data.
+
+flip newnames=n.
+
+list.
+])
+
+AT_CHECK([pspp -O format=csv flip.sps], [0], [dnl
+Table: Data List
+CASE_LBL,v,BY1
+a       ,1.00,1.00
+b       ,2.00,2.00
+c       ,3.00,3.00
+d       ,4.00,4.00
+])
+
+AT_CLEANUP