浏览代码

ensure valid setxid return value in an unexpected error case

If __synccall() fails to capture all threads because tkill fails for
some reason other than EAGAIN, then the callback given will never be
executed, so nothing will ever overwrite the initial value. So that is
the value that will be returned from the function. The previous setting
of 1 is not a valid value for setuid() et al. to return.

I chose -EAGAIN since I don't know the reason the synccall failed ahead
of time, but EAGAIN is a specified error code for a possibly temporary
failure in setuid().
Markus Wichmann 1 年之前
父节点
当前提交
7bb11f75c5
共有 1 个文件被更改,包括 1 次插入1 次删除
  1. 1 1
      src/unistd/setxid.c

+ 1 - 1
src/unistd/setxid.c

@@ -30,5 +30,5 @@ int __setxid(int nr, int id, int eid, int sid)
 	 * trigger the safety kill above. */
 	struct ctx c = { .nr = nr, .id = id, .eid = eid, .sid = sid, .ret = 1 };
 	__synccall(do_setxid, &c);
-	return __syscall_ret(c.ret);
+	return __syscall_ret(c.ret > 0 ? -EAGAIN : c.ret);
 }