Skip to content

Commit 4181c26

Browse files
authored
fix potential path traversal vulnerability
1 parent 4d338a6 commit 4181c26

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

builder/frameworks/espidf.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ def _get_installed_standard_pip_packages():
135135
flag_custom_sdkonfig = False
136136
flag_custom_component_add = False
137137
flag_custom_component_remove = False
138-
removed_components = set()
139138

140139
IDF5 = (
141140
platform.get_package_version("framework-espidf")
@@ -220,18 +219,22 @@ def load_custom_sdkconfig_file():
220219
response = requests.get(file_entry.split(" ")[0])
221220
if response.ok:
222221
return response.content.decode('utf-8')
223-
except Exception as e:
222+
except requests.RequestException as e:
224223
print(f"Error downloading {file_entry}: {e}")
224+
except UnicodeDecodeError as e:
225+
print(f"Error decoding response from {file_entry}: {e}")
225226
return ""
226227

227228
# Handle local files
228229
if "file://" in file_entry:
229-
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)
230233
if os.path.exists(file_path):
231234
try:
232235
with open(file_path, 'r') as f:
233236
return f.read()
234-
except Exception as e:
237+
except IOError as e:
235238
print(f"Error reading file {file_path}: {e}")
236239
return ""
237240
else:

0 commit comments

Comments
 (0)