|
75 | 75 | import shlex # Added for POSIX shell escaping |
76 | 76 |
|
77 | 77 | # input validation helper |
78 | | -def safe_name(value, context, allow_path=False): |
79 | | - """ |
80 | | - Validates that the input string does not contain characters dangerous |
81 | | - for filesystem paths or shell command injection. |
82 | | - """ |
83 | | - if not value: |
84 | | - raise ValueError(f"{context} cannot be empty") |
85 | | - # blocks control characters and shell metacharacters |
86 | | - # allow path separators and drive colons for full paths when needed |
87 | | - if allow_path: |
88 | | - pattern = r'[\x00-\x1F\x7F*?"<>|;&`$\'()]' |
89 | | - else: |
90 | | - # blocks path traversal (/, \, :) in addition to shell metacharacters |
91 | | - pattern = r'[\x00-\x1F\x7F\\/:*?"<>|;&`$\'()]' |
92 | | - if re.search(pattern, value): |
93 | | - raise ValueError(f"Unsafe {context}: '{value}' contains illegal characters.") |
94 | | - return value |
95 | | - |
96 | | -MKCONCORE_VER = "22-09-18" |
97 | | - |
98 | | -SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
99 | | - |
100 | | -def _resolve_concore_path(): |
101 | | - script_concore = os.path.join(SCRIPT_DIR, "concore.py") |
102 | | - if os.path.exists(script_concore): |
103 | | - return SCRIPT_DIR |
104 | | - cwd_concore = os.path.join(os.getcwd(), "concore.py") |
105 | | - if os.path.exists(cwd_concore): |
106 | | - return os.getcwd() |
107 | | - return SCRIPT_DIR |
108 | | - |
109 | | -GRAPHML_FILE = sys.argv[1] |
110 | | -TRIMMED_LOGS = True |
111 | | -CONCOREPATH = _resolve_concore_path() |
| 78 | +def safe_name(value, context, allow_path=False): |
| 79 | + """ |
| 80 | + Validates that the input string does not contain characters dangerous |
| 81 | + for filesystem paths or shell command injection. |
| 82 | + """ |
| 83 | + if not value: |
| 84 | + raise ValueError(f"{context} cannot be empty") |
| 85 | + # blocks control characters and shell metacharacters |
| 86 | + # allow path separators and drive colons for full paths when needed |
| 87 | + if allow_path: |
| 88 | + pattern = r'[\x00-\x1F\x7F*?"<>|;&`$\'()]' |
| 89 | + else: |
| 90 | + # blocks path traversal (/, \, :) in addition to shell metacharacters |
| 91 | + pattern = r'[\x00-\x1F\x7F\\/:*?"<>|;&`$\'()]' |
| 92 | + if re.search(pattern, value): |
| 93 | + raise ValueError(f"Unsafe {context}: '{value}' contains illegal characters.") |
| 94 | + return value |
| 95 | + |
| 96 | +MKCONCORE_VER = "22-09-18" |
| 97 | + |
| 98 | +SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 99 | + |
| 100 | +def _resolve_concore_path(): |
| 101 | + script_concore = os.path.join(SCRIPT_DIR, "concore.py") |
| 102 | + if os.path.exists(script_concore): |
| 103 | + return SCRIPT_DIR |
| 104 | + cwd_concore = os.path.join(os.getcwd(), "concore.py") |
| 105 | + if os.path.exists(cwd_concore): |
| 106 | + return os.getcwd() |
| 107 | + return SCRIPT_DIR |
| 108 | + |
| 109 | +if len(sys.argv) < 4: |
| 110 | + print("Usage: python mkconcore.py <GRAPHML_FILE> <sourcedir> <outdir> [type]") |
| 111 | + print(" type must be posix (macos or ubuntu), windows, or docker") |
| 112 | + sys.exit(1) |
| 113 | + |
| 114 | +GRAPHML_FILE = sys.argv[1] |
| 115 | +TRIMMED_LOGS = True |
| 116 | +CONCOREPATH = _resolve_concore_path() |
112 | 117 | CPPWIN = "g++" #Windows C++ 6/22/21 |
113 | 118 | CPPEXE = "g++" #Ubuntu/macOS C++ 6/22/21 |
114 | 119 | VWIN = "iverilog" #Windows verilog 6/25/21 |
@@ -152,18 +157,14 @@ def _resolve_concore_path(): |
152 | 157 | sourcedir = sys.argv[2] |
153 | 158 | outdir = sys.argv[3] |
154 | 159 |
|
155 | | -# Validate outdir argument (allow full paths) |
156 | | -safe_name(outdir, "Output directory argument", allow_path=True) |
| 160 | +# Validate outdir argument (allow full paths) |
| 161 | +safe_name(outdir, "Output directory argument", allow_path=True) |
157 | 162 |
|
158 | 163 | if not os.path.isdir(sourcedir): |
159 | 164 | logging.error(f"{sourcedir} does not exist") |
160 | 165 | quit() |
161 | 166 |
|
162 | | -if len(sys.argv) < 4: |
163 | | - logging.error("usage: py mkconcore.py file.graphml sourcedir outdir [type]") |
164 | | - logging.error(" type must be posix (macos or ubuntu), windows, or docker") |
165 | | - quit() |
166 | | -elif len(sys.argv) == 4: |
| 167 | +if len(sys.argv) == 4: |
167 | 168 | prefixedgenode = outdir+"_" #nodes and edges prefixed with outdir_ only in case no type specified 3/24/21 |
168 | 169 | concoretype = "docker" |
169 | 170 | else: |
@@ -1227,4 +1228,4 @@ def cleanup_script_files(): |
1227 | 1228 | os.chmod(outdir+"/clear",stat.S_IRWXU) |
1228 | 1229 | os.chmod(outdir+"/maxtime",stat.S_IRWXU) |
1229 | 1230 | os.chmod(outdir+"/params",stat.S_IRWXU) |
1230 | | - os.chmod(outdir+"/unlock",stat.S_IRWXU) |
| 1231 | + os.chmod(outdir+"/unlock",stat.S_IRWXU) |
0 commit comments