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

unicontrol: unbundle the find-unicode-control script #91

Open
kdudka opened this issue Jan 31, 2023 · 2 comments
Open

unicontrol: unbundle the find-unicode-control script #91

kdudka opened this issue Jan 31, 2023 · 2 comments

Comments

@kdudka
Copy link
Member

kdudka commented Jan 31, 2023

csmock bundles its own copy of the find-unicode-control script. We should remove the script from csmock's git repository and make the unicontrol plug-in download (and cache) the script from upstream as we do in the gitleaks and snyk plug-ins.

@kdudka kdudka mentioned this issue Feb 2, 2023
@kdudka
Copy link
Member Author

kdudka commented Feb 2, 2023

We need to get the following changes upstream first (the first two hunks should be harmless while the change of the output format will need a new option I guess):

--- a/find_unicode_control.py
+++ b/find_unicode_control.py
@@ -15,6 +15,7 @@ from __future__ import print_function

 import sys, os, argparse, re, unicodedata, subprocess
 import importlib
+import six
 from stat import *

 try:
@@ -63,9 +64,9 @@ scan_exclude_mime = [r'text/x-po$', r'text/x-tex$', r'text/x-troff$',
 verbose_mode = False

 # Print to stderr in verbose mode.
-def eprint(*args, **kwargs):
+def eprint(arg, **kwargs):
     if verbose_mode:
-        print(*args, file=sys.stderr, **kwargs)
+        six.print_(arg, file=sys.stderr, **kwargs)

 # Decode a single latin1 line.
 def decodeline(inf):
@@ -103,7 +104,8 @@ def analyze_text_detailed(filename, text, disallowed, msg):
         line = line + 1
         subset = [c for c in t if _chr(ord(c)) in disallowed]
         if subset:
-            print('%s:%d %s: %s' % (filename, line, msg, subset))
+            print('Error: UNICONTROL_WARNING:')
+            print('%s:%d: warning: %s: %s\n' % (filename, line, msg, subset))
             warned = True
     if not warned:
         eprint('%s: OK' % filename)
@@ -118,7 +120,8 @@ def analyze_text(filename, text, disallowed, msg):
         return analyze_text_detailed(filename, text, disallowed, msg)

     if not text.isdisjoint(disallowed):
-        print('%s: %s: %s' % (filename, msg, text & disallowed))
+        print('Error: UNICONTROL_WARNING:')
+        print('%s: warning: %s: %s\n' % (filename, msg, text & disallowed))
         return True
     else:
         eprint('%s: OK' % filename)

kdudka added a commit to kdudka/csmock that referenced this issue Feb 6, 2023
@kdudka
Copy link
Member Author

kdudka commented Jan 21, 2025

Alternatively, csmock-plugin-unicontrol may postprocess the output of the scanning script, e.g. by sed as we do in the sast-unicode-check task in Konflux: https://github.com/konflux-ci/build-definitions/blob/c2003d906d709799c1383f23f04d755fe4c837be/task/sast-unicode-check/0.1/sast-unicode-check.yaml#L154

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant