Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] inconsistent CVE matching depending on regexes count #1583

Closed
c0bw3b opened this issue Jan 23, 2024 · 2 comments · Fixed by #1586
Closed

[BUG] inconsistent CVE matching depending on regexes count #1583

c0bw3b opened this issue Jan 23, 2024 · 2 comments · Fixed by #1586

Comments

@c0bw3b
Copy link

c0bw3b commented Jan 23, 2024

OCS Inventory version

Version : server OCS Reports 2.12.0

Describe the bug

Matching CVEs with software inventory behaves differently according to the number of regexes defined.

To Reproduce

Defining the following single regex...:

Name or Regex Publisher result Name result
haproxy haproxy haproxy

... will match apr (as in Apache APR) software name and associate HAProxy CVEs to machines whose software inventory contains Apache APR.

Now if we define these two regexes:

Name or Regex Publisher result Name result
haproxy haproxy haproxy
apr apache portable_runtime

Then HAProxy CVEs won't be associated to Apache APR anymore.

It seems this problem comes from this test in cve.php.
I dont understand the logic or necessity of this test coming from #1137 by @charleneauger

In the first scenario wildcards will be ignored because stringMatchWithWildcard isn't called.

Expected behavior

Correct CPEs <> CVEs matching regardless of the number of regexes defined.

@c0bw3b
Copy link
Author

c0bw3b commented Jan 23, 2024

The following diff seems to fix the matching in the first scenario:

--- a/require/cve/Cve.php
+++ b/require/cve/Cve.php
@@ -268,8 +268,13 @@ private function match($values) {
 
     if(!empty($regs)) {
       foreach($regs as $key => $reg) {
-        if(count($regs) == 1) {
-          $reg_publish = true;
-          $reg_name = true;
-        } else {
-          $reg_publish = $this->stringMatchWithWildcard(trim($values['VENDOR']), $reg['NAME_REG']);
-          $reg_name = $this->stringMatchWithWildcard(trim($values['NAME']), $reg['NAME_REG']);
-        }
+        $reg_publish = $this->stringMatchWithWildcard(trim($values['VENDOR']), $reg['NAME_REG']);
+        $reg_name = $this->stringMatchWithWildcard(trim($values['NAME']), $reg['NAME_REG']);
 
         if($reg_name || $reg_publish) {
           if($reg['NAME_RESULT'] != "") {

But it may not be the correct approach.

PS : pas de problème pour échanger en français si vous le souhaitez :)

@c0bw3b c0bw3b changed the title [BUG] [BUG] inconsistent CVE matching depending on regexes count Jan 23, 2024
@charleneauger
Copy link
Member

Bonjour @c0bw3b ,

Merci pour votre retour.
Nous allons regarder ça de plus près et voir pour proposer un correctif/amélioration prochainement.

Je vous tiendrai au courant de lorsque ça sera disponible :)

Cordialement,
Charlène

@charleneauger charleneauger linked a pull request Feb 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants