Skip to content

[LAB6] 511558020 #520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions lab3/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,50 @@ const assert = require('assert');
const { Calculator } = require('./main');

// TODO: write your tests here

describe('Calculator', () => {

describe('exp', () => {
// 檢查 exp 方法在輸入 0、1 和 -1 時。
it('Calculate correctly', () => {
const calculator = new Calculator();
assert.strictEqual(calculator.exp(0), 1);
assert.strictEqual(calculator.exp(1), Math.exp(1));
assert.strictEqual(calculator.exp(-1), 1 / Math.exp(1));
});
// 檢查 exp 方法在Infinity(-) 時。
it('Calculate error', () => {
const calculator = new Calculator();
assert.throws(() => calculator.exp(NaN), Error);
assert.throws(() => calculator.exp(Infinity), Error);
assert.throws(() => calculator.exp(-Infinity), Error);
});
// 檢查 exp 方法在 overflow 時。
it('overflows', () => {
const calculator = new Calculator();
assert.throws(() => calculator.exp(9999), Error);
});
});

describe('log', () => {
// 檢查 log 方法在輸入 1 和 Math.E 時
it('calculate orrectly', () => {
const calculator = new Calculator();
assert.strictEqual(calculator.log(1), 0);
assert.strictEqual(calculator.log(Math.E), 1);
});
//檢查 log 方法在輸入 NaN、Infinity時
it('Calculate error', () => {
const calculator = new Calculator();
assert.throws(() => calculator.log(NaN), Error);
assert.throws(() => calculator.log(Infinity), Error);
assert.throws(() => calculator.log(-Infinity), Error);
});
// 檢查 log 方法在輸入 0 和 -1 時
it('negative infinity or NaN', () => {
const calculator = new Calculator();
assert.throws(() => calculator.log(0), Error);
assert.throws(() => calculator.log(-1), Error);
});
});
});
49 changes: 35 additions & 14 deletions lab4/main_test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
const puppeteer = require('puppeteer');

(async () => {
// Launch the browser and open a new blank page
// 啟動瀏覽器並打開一個新的空白頁面
const browser = await puppeteer.launch();
const page = await browser.newPage();
try{
// 導航至指定網址
await page.goto('https://pptr.dev/');


// Navigate the page to a URL
await page.goto('https://pptr.dev/');
// 點擊搜尋按鈕
await page.click('button.DocSearch.DocSearch-Button');


// Hints:
// Click search button
// Type into search box
// Wait for search result
// Get the `Docs` result section
// Click on first result in `Docs` section
// Locate the title
// Print the title
// 在搜尋框中輸入文字
await page.waitForSelector('#docsearch-input');
await page.type('#docsearch-input', 'chipi chipi chapa chapa', { delay: 1000 });


// Close the browser
await browser.close();
})();
// 等待搜尋結果
await page.waitForSelector('#docsearch-item-5');


// 點擊「Docs」部分的第一個結果
await page.click('#docsearch-item-5');


// 定位標題
await page.waitForSelector('h1');

// 獲取標題元素的文字內容
const title = await page.evaluate(() => {
const titleElement = document.querySelector('h1');
return titleElement.textContent;
});
console.log(title);
}catch(error){
console.error('An error occurred:', error);
}finally{
// 最後都會關閉瀏覽器
await browser.close();}
})();
46 changes: 44 additions & 2 deletions lab6/Answer.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,54 @@
Name:
ID:
Name: 劉珈佑
ID: 511558020

### Fuzz Monitor
```
american fuzzy lop 2.57b (bmpcomp)

┌─ process timing ─────────────────────────────────────┬─ overall results ─────┐
│ run time : 0 days, 0 hrs, 2 min, 2 sec │ cycles done : 0 │
│ last new path : 0 days, 0 hrs, 0 min, 28 sec │ total paths : 18 │
│ last uniq crash : 0 days, 0 hrs, 1 min, 54 sec │ uniq crashes : 1 │
│ last uniq hang : none seen yet │ uniq hangs : 0 │
├─ cycle progress ────────────────────┬─ map coverage ─┴───────────────────────┤
│ now processing : 0 (0.00%) │ map density : 0.04% / 0.05% │
│ paths timed out : 0 (0.00%) │ count coverage : 2.12 bits/tuple │
├─ stage progress ────────────────────┼─ findings in depth ────────────────────┤
│ now trying : arith 16/8 │ favored paths : 1 (5.56%) │
│ stage execs : 468/2599 (18.01%) │ new edges on : 4 (22.22%) │
│ total execs : 2962 │ total crashes : 121 (1 unique) │
│ exec speed : 44.27/sec (slow!) │ total tmouts : 369 (7 unique) │
├─ fuzzing strategy yields ───────────┴───────────────┬─ path geometry ────────┤
│ bit flips : 7/224, 3/223, 1/221 │ levels : 2 │
│ byte flips : 0/28, 0/27, 0/25 │ pending : 18 │
│ arithmetics : 7/1565, 0/0, 0/0 │ pend fav : 1 │
│ known ints : 0/0, 0/0, 0/0 │ own finds : 17 │
│ dictionary : 0/0, 0/0, 0/0 │ imported : n/a │
│ havoc : 0/0, 0/0 │ stability : 100.00% │
│ trim : 100.00%/37, 0.00% ├────────────────────────┘
└─────────────────────────────────────────────────────┘ [cpu010: 7%]

```

### Run Crash Result
```
+++ Testing aborted by user +++
[+] We're done here. Have a nice day!

(Lab6) liu@MSI:~/112-spring-software-testing-and-secure-programming/lab6/fuzz$ ls out/
crashes fuzz_bitmap fuzzer_stats hangs plot_data queue
(Lab6) liu@MSI:~/112-spring-software-testing-and-secure-programming/lab6/fuzz$ ls out/crashes/
README.txt id:000000,sig:06,src:000000,op:flip1,pos:20
(Lab6) liu@MSI:~/112-spring-software-testing-and-secure-programming/lab6/fuzz$ ../src/bmpcomp . /out/crashes/id\:000000,sig:06,src:000000,op:flip1,pos:20
size of Herder 54
AddressSanitizer:DEADLYSIGNAL
=================================================================
==208984==ERROR: AddressSanitizer: stack-overflow on address 0x7ffd201229f8 (pc 0x556e8c08f11f bp 0x7ffd20920e50 sp 0x7ffd20121a00 T0)
#0 0x556e8c08f11f in main /home/liu/112-spring-software-testing-and-secure-programming/lab6/src/hw0302.c:46
#1 0x7f037a105d8f (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f)
#2 0x7f037a105e3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f)
#3 0x556e8c08fc24 in _start (/home/liu/112-spring-software-testing-and-secure-programming/lab6/src/bmpcomp+0x2c24)

SUMMARY: AddressSanitizer: stack-overflow /home/liu/112-spring-software-testing-and-secure-programming/lab6/src/hw0302.c:46 in main
==208984==ABORTING
```
Loading