lib/bitmap.c: fix a special string handling bug in __bitmap_parselist
[firefly-linux-kernel-4.4.55.git] / lib / bitmap.c
index eb21456be4b9ed4efb4ae4dfd8576d52da2b88db..f549176e9250238a9b923225ed0534226c5ab40e 100644 (file)
@@ -546,6 +546,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
                                        return -EINVAL;
                                b = 0;
                                in_range = 1;
+                               at_start = 1;
                                continue;
                        }
 
@@ -558,6 +559,9 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
                        at_start = 0;
                        totaldigits++;
                }
+               /* if no digit is after '-', it's wrong*/
+               if (at_start && in_range)
+                       return -EINVAL;
                if (!(a <= b))
                        return -EINVAL;
                if (b >= nmaskbits)