Spaces:
Runtime error
Runtime error
Upload examples.txt
Browse files- examples.txt +47 -0
examples.txt
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#### examples of secure code
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
1. def findAverage(list): sum = 0. for x in list: sum = sum + x average = sum / len(list) return average
|
| 5 |
+
|
| 6 |
+
2. def findMax(list): max = list[0] for x in list: if x > max: max = x return max
|
| 7 |
+
|
| 8 |
+
3. def findRange(list): return max(list)-min(list)
|
| 9 |
+
|
| 10 |
+
4. def rng(): return random.randint(0,9)
|
| 11 |
+
|
| 12 |
+
5. def search(arr, low, high, x): if high >= low: mid = (high + low) // 2 if arr[mid] == x: return mid elif arr[mid] > x: return search(arr, low, mid - 1, x) else: return search(arr, mid + 1, high, x) else: return -1
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
#### examples of insecure code
|
| 18 |
+
(obtained from https://hackernoon.com/10-common-security-gotchas-in-python-and-how-to-avoid-them-e19fbe265e03
|
| 19 |
+
and from http://www.pvv.org/~oma/InsecureCodingC_NDC_June2014.pdf)
|
| 20 |
+
|
| 21 |
+
1.
|
| 22 |
+
import subprocess
|
| 23 |
+
def transcode_file(request, filename):
|
| 24 |
+
command = 'ffmpeg -i '{source}' output_file.mpg'.format(source=filename)
|
| 25 |
+
subprocess.call(command, shell=True)
|
| 26 |
+
|
| 27 |
+
2.
|
| 28 |
+
def foo(request, user): assert user.is_admin, “user does not have access”
|
| 29 |
+
|
| 30 |
+
3.
|
| 31 |
+
void authenticate_and_launch(void)
|
| 32 |
+
{
|
| 33 |
+
int n_missiles = 2;
|
| 34 |
+
bool allowaccess = false;
|
| 35 |
+
char response[8];
|
| 36 |
+
printf("Secret: ");
|
| 37 |
+
gets(response);
|
| 38 |
+
if (strcmp(response, "Joshua") == 0)
|
| 39 |
+
allowaccess = true;
|
| 40 |
+
if (allowaccess) {
|
| 41 |
+
puts("Access granted");
|
| 42 |
+
launch_missiles(n_missiles);
|
| 43 |
+
}
|
| 44 |
+
if (!allowaccess)
|
| 45 |
+
puts("Access denied");
|
| 46 |
+
|
| 47 |
+
|