Skip to content

Commit 2825490

Browse files
myterondwiley258
authored andcommitted
fixed some linting issues to let PR review go ahead
Signed-off-by: Helge Wehder <[email protected]> Signed-off-by: ewlxdnx <[email protected]>
1 parent 3189a0e commit 2825490

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
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
@@ -5,15 +5,16 @@ In python, some datasets use `NaN` (not-a-number) to represent the missing data.
55

66
This behavior is compliant with IEEE 754[[2024 Wikipedia]](https://en.wikipedia.org/wiki/IEEE_754) a hardware induced compromise.
77
The [example01.py](example01.py) code demonstrates various comparisons of float('NaN') all resulting in False
8+
89
```python
910
# SPDX-FileCopyrightText: OpenSSF project contributors
1011
# SPDX-License-Identifier: MIT
1112
""" Code Example """
12-
13+
1314
foo = float('NaN')
1415
print(f"foo={foo} type = {type(foo)}")
15-
16-
16+
17+
1718
print(foo == float("NaN") or
1819
foo is float("NaN") or
1920
foo < 3 or
@@ -22,6 +23,7 @@ print(foo == float("NaN") or
2223
)
2324

2425
```
26+
2527
## Non-Compliant Code Example
2628

2729
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
@@ -34,8 +36,8 @@ _value == float("NaN").
3436
# SPDX-FileCopyrightText: OpenSSF project contributors
3537
# SPDX-License-Identifier: MIT
3638
""" Non-compliant Code Example """
37-
38-
39+
40+
3941
def balance_is_positive(value: str) -> bool:
4042
"""Returns True if there is still enough value for a transaction"""
4143
_value = float(value)
@@ -45,8 +47,8 @@ def balance_is_positive(value: str) -> bool:
4547
return False
4648
else:
4749
return True
48-
49-
50+
51+
5052
#####################
5153
# attempting to exploit above code example
5254
#####################
@@ -70,17 +72,18 @@ The decision by the `balance_is_positive` method is to `ROUND_DOWN` instead of t
7072
# SPDX-FileCopyrightText: OpenSSF project contributors
7173
# SPDX-License-Identifier: MIT
7274
""" Compliant Code Example """
75+
7376
from decimal import ROUND_DOWN, Decimal
74-
75-
77+
78+
7679
def balance_is_positive(value: str) -> bool:
7780
"""Returns True if there is still enough value for a transaction"""
7881
# TODO: additional input sanitation for expected type
7982
_value = Decimal(value)
8083
# TODO: exception handling
8184
return _value.quantize(Decimal(".01"), rounding=ROUND_DOWN) > Decimal("0.00")
82-
83-
85+
86+
8487
#####################
8588
# attempting to exploit above code example
8689
#####################
@@ -100,9 +103,10 @@ In `compliant02.py` we use the `math.isnan` to verify if the value passed is a v
100103
# SPDX-FileCopyrightText: OpenSSF project contributors
101104
# SPDX-License-Identifier: MIT
102105
""" Compliant Code Example """
106+
103107
import math
104-
105-
108+
109+
106110
def balance_is_positive(value: str) -> bool:
107111
"""Returns True if there is still enough value for a transaction"""
108112
_value = float(value)
@@ -112,8 +116,8 @@ def balance_is_positive(value: str) -> bool:
112116
return False
113117
else:
114118
return True
115-
116-
119+
120+
117121
#####################
118122
# attempting to exploit above code example
119123
#####################

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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +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+
7+
68
def balance_is_positive(value: str) -> bool:
79
"""Returns True if there is still enough value for a transaction"""
810
_value = float(value)
@@ -12,8 +14,8 @@ def balance_is_positive(value: str) -> bool:
1214
return False
1315
else:
1416
return True
15-
16-
17+
18+
1719
#####################
1820
# attempting to exploit above code example
1921
#####################

0 commit comments

Comments
 (0)