Skip to content

Commit fbc4ef9

Browse files
committed
fixed some linting issues to let PR review go ahead
Signed-off-by: Helge Wehder <[email protected]>
1 parent 1f9baa7 commit fbc4ef9

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ In python, some datasets use NaN (not-a-number) to represent the missing data. T
44

55
This behavior is compliant with IEEE 754[[2024 Wikipedia]](https://en.wikipedia.org/wiki/IEEE_754) a hardware induced compromise.
66
The [example01.py](example01.py) code demonstrates various comparisons of float('NaN') all resulting in False
7+
78
```python
89
""" Code Example """
9-
10+
1011
foo = float('NaN')
1112
print(f"foo={foo} type = {type(foo)}")
12-
13-
13+
14+
1415
print(foo == float("NaN") or
1516
foo is float("NaN") or
1617
foo < 3 or
@@ -19,6 +20,7 @@ print(foo == float("NaN") or
1920
)
2021

2122
```
23+
2224
## Non-Compliant Code Example
2325

2426
This noncompliant code example [[2024 docs.python.org]](https://docs.python.org/3/reference/expressions.html#value-comparisons) attempts a direct comparison with NaN in
@@ -29,8 +31,8 @@ _value == float("NaN").
2931

3032
```python
3133
""" Non-compliant Code Example """
32-
33-
34+
35+
3436
def balance_is_positive(value: str) -> bool:
3537
"""Returns True if there is still enough value for a transaction"""
3638
_value = float(value)
@@ -40,8 +42,8 @@ def balance_is_positive(value: str) -> bool:
4042
return False
4143
else:
4244
return True
43-
44-
45+
46+
4547
#####################
4648
# attempting to exploit above code example
4749
#####################
@@ -65,17 +67,18 @@ The decision by the balance_is_positive method is to ROUND_DOWN instead of the d
6567
# SPDX-FileCopyrightText: OpenSSF project contributors
6668
# SPDX-License-Identifier: MIT
6769
""" Compliant Code Example """
70+
6871
from decimal import ROUND_DOWN, Decimal
69-
70-
72+
73+
7174
def balance_is_positive(value: str) -> bool:
7275
"""Returns True if there is still enough value for a transaction"""
7376
# TODO: additional input sanitation for expected type
7477
_value = Decimal(value)
7578
# TODO: exception handling
7679
return _value.quantize(Decimal(".01"), rounding=ROUND_DOWN) > Decimal("0.00")
77-
78-
80+
81+
7982
#####################
8083
# attempting to exploit above code example
8184
#####################
@@ -95,9 +98,10 @@ In `compliant02.py` we use the math.isnan to very if the value passed is a valid
9598
# SPDX-FileCopyrightText: OpenSSF project contributors
9699
# SPDX-License-Identifier: MIT
97100
""" Compliant Code Example """
101+
98102
import math
99-
100-
103+
104+
101105
def balance_is_positive(value: str) -> bool:
102106
"""Returns True if there is still enough value for a transaction"""
103107
_value = float(value)
@@ -107,8 +111,8 @@ def balance_is_positive(value: str) -> bool:
107111
return False
108112
else:
109113
return True
110-
111-
114+
115+
112116
#####################
113117
# attempting to exploit above code example
114118
#####################

docs/Secure-Coding-Guide-for-Python/CWE-703/CWE-230/compliant01.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-FileCopyrightText: OpenSSF project contributors
22
# SPDX-License-Identifier: MIT
3-
""" Non-compliant Code Example """
3+
""" Compliant Code Example """
44

55
from decimal import ROUND_DOWN, Decimal
66

docs/Secure-Coding-Guide-for-Python/CWE-703/CWE-230/compliant02.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# SPDX-FileCopyrightText: OpenSSF project contributors
22
# SPDX-License-Identifier: MIT
3-
""" Non-compliant Code Example """
3+
""" Compliant Code Example """
4+
45
import math
5-
6-
6+
7+
78
def balance_is_positive(value: str) -> bool:
89
"""Returns True if there is still enough value for a transaction"""
910
_value = float(value)
@@ -13,8 +14,8 @@ def balance_is_positive(value: str) -> bool:
1314
return False
1415
else:
1516
return True
16-
17-
17+
18+
1819
#####################
1920
# attempting to exploit above code example
2021
#####################

0 commit comments

Comments
 (0)