Introduce flags indicating errors to catch non-checked return codes
Certain functions can fail before we execute exile_enable_policy(). While the return code should be checked, it's easily forgotten. For most users, checking just the exile_enable_policy() return code should suffice. exile_append_path_policies(): Add check whether a path exists. If not, set the error flag. This also allows an early exit, allowing to cleanly handle the case when a path does not exist. Previously, this was only caught during activation, and a failure there is generally undefined.
Αυτή η υποβολή περιλαμβάνεται σε:
13
test.c
13
test.c
@@ -530,6 +530,18 @@ int test_mkpath()
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_fail_flags()
|
||||
{
|
||||
struct exile_policy *policy = exile_init_policy();
|
||||
exile_append_path_policy(policy, EXILE_FS_ALLOW_ALL_READ, "/nosuchpathexists");
|
||||
int ret = exile_enable_policy(policy);
|
||||
if(ret == 0)
|
||||
{
|
||||
fprintf(stderr, "Failed: A path that does not exist should have set the error flag %i\n", ret);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct dispatcher
|
||||
{
|
||||
@@ -554,6 +566,7 @@ struct dispatcher dispatchers[] = {
|
||||
{ "no_fs", &test_nofs},
|
||||
{ "no_new_fds", &test_no_new_fds},
|
||||
{ "mkpath", &test_mkpath},
|
||||
{ "failflags", &test_fail_flags},
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
Αναφορά σε νέο ζήτημα
Block a user