commit:     c26adcb74a24c169fd2b2b83b5e72cdd478e6b34
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Tue Apr 23 08:39:11 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Tue Apr 23 08:39:11 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=c26adcb7

q_vdb_filter_cat: make name check more strict

Validate to exclude things like distfiles, metadata, profiles.  Require
the hyphen except for "virtual".  This isn't strictly conforming to PMS
but matches Gentoo reality.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/vdb.c                                         | 40 +++++++++++++---------
 tests/qcheck/list04.good                           |  2 +-
 tests/qcheck/list05.good                           |  2 +-
 tests/qcheck/list06.good                           |  2 +-
 tests/qcheck/list07.good                           |  2 +-
 tests/qcheck/root/{cat => virtual}/pkg-1/CONTENTS  |  0
 tests/qcheck/root/{cat => virtual}/pkg-1/SLOT      |  0
 .../qcheck/root/{cat => virtual}/pkg-1/repository  |  0
 tests/qlist/dotest                                 |  2 +-
 tests/qlist/list01.good                            |  4 +--
 tests/qlist/list07.good                            |  4 +--
 tests/qlist/list11.good                            |  4 +--
 tests/qlist/list12.good                            |  4 +--
 tests/qlist/list14.good                            |  4 +--
 tests/qlist/list16.good                            |  2 +-
 tests/qlist/root/{cat => virtual}/pkg-1/CONTENTS   |  0
 tests/qlist/root/{cat => virtual}/pkg-1/SLOT       |  0
 tests/qlist/root/{cat => virtual}/pkg-1/repository |  0
 tests/qlist/root/{cat => virtual}/sub-2/CONTENTS   |  0
 tests/qlist/root/{cat => virtual}/sub-2/SLOT       |  0
 tests/qlist/root/{cat => virtual}/sub-2/repository |  0
 21 files changed, 40 insertions(+), 32 deletions(-)

diff --git a/libq/vdb.c b/libq/vdb.c
index 974986c..6b973e8 100644
--- a/libq/vdb.c
+++ b/libq/vdb.c
@@ -68,6 +68,7 @@ int
 q_vdb_filter_cat(const struct dirent *de)
 {
        int i;
+       bool founddash;
 
 #ifdef DT_UNKNOWN
        if (de->d_type != DT_UNKNOWN &&
@@ -76,24 +77,31 @@ q_vdb_filter_cat(const struct dirent *de)
                return 0;
 #endif
 
-       if (de->d_name[0] == '.' || de->d_name[0] == '-')
-               return 0;
-
-       for (i = 0; de->d_name[i]; ++i) {
-               if (!isalnum(de->d_name[i])) { /* [A-Za-z0-9+_.-] */
-                       switch (de->d_name[i]) {
-                               case '+':
-                               case '_':
-                               case '.':
-                               case '-':
-                                       if (i)
-                                               break;
-                                       /* fall through */
-                               default:
-                                       return 0;
-                       }
+       /* PMS 3.1.1 */
+       founddash = false;
+       for (i = 0; de->d_name[i] != '\0'; i++) {
+               switch (de->d_name[i]) {
+                       case '_':
+                               break;
+                       case '-':
+                               founddash = true;
+                               /* fall through */
+                       case '+':
+                       case '.':
+                               if (i)
+                                       break;
+                               return 0;
+                       default:
+                               if ((de->d_name[i] >= 'A' && de->d_name[i] <= 
'Z') ||
+                                               (de->d_name[i] >= 'a' && 
de->d_name[i] <= 'z') ||
+                                               (de->d_name[i] >= '0' && 
de->d_name[i] <= '9'))
+                                       break;
+                               return 0;
                }
        }
+       if (!founddash && strcmp(de->d_name, "virtual") != 0)
+               return 0;
+
        return i;
 }
 

diff --git a/tests/qcheck/list04.good b/tests/qcheck/list04.good
index 930f896..b90a759 100644
--- a/tests/qcheck/list04.good
+++ b/tests/qcheck/list04.good
@@ -7,5 +7,5 @@ Checking a-b/pkg-1.0 ...
  AFK: /missing-dir/missing-file
  AFK: /missing-dir/missing-sym
   * 4 out of 11 files are good (2 files were ignored)
-Checking cat/pkg-1 ...
+Checking virtual/pkg-1 ...
   * 0 out of 0 file are good

diff --git a/tests/qcheck/list05.good b/tests/qcheck/list05.good
index d4c4243..6a6d206 100644
--- a/tests/qcheck/list05.good
+++ b/tests/qcheck/list05.good
@@ -7,5 +7,5 @@ Checking a-b/pkg-1.0 ...
  AFK: /missing-dir/missing-file
  AFK: /missing-dir/missing-sym
   * 4 out of 11 files are good (2 files were ignored)
-Checking cat/pkg-1 ...
+Checking virtual/pkg-1 ...
   * 0 out of 0 file are good

diff --git a/tests/qcheck/list06.good b/tests/qcheck/list06.good
index 3cd48f7..a924758 100644
--- a/tests/qcheck/list06.good
+++ b/tests/qcheck/list06.good
@@ -4,5 +4,5 @@ Checking a-b/pkg-1.0 ...
  SHA1-DIGEST: /bin/bad-sha1
  MTIME: /bin/bad-mtime-sym
   * 4 out of 8 files are good (5 files were ignored)
-Checking cat/pkg-1 ...
+Checking virtual/pkg-1 ...
   * 0 out of 0 file are good

diff --git a/tests/qcheck/list07.good b/tests/qcheck/list07.good
index fb59689..f354269 100644
--- a/tests/qcheck/list07.good
+++ b/tests/qcheck/list07.good
@@ -1,4 +1,4 @@
 Checking a-b/pkg-1.0 ...
   * 4 out of 4 files are good (9 files were ignored)
-Checking cat/pkg-1 ...
+Checking virtual/pkg-1 ...
   * 0 out of 0 file are good

diff --git a/tests/qcheck/root/cat/pkg-1/CONTENTS 
b/tests/qcheck/root/virtual/pkg-1/CONTENTS
similarity index 100%
rename from tests/qcheck/root/cat/pkg-1/CONTENTS
rename to tests/qcheck/root/virtual/pkg-1/CONTENTS

diff --git a/tests/qcheck/root/cat/pkg-1/SLOT 
b/tests/qcheck/root/virtual/pkg-1/SLOT
similarity index 100%
rename from tests/qcheck/root/cat/pkg-1/SLOT
rename to tests/qcheck/root/virtual/pkg-1/SLOT

diff --git a/tests/qcheck/root/cat/pkg-1/repository 
b/tests/qcheck/root/virtual/pkg-1/repository
similarity index 100%
rename from tests/qcheck/root/cat/pkg-1/repository
rename to tests/qcheck/root/virtual/pkg-1/repository

diff --git a/tests/qlist/dotest b/tests/qlist/dotest
index 317a282..2ba7033 100755
--- a/tests/qlist/dotest
+++ b/tests/qlist/dotest
@@ -68,7 +68,7 @@ test 14 0 "qlist -ICSS"
 test 15 1 "qlist -Iv lajsdflkjasdflkjasdfljasdf"
 
 # match test w/out sub-SLOT
-test 16 0 "qlist -ICSS cat/sub-2:1"
+test 16 0 "qlist -ICSS virtual/sub-2:1"
 
 cleantmpdir
 

diff --git a/tests/qlist/list01.good b/tests/qlist/list01.good
index 82249bf..1dd8070 100644
--- a/tests/qlist/list01.good
+++ b/tests/qlist/list01.good
@@ -1,6 +1,6 @@
 a-b/a
 a-b/b
 app-arch/cpio
-cat/pkg
-cat/sub
 sys-fs/mtools
+virtual/pkg
+virtual/sub

diff --git a/tests/qlist/list07.good b/tests/qlist/list07.good
index 769299c..618697b 100644
--- a/tests/qlist/list07.good
+++ b/tests/qlist/list07.good
@@ -1,6 +1,6 @@
 a-b/a:a-0
 a-b/b:b-0
 app-arch/cpio:0
-cat/pkg:1
-cat/sub:1
 sys-fs/mtools:0
+virtual/pkg:1
+virtual/sub:1

diff --git a/tests/qlist/list11.good b/tests/qlist/list11.good
index cb2abaf..d41c6bf 100644
--- a/tests/qlist/list11.good
+++ b/tests/qlist/list11.good
@@ -1,6 +1,6 @@
 a-b/a::a
 a-b/b::b
 app-arch/cpio::gentoo
-cat/pkg::repo
-cat/sub::repo
 sys-fs/mtools::gentoo
+virtual/pkg::repo
+virtual/sub::repo

diff --git a/tests/qlist/list12.good b/tests/qlist/list12.good
index 706cb29..575aea4 100644
--- a/tests/qlist/list12.good
+++ b/tests/qlist/list12.good
@@ -1,6 +1,6 @@
 a-b/a:a-0::a
 a-b/b:b-0::b
 app-arch/cpio:0::gentoo
-cat/pkg:1::repo
-cat/sub:1::repo
 sys-fs/mtools:0::gentoo
+virtual/pkg:1::repo
+virtual/sub:1::repo

diff --git a/tests/qlist/list14.good b/tests/qlist/list14.good
index 37abd51..d401b1e 100644
--- a/tests/qlist/list14.good
+++ b/tests/qlist/list14.good
@@ -1,6 +1,6 @@
 a-b/a:a-0
 a-b/b:b-0
 app-arch/cpio:0
-cat/pkg:1
-cat/sub:1/1234
 sys-fs/mtools:0
+virtual/pkg:1
+virtual/sub:1/1234

diff --git a/tests/qlist/list16.good b/tests/qlist/list16.good
index 9c27e9c..9e1d5e3 100644
--- a/tests/qlist/list16.good
+++ b/tests/qlist/list16.good
@@ -1 +1 @@
-cat/sub:1/1234
+virtual/sub:1/1234

diff --git a/tests/qlist/root/cat/pkg-1/CONTENTS 
b/tests/qlist/root/virtual/pkg-1/CONTENTS
similarity index 100%
rename from tests/qlist/root/cat/pkg-1/CONTENTS
rename to tests/qlist/root/virtual/pkg-1/CONTENTS

diff --git a/tests/qlist/root/cat/pkg-1/SLOT 
b/tests/qlist/root/virtual/pkg-1/SLOT
similarity index 100%
rename from tests/qlist/root/cat/pkg-1/SLOT
rename to tests/qlist/root/virtual/pkg-1/SLOT

diff --git a/tests/qlist/root/cat/pkg-1/repository 
b/tests/qlist/root/virtual/pkg-1/repository
similarity index 100%
rename from tests/qlist/root/cat/pkg-1/repository
rename to tests/qlist/root/virtual/pkg-1/repository

diff --git a/tests/qlist/root/cat/sub-2/CONTENTS 
b/tests/qlist/root/virtual/sub-2/CONTENTS
similarity index 100%
rename from tests/qlist/root/cat/sub-2/CONTENTS
rename to tests/qlist/root/virtual/sub-2/CONTENTS

diff --git a/tests/qlist/root/cat/sub-2/SLOT 
b/tests/qlist/root/virtual/sub-2/SLOT
similarity index 100%
rename from tests/qlist/root/cat/sub-2/SLOT
rename to tests/qlist/root/virtual/sub-2/SLOT

diff --git a/tests/qlist/root/cat/sub-2/repository 
b/tests/qlist/root/virtual/sub-2/repository
similarity index 100%
rename from tests/qlist/root/cat/sub-2/repository
rename to tests/qlist/root/virtual/sub-2/repository

Reply via email to