This shows you the differences between two versions of the page.
cns:labs:lab-12 [2017/01/15 15:05] lucian.mogosanu [Identifying the problem] |
cns:labs:lab-12 [2019/12/08 15:18] (current) dennis.plosceanu |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Lab 12 - Integers ====== | + | ====== Extra - Integers ====== |
===== Resources ===== | ===== Resources ===== | ||
Line 18: | Line 18: | ||
Please download the lab archive an then unpack it using the commands below: | Please download the lab archive an then unpack it using the commands below: | ||
<code bash> | <code bash> | ||
- | student@mjolnir:~$ wget http://elf.cs.pub.ro/oss/res/labs/lab-12.tar.gz | + | student@asgard:~$ wget http://elf.cs.pub.ro/oss/res/labs/lab-12.tar.gz |
- | student@mjolnir:~$ tar xzf lab-12.tar.gz | + | student@asgard:~$ tar xzf lab-12.tar.gz |
</code> | </code> | ||
After unpacking we will get the ''lab-12/'' folder that we will use for the lab: | After unpacking we will get the ''lab-12/'' folder that we will use for the lab: | ||
<code bash> | <code bash> | ||
- | student@mjolnir:~$ cd lab-12/ | + | student@asgard:~$ cd lab-12/ |
- | student@mjolnir:~/lab-12$ ls -F | + | student@asgard:~/lab-12$ ls -F |
1-overflow/ 2-comparison/ 3-sts7/ 4-sts2/ 5-sts2_alt/ | 1-overflow/ 2-comparison/ 3-sts7/ 4-sts2/ 5-sts2_alt/ | ||
</code> | </code> | ||
+ | |||
+ | ===== 0. Feedback ===== | ||
+ | |||
+ | In order to improve the Computer Network Security course, your opinions and suggestions are important to us. The feedback is anonymous and the results will only become visible after the final exam. You will find the link to the feedback form on the main page of the curs.pub.ro instance for your master's program CNS class (either PDCS or SRIC). It's **not** in the meta-course for all students. | ||
===== Introduction ===== | ===== Introduction ===== | ||
Line 49: | Line 53: | ||
First take a look at the source code in ''overflow.c''. The program receives two arguments ''num1'' and ''num2'' that are then intepreted to integers using [[http://man7.org/linux/man-pages/man3/atoi.3.html|atoi]]. Use a different terminal tab to try some sample runs of the program:<code> | First take a look at the source code in ''overflow.c''. The program receives two arguments ''num1'' and ''num2'' that are then intepreted to integers using [[http://man7.org/linux/man-pages/man3/atoi.3.html|atoi]]. Use a different terminal tab to try some sample runs of the program:<code> | ||
- | student@asgard:~/lab-08/1-overflow$ ./overflow 10 50 | + | student@asgard:~/lab-12/1-overflow$ ./overflow 10 50 |
- | student@asgard:~/lab-08/1-overflow$ ./overflow 100 200 | + | student@asgard:~/lab-12/1-overflow$ ./overflow 100 200 |
Input number too small. | Input number too small. | ||
- | student@asgard:~/lab-08/1-overflow$ ./overflow 1500 1500 | + | student@asgard:~/lab-12/1-overflow$ ./overflow 1500 1500 |
Input number too small. | Input number too small. | ||
</code> | </code> | ||
Line 77: | Line 81: | ||
**[1.5p]** Update the ''overflow.c'' file accordigly, and then recompile it using<code> | **[1.5p]** Update the ''overflow.c'' file accordigly, and then recompile it using<code> | ||
- | student@asgard:~/lab-08/1-overflow$ make | + | student@asgard:~/lab-12/1-overflow$ make |
</code> | </code> | ||
Then feed it different arguments and prove that now it behaves correctly. | Then feed it different arguments and prove that now it behaves correctly. | ||
Line 86: | Line 90: | ||
===== 2. [2.5p] Signed/unsigned comparison ===== | ===== 2. [2.5p] Signed/unsigned comparison ===== | ||
- | For our first task, let's investigate how comparison between signed and unsigned values results in unwelcomed program behavior. | + | For our second task, let's investigate how comparison between signed and unsigned values results in unwelcomed program behavior. |
Please access the ''2-comparison/'' subfolder in the lab archive. It consists of three files: a ''Makefile'', a C source code file dubbed ''comparison.c'' and the resulting executable (ELF) file on a 32-bit system ''comparison''. | Please access the ''2-comparison/'' subfolder in the lab archive. It consists of three files: a ''Makefile'', a C source code file dubbed ''comparison.c'' and the resulting executable (ELF) file on a 32-bit system ''comparison''. | ||
First take a look at the source code in ''comparison.c''. The program receives an argument ''x1'' that is then intepreted as an integer using [[http://man7.org/linux/man-pages/man3/atoi.3.html|atoi]]. Use a different terminal tab to try some sample runs of the program:<code> | First take a look at the source code in ''comparison.c''. The program receives an argument ''x1'' that is then intepreted as an integer using [[http://man7.org/linux/man-pages/man3/atoi.3.html|atoi]]. Use a different terminal tab to try some sample runs of the program:<code> | ||
- | student@asgard:~/lab-08/2-comparison$ ./comparison 10 | + | student@asgard:~/lab-12/2-comparison$ ./comparison 10 |
0x0000000a | 0x0000000a | ||
- | student@asgard:~/lab-08/2-comparison$ ./comparison 100 | + | student@asgard:~/lab-12/2-comparison$ ./comparison 100 |
0x00000064 | 0x00000064 | ||
- | student@asgard:~/lab-08/2-comparison$ ./comparison 1000 | + | student@asgard:~/lab-12/2-comparison$ ./comparison 1000 |
0x000003e8 | 0x000003e8 | ||
- | student@asgard:~/lab-08/2-comparison$ ./comparison -10 | + | student@asgard:~/lab-12/2-comparison$ ./comparison -10 |
0xfffffff6 | 0xfffffff6 | ||
- | student@asgard:~/lab-08/2-comparison$ ./comparison -100 | + | student@asgard:~/lab-12/2-comparison$ ./comparison -100 |
0xffffff9c | 0xffffff9c | ||
- | student@asgard:~/lab-08/2-comparison$ ./comparison -1000 | + | student@asgard:~/lab-12/2-comparison$ ./comparison -1000 |
0xfffffc18 | 0xfffffc18 | ||
</code> | </code> | ||
Line 111: | Line 115: | ||
The hexadecimal representation of ''x2'' may be shown using a Python script:<code> | The hexadecimal representation of ''x2'' may be shown using a Python script:<code> | ||
- | student@asgard:~/lab-08/2-comparison$ python -c 'print hex(2147483649)' | + | student@asgard:~/lab-12/2-comparison$ python -c 'print hex(2147483649)' |
0x80000001 | 0x80000001 | ||
</code> | </code> | ||
Line 126: | Line 130: | ||
<note tip> | <note tip> | ||
There are multiple ways to achieve this. Choose any that results in the program behaving correcty, that is, getting the following output:<code> | There are multiple ways to achieve this. Choose any that results in the program behaving correcty, that is, getting the following output:<code> | ||
- | student@asgard:~/lab-08/2-comparison$ ./comparison -10 | + | student@asgard:~/lab-12/2-comparison$ ./comparison -10 |
0xfffffff6 | 0xfffffff6 | ||
That looks quite odd, doesn't it? | That looks quite odd, doesn't it? | ||
- | student@asgard:~/lab-08/2-comparison$ ./comparison -100 | + | student@asgard:~/lab-12/2-comparison$ ./comparison -100 |
0xffffff9c | 0xffffff9c | ||
That looks quite odd, doesn't it? | That looks quite odd, doesn't it? | ||
- | student@asgard:~/lab-08/2-comparison$ ./comparison -1000 | + | student@asgard:~/lab-12/2-comparison$ ./comparison -1000 |
0xfffffc18 | 0xfffffc18 | ||
That looks quite odd, doesn't it? | That looks quite odd, doesn't it? |