Skip to content

Commit 6053aea

Browse files
nanasi880cyphar
authored andcommitted
Fix undefined behavior.
Do not accept setjmp return value as variable. Signed-off-by: Kazuki Hasegawa <[email protected]>
1 parent e42c219 commit 6053aea

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

libcontainer/nsenter/nsexec.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -980,8 +980,7 @@ void nsexec(void)
980980
* -- Aleksa "what has my life come to?" Sarai
981981
*/
982982

983-
current_stage = setjmp(env);
984-
switch (current_stage) {
983+
switch (setjmp(env)) {
985984
/*
986985
* Stage 0: We're in the parent. Our job is just to create a new child
987986
* (stage 1: STAGE_CHILD) process and write its uid_map and
@@ -995,6 +994,7 @@ void nsexec(void)
995994
bool stage1_complete, stage2_complete;
996995

997996
/* For debugging. */
997+
current_stage = STAGE_PARENT;
998998
prctl(PR_SET_NAME, (unsigned long)"runc:[0:PARENT]", 0, 0, 0);
999999
write_log(DEBUG, "~> nsexec stage-0");
10001000

@@ -1152,6 +1152,9 @@ void nsexec(void)
11521152
pid_t stage2_pid = -1;
11531153
enum sync_t s;
11541154

1155+
/* For debugging. */
1156+
current_stage = STAGE_CHILD;
1157+
11551158
/* We're in a child and thus need to tell the parent if we die. */
11561159
syncfd = sync_child_pipe[0];
11571160
if (close(sync_child_pipe[1]) < 0)
@@ -1323,6 +1326,9 @@ void nsexec(void)
13231326
*/
13241327
enum sync_t s;
13251328

1329+
/* For debugging. */
1330+
current_stage = STAGE_INIT;
1331+
13261332
/* We're in a child and thus need to tell the parent if we die. */
13271333
syncfd = sync_grandchild_pipe[0];
13281334
if (close(sync_grandchild_pipe[1]) < 0)
@@ -1377,7 +1383,7 @@ void nsexec(void)
13771383
}
13781384
break;
13791385
default:
1380-
bail("unknown stage '%d' for jump value", current_stage);
1386+
bail("unexpected jump value");
13811387
}
13821388

13831389
/* Should never be reached. */

0 commit comments

Comments
 (0)