TY - JOUR
T1 - When long jumps fall short
T2 - control-flow tracking and misuse detection for nonlocal jumps in C: Extended version
AU - Erhard, Julian
AU - Schwarz, Michael
AU - Vojdani, Vesal
AU - Saan, Simmo
AU - Seidl, Helmut
N1 - Publisher Copyright:
© The Author(s) 2024.
PY - 2024/10
Y1 - 2024/10
N2 - The C programming language offers setjmp/ longjmp as a mechanism for nonlocal control flow. This mechanism has complicated semantics. As most developers do not encounter it day-to-day, they may be unfamiliar with all its intricacies – leading to subtle programming errors. At the same time, most static analyzers lack proper support, implying that otherwise sound tools miss whole classes of program deficiencies. We propose a concrete semantics of a subset of C with setjmp/ longjmp, where interprocedural longjmps are performed directly, as well as an equivalent formulation where such jumps are implemented via stack-unwinding at the call-sites. Reflecting this semantic equivalence, we propose an approach for lifting existing interprocedural analyses to support setjmp/ longjmp and to flag their misuse. To deal with the nonlocal semantics, our approach leverages side-effecting transfer functions, which, when executed, may additionally trigger contributions for program points that are not static control-flow successors. We showcase our analysis on a real-world example and propose a set of litmus tests for other analyzers.
AB - The C programming language offers setjmp/ longjmp as a mechanism for nonlocal control flow. This mechanism has complicated semantics. As most developers do not encounter it day-to-day, they may be unfamiliar with all its intricacies – leading to subtle programming errors. At the same time, most static analyzers lack proper support, implying that otherwise sound tools miss whole classes of program deficiencies. We propose a concrete semantics of a subset of C with setjmp/ longjmp, where interprocedural longjmps are performed directly, as well as an equivalent formulation where such jumps are implemented via stack-unwinding at the call-sites. Reflecting this semantic equivalence, we propose an approach for lifting existing interprocedural analyses to support setjmp/ longjmp and to flag their misuse. To deal with the nonlocal semantics, our approach leverages side-effecting transfer functions, which, when executed, may additionally trigger contributions for program points that are not static control-flow successors. We showcase our analysis on a real-world example and propose a set of litmus tests for other analyzers.
KW - Abstract interpretation
KW - Side-effecting constraint systems
KW - Static analysis
KW - setjmp/ longjmp
UR - http://www.scopus.com/inward/record.url?scp=85202618924&partnerID=8YFLogxK
U2 - 10.1007/s10009-024-00764-z
DO - 10.1007/s10009-024-00764-z
M3 - Article
AN - SCOPUS:85202618924
SN - 1433-2779
VL - 26
SP - 589
EP - 605
JO - International Journal on Software Tools for Technology Transfer
JF - International Journal on Software Tools for Technology Transfer
IS - 5
ER -