Skip to content

Commit a8b6345

Browse files
Update README.md
Left a sentence about the output of "compliant01.py" Signed-off-by: Bartlomiej Karas <[email protected]>
1 parent ccac54b commit a8b6345

File tree

1 file changed

+3
-1
lines changed
  • docs/Secure-Coding-Guide-for-Python/CWE-703/CWE-754

1 file changed

+3
-1
lines changed

docs/Secure-Coding-Guide-for-Python/CWE-703/CWE-754/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ class Package:
123123
self.max_package_weight: float = 100.0
124124
125125
def add_to_package(self, object_weight: Union[str, int, float]) -> None:
126+
# TODO: input sanitation.
127+
# TODO: proper exception handling
126128
"""Add an object into the package after validating its weight."""
127129
try:
128130
value = float(object_weight)
@@ -164,7 +166,7 @@ for item in [100, "-infinity", sys.float_info.max, "NaN", -100]:
164166
print(e)
165167
```
166168
167-
The compliant code example successfully ensures that any object added to the package is a valid and anticipated float value, and that the code cannot be exploited by inputting values such as NaN, infinite or -infinite.
169+
This compliant code example will raise a ValueError for inputs that are "-infinity", "infinity", or NaN, with messages "Input is not a finite number" and "Input is not a number" respectively. It should also ensure weights are non-negative, returning "Weight must be a non-negative number" for negative inputs.
168170
169171
**Example `compliant01.py` output:**
170172

0 commit comments

Comments
 (0)