-
Notifications
You must be signed in to change notification settings - Fork 0
/
brpo4.html
497 lines (424 loc) · 16 KB
/
brpo4.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title></title>
<link rel="stylesheet" href="dist/reveal.css" />
<link rel="stylesheet" href="dist/theme/white.css" id="theme" />
<link rel="stylesheet" href="plugin/highlight/zenburn.css" />
<link rel="stylesheet" href="css/layout.css" />
<link rel="stylesheet" href="plugin/customcontrols/style.css">
<script defer src="dist/fontawesome/all.min.js"></script>
<script type="text/javascript">
var forgetPop = true;
function onPopState(event) {
if(forgetPop){
forgetPop = false;
} else {
parent.postMessage(event.target.location.href, "app://obsidian.md");
}
}
window.onpopstate = onPopState;
window.onmessage = event => {
if(event.data == "reload"){
window.document.location.reload();
}
forgetPop = true;
}
function fitElements(){
const itemsToFit = document.getElementsByClassName('fitText');
for (const item in itemsToFit) {
if (Object.hasOwnProperty.call(itemsToFit, item)) {
var element = itemsToFit[item];
fitElement(element,1, 1000);
element.classList.remove('fitText');
}
}
}
function fitElement(element, start, end){
let size = (end + start) / 2;
element.style.fontSize = `${size}px`;
if(Math.abs(start - end) < 1){
while(element.scrollHeight > element.offsetHeight){
size--;
element.style.fontSize = `${size}px`;
}
return;
}
if(element.scrollHeight > element.offsetHeight){
fitElement(element, start, size);
} else {
fitElement(element, size, end);
}
}
document.onreadystatechange = () => {
fitElements();
if (document.readyState === 'complete') {
if (window.location.href.indexOf("?export") != -1){
parent.postMessage(event.target.location.href, "app://obsidian.md");
}
if (window.location.href.indexOf("print-pdf") != -1){
let stateCheck = setInterval(() => {
clearInterval(stateCheck);
window.print();
}, 250);
}
}
};
</script>
</head>
<body>
<div class="reveal">
<div class="slides"><section data-markdown><script type="text/template"><!-- .slide: class="drop" -->
<div class="" style="position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center" absolute="true">
### Безопасная разработка программного обеспечения
Занятие 4. Статический анализ 2.
Основано на Введении в статический анализ Дмитрия Журихина (ИСП РАН)
23.09.2024
</div></script></section><section data-markdown><script type="text/template"><!-- .slide: class="drop" -->
<div class="" style="position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center" absolute="true">
[CWE Top 25 2023](https://cwe.mitre.org/top25/archive/2023/2023_top25_list.html)
</div></script></section><section data-markdown><script type="text/template"><!-- .slide: class="drop" -->
<div class="" style="position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center" absolute="true">
```cpp
void foo(char *p, int c) {
if (c) {
p = 0;
}
// ...
*p = '\0';
}
```
</div></script></section><section data-markdown><script type="text/template"><!-- .slide: class="drop" -->
<div class="" style="position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center" absolute="true">
```cpp
int buf[10];
int bar(int a, int b) {
if (a >= 9) { // True
// ...
}
if (b) // True
a++;
return buf[a]; // Ошибка
}
```
</div></script></section><section data-markdown><script type="text/template"><!-- .slide: class="drop" -->
<div class="" style="position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center" absolute="true">
Примеры «неконсистентностей» в коде
```cpp
if (op1 == null || op1 == null) // Ошибка
return null;
```
```cpp
p = get_value();
if (p == NULL)
return;
// ...
q = get_value();
if (q == NULL)
return;
// ...
r = get_value();
*r = 42; // Ошибка
```
</div></script></section><section data-markdown><script type="text/template"><!-- .slide: class="drop" -->
<div class="" style="position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center" absolute="true">
Android 5.0.2, external/linux-tools-perf/perf-3.12.0/tools/perf/builtin-script.c:914
```cpp
void desc_delete(struct desc *s) {
free(s->name);
free(s);
}
struct desc* findnew(const char *name) {
struct desc *s = desc_find(name);
if (s)
return s;
desc_delete(s);
return NULL;
}
```
</div></script></section><section data-markdown><script type="text/template"><!-- .slide: class="drop" -->
<div class="" style="position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center" absolute="true">
```cpp
int foo(char *str, unsigned index) {
int pos = index;
pos++;
return str[pos];
}
```
</div></script></section><section data-markdown><script type="text/template"><!-- .slide: class="drop" -->
<div class="" style="position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center" absolute="true">
OS Command injection
The mlfi_envrcpt function in spamass-milter.cpp in SpamAssassin Milter Plugin 0.3.1, when using the expand option, allows remote attackers to execute arbitrary system commands via shell metacharacters in the RCPT TO field of an email message.
Example: `rcpt to: root+:"|touch /tmp/foo"`
```cpp
/* open a pipe to sendmail so we can do address expansion */
char buf[1024];
const char *fmt="%s -bv \"%s\" 2>&1";
snprintf(buf, sizeof(buf)-1, fmt, SENDMAIL, envrcpt[0]);
...
p = popen(buf, "r");
```
</div></script></section><section data-markdown><script type="text/template"><!-- .slide: class="drop" -->
<div class="" style="position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center" absolute="true">
Проблемы многопоточных программ
Deadlock
```cpp
pthread_mutex_t *a, *b;
void thread1() {
pthread_mutex_lock(a);
// ...
pthread_mutex_lock(b);
// ...
}
void thread2() {
pthread_mutex_lock(b);
// ...
pthread_mutex_lock(a);
// ...
}
```
</div></script></section><section data-markdown><script type="text/template"><!-- .slide: class="drop" -->
<div class="" style="position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center" absolute="true">
Виды статического анализа
```
void foo (void) {
char *p = NULL;
*p = 0;
}
```
</div></script></section><section data-markdown><script type="text/template"><!-- .slide: class="drop" -->
<div class="" style="position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center" absolute="true">
Потоково-чувствительный анализ
Разыменование после сравнения с NULL.
```
void foo (char *p) {
if (p == NULL) {
*p = 0;
}
}
```
Неконсистентные проверки на NULL
```
void foo (char *p) {
if (p != NULL) {
*p = 5;
}
*p = 42;
}
```
Требование: чувствительный к потоку анализ.
</div></script></section><section data-markdown><script type="text/template"><!-- .slide: class="drop" -->
<div class="" style="position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center" absolute="true">
Разыменование NULL на некотором пути
```
void foo (char *p, int x) {
if (x > 0)
p = NULL;
if (x < 0)
*p = 42; // Нет ошибки
}
void bar (char *p, int x) {
if (x > 0)
p = NULL;
if (x < 7)
*p = 42; // Ошибка
}
```
Требование: чувствительный к путям анализ.
</div></script></section><section data-markdown><script type="text/template"><!-- .slide: class="drop" -->
<div class="" style="position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center" absolute="true">
Разыменование NULL в вызываемой функции.
```
void foo (char *p, int x) {
if (p != NULL)
*p = 5;
cderef(p, x); // Ошибка
}
void bar (char *p, int x) {
if (p != NULL)
cderef(p, x); // Нет ошибки
}
void baz (char *p, int x) {
cderef(NULL, abs(x)); //Нет ошибки
}
void cderef (char *p, int x) {
if (x < 0)
*p = 42;
}
```
Требование: межпроцедурный чувствительный к контексту анализ.
</div></script></section><section data-markdown><script type="text/template"><!-- .slide: class="drop" -->
<div class="" style="position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center" absolute="true">
Разыменование псевдонима после сравнения с NULL.
```
struct s {
char *buf;
...
};
void func (struct s *p) {
char *q = p->buf;
if (p->buf == NULL) { // q == NULL
*q = 42; // Ошибка
}
}
```
Требование: анализ псевдонимов (алиасов).
</div></script></section><section data-markdown><script type="text/template"><!-- .slide: class="drop" -->
<div class="" style="position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center" absolute="true">
Разыменование NULL в поле структуры.
```
struct s {
int x;
int *next;
};
void write (struct s *q) {
*(q->next) = 42;
}
void foo (struct s *p) {
p->next = NULL;
write(p); // Ошибка
}
```
Требование: чувствительный к полям анализ (field sensitive).
</div></script></section><section data-markdown><script type="text/template"><!-- .slide: class="drop" -->
<div class="" style="position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center" absolute="true">
Переполнение буфера из-за некорректного вычисления индекса.
```
int buf[100];
void foo(unsigned i) {
if (i >= 100)
return;
// i ∈ [0, 99]
// ...
x = i + 5; // x ∈ [5, 104]
buf[x] = 42 // Ошибка
}
```
Требование: анализ связей между значениями (интервальный или точнее).
</div></script></section><section data-markdown><script type="text/template"><!-- .slide: class="drop" -->
<div class="" style="position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center" absolute="true">
Переполнение буфера после цикла.
```
int buf[100];
int find(void) {
for (int i = 0; i < 100; i++) {
if (check(i))
break;
}
return buf[i]; // Ошибка
}
```
Требование: анализ циклов.
</div></script></section><section data-markdown><script type="text/template"><!-- .slide: class="drop" -->
<div class="" style="position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center" absolute="true">
Разыменование NULL после проверки.
```
void foo() {
int *p = get_pointer();
if (p == NULL)
log_error_and_exit();
*p = 42; // Нет ошибки
}
```
Требование: анализ недостижимого кода, учёт функций, не возвращающих управление.
</div></script></section><section data-markdown><script type="text/template"><!-- .slide: class="drop" -->
<div class="" style="position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center" absolute="true">
Уровни статического анализа
<img src="Bins/Images/Pasted image 20240923162705.png" alt="" style="object-fit: scale-down">
</div></script></section></div>
</div>
<script src="dist/reveal.js"></script>
<script src="plugin/markdown/markdown.js"></script>
<script src="plugin/highlight/highlight.js"></script>
<script src="plugin/zoom/zoom.js"></script>
<script src="plugin/notes/notes.js"></script>
<script src="plugin/math/math.js"></script>
<script src="plugin/mermaid/mermaid.js"></script>
<script src="plugin/chart/chart.min.js"></script>
<script src="plugin/chart/plugin.js"></script>
<script src="plugin/menu/menu.js"></script>
<script src="plugin/customcontrols/plugin.js"></script>
<script>
function extend() {
var target = {};
for (var i = 0; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (source.hasOwnProperty(key)) {
target[key] = source[key];
}
}
}
return target;
}
function isLight(color) {
let hex = color.replace('#', '');
// convert #fff => #ffffff
if(hex.length == 3){
hex = `${hex[0]}${hex[0]}${hex[1]}${hex[1]}${hex[2]}${hex[2]}`;
}
const c_r = parseInt(hex.substr(0, 2), 16);
const c_g = parseInt(hex.substr(2, 2), 16);
const c_b = parseInt(hex.substr(4, 2), 16);
const brightness = ((c_r * 299) + (c_g * 587) + (c_b * 114)) / 1000;
return brightness > 155;
}
var bgColor = getComputedStyle(document.documentElement).getPropertyValue('--r-background-color').trim();
var isLight = isLight(bgColor);
if(isLight){
document.body.classList.add('has-light-background');
} else {
document.body.classList.add('has-dark-background');
}
// default options to init reveal.js
var defaultOptions = {
controls: true,
progress: true,
history: true,
center: true,
transition: 'default', // none/fade/slide/convex/concave/zoom
plugins: [
RevealMarkdown,
RevealHighlight,
RevealZoom,
RevealNotes,
RevealMath.MathJax3,
RevealMermaid,
RevealChart,
RevealCustomControls,
RevealMenu,
],
allottedTime: 120 * 1000,
mathjax3: {
mathjax: 'plugin/math/mathjax/tex-mml-chtml.js',
},
markdown: {
gfm: true,
mangle: true,
pedantic: false,
smartLists: false,
smartypants: false,
},
mermaid: {
theme: isLight ? 'default' : 'dark',
},
customcontrols: {
controls: [
]
},
menu: {
loadIcons: false
}
};
// options from URL query string
var queryOptions = Reveal().getQueryHash() || {};
var options = extend(defaultOptions, {"width":960,"height":700,"margin":0.04,"controls":true,"progress":true,"slideNumber":true,"transition":"slide","transitionSpeed":"default"}, queryOptions);
</script>
<script>
Reveal.initialize(options);
</script>
</body>
<!-- created with Advanced Slides -->
</html>