lab0-c icon indicating copy to clipboard operation
lab0-c copied to clipboard

In qtest.c, using non-reentrant function in signal handler can lead to unpredictable result.

Open soyWXY opened this issue 3 years ago • 2 comments

In sigsegvhandler(), report() is called, which invocates non-reentrant stdio functions.

I check signal-safety(7) — Linux manual page to determine whether a function is reentrant, and I wonder if this should be taken into consideration in this case.

In my opinion, using write() to stderr to replace stdio functions might be a solution.

soyWXY avatar Sep 05 '22 15:09 soyWXY

@soyWXY , vfprintf would internally call write, thus, there is no need to consider reentrant issue in this case. Also, I suppose this lab would not raise reentrant problem. If there is no other concern, I will close the issue.

eecheng87 avatar Sep 06 '22 12:09 eecheng87

First, stdio is non-reentrant for some reasons. Explanation is in the second and third paragraph in description section over here. Further, stdio call might implicitly invocate malloc() which is also non-reentrant, so it is better to check the manual to determine if a library function is reentrant.

Second, about this lab, I'll say if any stdio function triggers SIGSEGV, the non-reentrant problem is raised, and formatted output can possibly do that.

soyWXY avatar Sep 07 '22 14:09 soyWXY