Skip to content

Commit 022ed65

Browse files
authored
fix potential path traversal vulnerability
1 parent d7f29a2 commit 022ed65

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

builder/frameworks/espidf.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,18 +219,22 @@ def load_custom_sdkconfig_file():
219219
response = requests.get(file_entry.split(" ")[0])
220220
if response.ok:
221221
return response.content.decode('utf-8')
222-
except Exception as e:
222+
except requests.RequestException as e:
223223
print(f"Error downloading {file_entry}: {e}")
224+
except UnicodeDecodeError as e:
225+
print(f"Error decoding response from {file_entry}: {e}")
224226
return ""
225227

226228
# Handle local files
227229
if "file://" in file_entry:
228-
file_path = join(PROJECT_DIR, file_entry.lstrip("file://").split(os.path.sep)[-1])
230+
file_ref = file_entry[7:] if file_entry.startswith("file://") else file_entry
231+
filename = os.path.basename(file_ref)
232+
file_path = join(PROJECT_DIR, filename)
229233
if os.path.exists(file_path):
230234
try:
231235
with open(file_path, 'r') as f:
232236
return f.read()
233-
except Exception as e:
237+
except IOError as e:
234238
print(f"Error reading file {file_path}: {e}")
235239
return ""
236240
else:

0 commit comments

Comments
 (0)