United States Na val Academy Electrical and … exams/EC312Spring2018...EC312 Six Week Exam Spring...

Post on 23-Apr-2020

2 views 0 download

Transcript of United States Na val Academy Electrical and … exams/EC312Spring2018...EC312 Six Week Exam Spring...

EC312 Six Week Exam Spring 2018 February 15th, 2018

United States Na val Academy Electrical and Computer Engineering Department

EC312 - 6 Week Midterm - Spring 2018

1. Do a page check: you should have 6 pages including this cover sheet. 2. You have 50 minutes to complete this exam. 3. An FE-approved calculator may be used for this exam. Calculators may not be shared. 4. This is a closed book and closed notes exam. You may use one single-sided hand-written page of notes. 5. Turn in your single-sided hand-written page of notes with your exam. 6. This exam may be given as a makeup exam to several midshipmen at a later time. No communication is

permitted concerning this exam with anyone who has not yet taken the exam.

Name:

Instructor:

hex digit 0 4-bit pattern 0000

Qec

32 33 34 35 36 37 32 39 .; o 41 42

1 2 0001 00 10

2 22 23

25 26

7

8 29 2a

C?-:ar

&

3 4 5

0011 0100 010 1

Cec

0 2c 2d 2e

42 3:, .; 9 3:.

so 3 51 33 52 34 53 35

C~ar

)

3 4 5

6 7 8

01 10 011 1 1000

5" S6

5a 59 c 61 62 63 64

Eex 3E

r 33 39 3a 3c

.:!:ar

~c < 3d 3e > 3= ?

9

100 1

ES 66 co-E3 E9

2 13

a b

1010 1011

C!-:ar .;: 42

4E

4a

B

c ['

E

Wee Eex ,....har Dec Eex .,::!;,ar J:.:.;o. Eex 2r.a.r [:::.r ::ex c:;.ar 2..., 5'" :-1 92 £: o :.:s E:i m :.2: -e x

88 29 9C 91 92 93 9.;

58 x 59 y Sa Z Sb Sc Sd Se

99 100

01 102 1J3 104 105

63 6-: ES 66 6-68 69

c d e

g h i

_J6 fa 1 ~ -- ~ I 6C k

6c 1

::.1 :.12 113

:.:.s

::9

Ee r.

6:: 0

!:> q r

::.

7a z 123

24 :2 5 126

c

11 00

Cec

E3

26

d e I f

11 01 111 01 1111

Ee:..: :.·:-.ar

.;d !!

.; : c c;)

s:

53

s: 56

s

Page 1of6

EC312 Six Week Exam Spring 2018 February 15th, 2018

Question 1. a) (4 pts) For the given circuit fill in the truth table where 0 is OV and 1 is 5V.

A B Out -sv

0 0 I

0 \ ()

I 0 0

I ( 0

A

b) (2 pts) Determine the logic function the circuit performs. Logic function: ~0(2.-

-~~-----

Question 2. For the logic circuit shown below: a) (6 pts) Complete the truth table.

A w

B

c

A 0 0 0 0 1 1 1

y I

B c 0 0 o. 1 1 0 1 1 0 0 0 1 1 0 I I

b) (4 pts) Determine the Boolean expression for the output Zin terms of A, B & C.

w x y z I l 0 1 I I 0 \

' \ b \

' l \ 0 ~ 0 n I

t> 0 0 I

0 \ 0 \ 0 I I ()

Page 2 of 6

EC312 Six Week Exam Spring 2018 February 15th, 2018

Question 3. a) (3 pts) What is the danger with the following code snippet? int x=5 ; int array[ SJ={ 1,2,3,4,5}; array[7]=1 O;

o. \lo ~h.J .S fX'UL h_,. 5 e~b c...V\J

\(ov l,vr •~ h,

b) (3 pts) What feature of C allows this to happen?

t.~r--0\-1- f!, .:i? y(.)u.. l.oJJ ()..J<..>V-v.>r ."-k :g;,,,. ... ~Jt11!.i.J c..Lc_,

(_ ~u no.\- vu)-.,_{ ~.., ...... Jc.,..;~s, Question 4. (10 pts) What will be the output of this program when it is compiled and run?

#include <stdio .. h> int main ()

0 I Z 5 '-/ S int counter [ 10 ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ; int i;

for ( i = 5 ; i >= O; i =i- 2) {

if (i >l) printf( " %d\n", counter[i]) ;

else printf( " Go Navy\n " ) ;

. }

Question 5. (a) (8 pts) Fill in the blanks

The setuid flag allows other users to execute a program with the same permissions as

Sudo allows a user to act as 1 o ~ r for one command. ------

Write out the exact gdb command you would use to look at four bytes of memory iq hexadecimal starting at the address which esp points to: 2< / L-4 '/. b 4 ~f or x/xL.J f e...y

The Cq, ~ command displays the contents of a file but does not enable editing the file .

(b) (6 pts) If midshipman is part of group mids and class, what permissions does midshipman have

on the follkwinj file? - rwxr - x -- 1 coordinator instructo r 542 2018 - 01-24 02 :4 3 grader .. exe

Page 3 of 6

EC312 Six Week Exam Spring 2018 February 15th, 2018

Question 6. Consider the C program below. The program is run up to a breakpoint on line 9. 1 #include<stdio.h> 2 #include<string.h> 3 int getinfo() 4 5 6 7 8 9

int number=O; printf("\nEnter your company number " ) ; scanf ( " %d", number) ; return number;

10 int main () 11 12 13 14 15 16 17 18 19 20 21

int x =27 ; char name[20]="USNA"; int company=30 ; int i ;

printf ("%s ", name); printf (" \nEnter your name : "); scanf ("%s" , name) ; getinfo();

(a) (3 pts) How much memory in bytes, must the compiler set aside for the main function assuming no

padding? Lf + -z_o 4- y + lf, -=- 3 1 b1.;w I

7' n4~ (¥1'\f<~ .1

(b) (8 pts) Fill out this sketch of the stack at this point in program execution, including each item's name and size.

t--~~~~~~~~~....,..,..,r+-~~~~---;

esp_ main points here

~~~~~~~~~~~~~~~~~

ebp _main points here

( c) (3 pts) When the user enters their name what is the maximum number of characters they can enter in the variable name without overwriting any other variable? Explain.

' 1

(d) (5 pts) Which variable(s) are not vulnerable to being overwritten by buffer overflow? Explain . •

0.\,\_v"'\.W 1 1 /

(_oM p~" ! Page 4 of 6

EC312 Six Week Exam Spring 2018 February XX, 2018

Continued from the code on the previous page, you compile the program and running gdb you get the following

screen:

(e) (6 pts) How big is the stack the compiler created? 17 3

b ~+ ~ ~ ,2 t g- l b

- b ~~~-\:(c.O ' 5 ~ 0

+ q-

jYfblfu j (f) (6 pts) Which memory location stores company? (This should be a hexadecimal number)

7 /(. Z"j

30 ~7 I e e_ b F - roo b Pt f= ~ g,n; 10 f(o

~01/ J C11.,

(g) (4 pts) What is the next assembly instructi o e executed?

L \f'-? O <{ ()LI '6 5 b 2 - ) \Y\cV U~RD

Page 5 of 6

EC312 Six Week Exam Spring 2018 February XX, 2018

Qu~<,tion 7. ( un..,tlkr the C program bclo\\ .

line 15.

\ s..,umc no padding. The progrnm j.., run up lo a hn:al,point 1111

\cl d IT..,S \ a luc l)eq: npt11111

-'11.P<'s:..u1c . h>

r. ... -~·-'- :r~r...:i . . 1 lJ\BI I I I 8%

nr r 1-:11 ... 1 J ( :!.r. .... :--:=2S l ; ChBI I I 1· 898 -t &'

char nam '. '~; " [J~Nl\ " ; I"

'Odr 'f"' I ;d:.• ; lhBI I 11 89<>

ll\131 I I HilJ \ ") ..

I I.

f ' ' ... .... f' J • II f (l\BI I I I l\ll( l I! < ( ,. ..J

4 ,.. II .· fl\ 131 I I I 8 <l I) ;xr ') ~

tl\lll I I I 81!1

tal r8 pl J \\ hm 1.., th\.' output nfthc print!'. tatL'l11C111 \)Jl

line I Y.' Shu\\ :111\ ''nrh. in the Value column . lh.ll l I I I ~NI

)Y ,,..

/rJ

u lh.HI 11 I 8 \fl / /1

()\ B I I r· r 8 \ I 01 )) I' ---

( b) t 6 ph l \\ hat i · the output o !'the pri ntf. talcment on 0' line J.r.1

, .. ,plain tl\1311 I I 8 \3

L VJ 11,ll l I I I 8 \ ·

+ l l l\ r l r t 1> I O\.l~I I I I 8 \ "

~ ,..

r- I CJ;. , to;--(' Jf I" t , ..

::;.) 'f- ~ v

Qul'~tion 8. (::' pb I I ist and describe a technical uluti11n ag.1111'-l ii hunl.·r ti\ L'rllP\\ ~1ttack

I

t

Tu1·11 in) our l'lJLlalio11 -,hcl'I "ith .'o ur C\alll!

Page 6 of 6