Programming Paradigms Final

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/133

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

134 Terms

1
New cards

What do pointer types store?

Memory addresses and NULL (provides indirect addressing)

2
New cards

What is a dangling pointer?

A pointer that points to a heap-dynamic variable that has been deallocated

3
New cards

What is a lost heap-dynamic variable?

A heap-dynamic variable that is no longer accessible to the user program (AKA garbage). The process of losing these variables is called memory leakage.

4
New cards

Does C check array bounds?

No, C does not check array bounds

5
New cards

Does Java check array bounds?

Yes, Java is strongly typed and enforces bounds

6
New cards

What is coercion in type checking?

Implicit/automatic conversion from one type to another

7
New cards

When is static type checking done?

At compile time

8
New cards

When is dynamic type checking done?

At run time

9
New cards

What is explicit static type binding?

Program statement used to declare the types of variables

10
New cards

What is implicit static type binding?

Specifies types through default conventions; provides greater writability but less reliability

11
New cards

What are the characteristics of dynamic type binding?

Flexible, but high in cost and difficult to detect errors

12
New cards

What is a buffer overflow?

When a program writes more data to a block of memory or buffer than it was allocated for

13
New cards

Describe the stack smashing process

1) Buffer overflow - excess data flows into adjacent memory, 2) Overwriting control data - overflow overwrites critical control data, 3) Manipulating program flow - redirects program's execution flow, 4) Execution of arbitrary code - introduces attacker's own code

14
New cards

List 5 ways to prevent stack smashing

1) Bounds checking, 2) Safe string functions (strncpy vs strcpy), 3) Address space randomization, 4) Stack Canaries, 5) Non-executable stack

15
New cards

What are stack canaries?

Random values placed between buffer and control data, used to flag if there's an overflow

16
New cards

How do you prevent format string vulnerabilities? (List 5 methods)

1) Avoid user-controlled format strings, 2) Validate and sanitize input, 3) Use explicit format strings, 4) Limit permissions, 5) Static code analysis

17
New cards

What is RAD (Return Address Defender)?

Saves copies of a function's return address; checks when a function finishes

18
New cards

What does DEP (Data Execution Prevention) do?

Makes stack and heap non-executable

19
New cards

What are gadgets in ROP (Return Oriented Programming)?

Operations where complex code is transformed into a sequence of primitive operations

20
New cards

Describe a Ret2LibC attack

1) Exploit buffer overflow to overwrite return address, 2) Set return address (EIP) to a function in LibC, 3) Prepare fake stack frame with arguments, 4) Program returns to LibC function and executes with attacker's arguments

21
New cards

What are the three main Java security components?

1) Class loaders (sandbox), 2) Bytecode verifier, 3) Security manager (policy and enforcement)

22
New cards

What are the three types of Cross-Site Scripting (XSS)?

1) Reflected XSS: sent in url and reflected onto page

2) Stored XSS: persistent in server, shown to every visitor most dangerous

3) DOM XSS: javascript on the page itself does damage

23
New cards

What are two solutions to XSS attacks?

1) SOP (Same Origin Policy), 2) Secure Input Handling (Encoding & Validation)

24
New cards

What is the key property of functional programming regarding side effects?

No side effects - output depends only on inputs, functions change nothing in the evaluation, can be evaluated in any order

25
New cards

How are complex functions built in functional programming?

Based on recursion

26
New cards

List the historical progression of functional programming languages

Lambda calculus (1930s) → Lisp (1950s) → Meta Language (1970s) → Haskell (1990s) → Python, Scala, Java, C++

27
New cards

What are the three key properties of Lambda Calculus?

1) Anonymous, 2) Immutable, 3) First-class citizen (functions treated like other variables)

28
New cards

What does 'cons' do in list processing?

Takes an element and adds the element to front of list

29
New cards

What does 'car' do in list processing?

Retrieves the 1st element in list/pair

30
New cards

What does 'cdr' do in list processing?

Retrieves rest of elements in a list/pair after 1st element

31
New cards

What does 'append' do?

Concatenates lists

32
New cards

What does 'map' do?

Applies a given function to each element of a list and returns the new list

33
New cards

What does 'filter' do?

Applies a given predicate function to each element of a list and returns a new list containing only true elements

34
New cards

What does 'foldl' do?

Applies a given binary function to the elements cumulatively, reduces to single value

35
New cards

How many arguments does 'if' take in Racket?

3 arguments (must have else)

36
New cards

How many arguments does 'when' take in Racket?

2 arguments (no else)

37
New cards

What does 'for/list' do?

Accumulates body results into a list

38
New cards

What does 'for*' do?

Nests multiple clauses instead of running them in parallel

39
New cards

Difference between 'display' and 'print' output functions?

Display - human-readable, no quotes; Print - Racket readable, adds quotes

40
New cards

Difference between 'printf' and 'write' output functions?

Printf - human-readable, like display. NOT SAFE!; Write - C++ readable, like print. SAFER!

41
New cards

What does 'eval' do?

By default 1st list element is evaluated as a function, remainder of elements are arguments to that function

42
New cards

What does 'let' do?

Binds variables to values within a specific block of code

43
New cards

What does 'begin' do?

Groups multiple expressions into a single body

44
New cards

What are the key paradigms of logic programming?

Rules, Declarative nature, Inference and Backtracking, Pattern Matching, Non-Procedural Symbolic Reasoning

45
New cards

What are Prolog clauses?

Unit of logic programming made of facts and rules

46
New cards

What are facts in Prolog?

Statements about relationships between entities (Ex: happy(Bob))

47
New cards

What are rules in Prolog?

Express relationships based on conditions (Ex: eatsPizza(Bob) :- happy(Bob))

48
New cards

What are predicates in Prolog?

A logical statement defining a condition or property

49
New cards

What is arity in Prolog?

The number of arguments taken by a predicate

50
New cards

How are variables denoted in Prolog?

Using capital letter or underscore

51
New cards

What can an underscore alone be used for in Prolog?

As a placeholder

52
New cards

What operator is used for conjunction in Prolog?

, (comma)

53
New cards

What operator is used for disjunction in Prolog?

; (semicolon)

54
New cards

What operator is used for implication in Prolog?

:- (colon-dash)

55
New cards

What is unification in Prolog?

The process of finding substitutions for variables in order to make two terms identical (using the given rules)

56
New cards

What search strategy does Prolog use?

Depth-first search strategy with backtracking

57
New cards

Is the order of clauses important in Prolog?

Yes, the order of clauses is crucial

58
New cards

How are lists constructed in Prolog?

Using the Head (1st element of list) and Tail (the rest of the list)

59
New cards

What is the cut operator in Prolog?

! (exclamation mark) - Prevents backtracking over specific branches

60
New cards

What does \+ represent in Prolog?

Negation (the absence of whatever is specified)

61
New cards

What is the scope of a variable in Prolog?

A single clause (fact or rule) or a single query

62
New cards

What inference method does Prolog use?

Backward chaining

63
New cards

What is the use of "is" in Prolog?

Arithmetic evaluation

64
New cards

Can the cut (!) in Prolog be backtracked?

No, it always succeeds but cannot be backtracked

65
New cards

In return-oriented programming, can a return from a hijacked function be controlled by the hijacker?

TRUE (the hijacker CAN control returns)

66
New cards

How can a stack buffer overflow hijack the control flow of a program?

By overwriting the return address AND function pointer on the stack

67
New cards

How may an attacker overflow the buffer in ROP?

By appending 1 or more fake calling frames

68
New cards

In ROP, is it possible to invoke an arbitrary function by placing a fake frame in stack memory?

TRUE

69
New cards

What checks code fragments for illegal code in Java?

Bytecode verifier

70
New cards

In CFI, do direct calls to functions need to be monitored?

FALSE, only indirect

71
New cards

Which statement is WRONG about orchestrating gadgets in ROP?

"Some gadgets can be injected onto the stack" (gadgets are found in existing code, not injected)

72
New cards

What leads to portability and security of Java?

Bytecode is executed by JVM

73
New cards

Do sandbox restrictions provide strict limitations on system resources an applet can access?

TRUE

74
New cards

In hardware-enforced NX bit, can the EIP jump to executable regions?

TRUE

75
New cards

Can lambda special form be used to define anonymous functions in Lisp?

TRUE!

76
New cards

What is the output of: (cons (car '(a b)) (cdr '(p q)))?

'(a q)

77
New cards

Are functions considered first-class citizens in functional programming?

Yes - they can be passed as arguments, returned as results, and assigned to names

78
New cards

Output of: (define (b p) (+ p p)) (define z 1) (b z)?

2

79
New cards

Output of:

(define thing 'sphere)
(define r 2)

(cond
  [(eq? thing 'circle)
   (3 r r)]
  [else
   (4 3 r r)])

48

80
New cards

Output of: (define (multiply p q) (* p q)) (cons 4 (multiply 2 4))?

'(4 . 8)

81
New cards

Output of: (define x 'outside) (let ((x 'inside) (y x)) (list x y))?

'(inside outside)

82
New cards

Output of: (define (aaa-x x) (lambda(y)(+ x y))) (define add-d (aaa-x 7)) (add-d 15)?

22

83
New cards

Output of: (define whole-list '(monday tuesday wednesday thursday friday)) (define (mystery) (cons (first whole-list) (last whole-list))) (mystery)?

'(monday . friday)

84
New cards

Write the addition of four numbers using maximum possible braces?

(+ (+ 1 2) (+ 3 4))

85
New cards

For ?-[[X,Y],Z|R] = [[a,b],[1,2],[c,d]], which binding applies?

X=a, Y=b, Z=[1,2], R=[[c,d]]

86
New cards

Output of: ?- f(a,b) = f(Y,X)?

X=b, Y=a

87
New cards

Which returns true? boy(john,123). girl(jane,234). student(john,123).

boy(john, 123)

88
New cards

What does r(X, Y) :- parent(Z,X), parent(Z,Y), male(X), X \= Y represent?

X is the brother of Y

89
New cards

What are call stacks used for?

Save execution status of the caller, pass parameters, pass return address to the callee, transfer control to the callee

90
New cards

What is the purpose of a bytecode verifier in Java?

Checks code fragments for illegal code

91
New cards

What does SOP stand for?

Same Origin Policy

92
New cards

What library attack exploits buffer overflow?

Ret2LibC (Return to LibC)

93
New cards

What makes Java code portable?

Bytecode is executed by JVM (Java Virtual Machine)

94
New cards

What does NX bit stand for?

Non-executable bit (prevents code execution in certain memory regions)

95
New cards

What is the purpose of address space randomization?

Makes it harder for attackers to predict memory addresses for exploits

96
New cards

Difference between static and dynamic type binding?

Static - done at compile time; Dynamic - done at run time

97
New cards

What is garbage in programming?

Lost heap-dynamic variables that are no longer accessible

98
New cards

What does CFI stand for?

Control Flow Integrity

99
New cards

What is the main advantage of functional programming?

No side effects, making code more predictable and easier to reason about

100
New cards

What does "first-class citizen" mean for functions?

Functions can be treated like any other variable - passed as arguments, returned from functions, assigned to names