Skip to content

Commit a1e4cd1

Browse files
BartyBoi1128s19110
andauthored
Update docs/Secure-Coding-Guide-for-Python/CWE-703/CWE-390/REAME.md
Had the wrong Code Example in! Co-authored-by: Hubert Daniszewski <[email protected]> Signed-off-by: BartyBoi1128 <[email protected]>
1 parent 9e57d44 commit a1e4cd1

File tree

1 file changed

+17
-11
lines changed
  • docs/Secure-Coding-Guide-for-Python/CWE-703/CWE-390

1 file changed

+17
-11
lines changed

docs/Secure-Coding-Guide-for-Python/CWE-703/CWE-390/REAME.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,24 +104,30 @@ If recovery from an exception remains impossible, it is often best practice to w
104104
```py
105105
# SPDX-FileCopyrightText: OpenSSF project contributors
106106
# SPDX-License-Identifier: MIT
107-
""" Compliant Code Example """
108-
from time import sleep
107+
"""Code Example"""
109108

110109

111-
def exception_example():
112-
"""Compliant Code Example catching a specific exception"""
113-
while True:
114-
sleep(1)
115-
try:
116-
_ = 1 / 0
117-
except ZeroDivisionError:
118-
print("How is it now?")
110+
def slice_cake(cake: int, plates: int) -> float:
111+
"""Calculates size of each slice per plate for a cake
112+
Args:
113+
cake (int) : Size of the cake
114+
guests (int): Amount of guests
115+
Returns:
116+
(float): Size of each slice
117+
"""
118+
119+
try:
120+
return cake / plates
121+
except ZeroDivisionError as zero_division_error:
122+
raise ZeroDivisionError(
123+
"slice_cake:You got to give me plates"
124+
) from zero_division_error
119125

120126

121127
#####################
122128
# exploiting above code example
123129
#####################
124-
exception_example()
130+
slice_cake(cake=100, plates=0)
125131
```
126132

127133
## Automated Detection

0 commit comments

Comments
 (0)