Demo to see how compiler optimization can introduce security vulnerabilities

Took a module under Dr Roland Yap, CS4239 Software Security, at my alma mater NUS (National University of Singapore) School of Computing, back in 2017 Semester 1. It was part of its Lifelong Education programme, under SCALE (School of Continuing and Lifelong Education), where modules were opened up to the general public. One interesting lesson …

When an object is assigned to a variable, will modifying the variable modify the original object?

This is similar to the previous blog post except this is more direct. The answer is “Yes” for all tested languages except C and C++. This may seem trivial until you meet a situation where the same original object is shared across requests/sessions, like a public static variable in Java or an incorrectly scoped Javascript …

Does modifying objects passed in to functions modify original object?

As per title, ran this across various languages. Results are mixed, but IMHO, it seems unsafe to design your functions/methods this way. It would be better to pass in the object, compute the changes without modifying the object, return the computed changes and assign it back to the original variable. Below are sample code snippets …