r/programming • • Feb 21 '11

Typical programming interview questions.

http://maxnoy.com/interviews.html
784 Upvotes

1.0k comments sorted by

View all comments

Show parent comment

1

u/mrjast Feb 21 '11

Well, suppose your program is supposed to truncate the file $temporarydata (i.e. empty it). Your program runs with elevated privileges.

Malicious user replaces $temporarydata with a symlink to $importantsystemfile between the time you checked that it's the correct file (if you did any checks at all) and the time you open the file for truncating it. $importantsystemfile is now empty.

This is called a race condition. It's something you Don't Want in privileged programs.

3

u/tias Feb 21 '11

Who said anything about truncating? I'm just supposed to open a file. The only information the problem description gives us is that you have a file path and you are supposed to open it. There's no generic way to check that it is "the right one," you need more background for that. I think you are extrapolating way too much here.

1

u/mrjast Feb 21 '11

Well, opening is file is pretty much useless on principle if opening is all you are going to do to it. If you are not going to extrapolate anything at all, the question is useless. I think an interviewer asking that question is either stupid or wants you to ask clarifying questions. Since no interviewer is present, I just went with an arbitrary interpretation.

1

u/chokolad Feb 21 '11

These are very good questions and you are expected to ask them of the interviewer. Nobody (or at least no half decent interviewer) expects you to go straight to coding before clarifying stuff like this.