mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-19 09:32:27 +02:00
util/nvmutil: check file flags properly
masking O_ACCMODE tells you which flag it is Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
+10
-6
@@ -225,7 +225,7 @@ main(int argc, char *argv[])
|
|||||||
cmd = &nv->cmd[*i];
|
cmd = &nv->cmd[*i];
|
||||||
|
|
||||||
#ifdef NVMUTIL_UNVEIL
|
#ifdef NVMUTIL_UNVEIL
|
||||||
if (cmd->flags == O_RDONLY) {
|
if ((cmd->flags & O_ACCMODE) == O_RDONLY) {
|
||||||
if (unveil(f->fname, "r") == -1)
|
if (unveil(f->fname, "r") == -1)
|
||||||
err(errno, "%s: unveil r", f->fname);
|
err(errno, "%s: unveil r", f->fname);
|
||||||
} else {
|
} else {
|
||||||
@@ -256,7 +256,7 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
run_cmd();
|
run_cmd();
|
||||||
|
|
||||||
if (cmd->flags == O_RDWR)
|
if ((cmd->flags & O_ACCMODE) == O_RDWR)
|
||||||
write_to_gbe_bin();
|
write_to_gbe_bin();
|
||||||
|
|
||||||
if (exit_cleanup() == -1)
|
if (exit_cleanup() == -1)
|
||||||
@@ -294,6 +294,8 @@ sanitize_command_index(unsigned long c)
|
|||||||
|
|
||||||
struct commands *cmd = &nv->cmd[c];
|
struct commands *cmd = &nv->cmd[c];
|
||||||
|
|
||||||
|
int _flag;
|
||||||
|
|
||||||
check_command_num(c);
|
check_command_num(c);
|
||||||
|
|
||||||
if (cmd->argc < 3)
|
if (cmd->argc < 3)
|
||||||
@@ -337,8 +339,10 @@ sanitize_command_index(unsigned long c)
|
|||||||
err(EINVAL, "rw_size larger than GbE part: %lu",
|
err(EINVAL, "rw_size larger than GbE part: %lu",
|
||||||
(unsigned long)gbe_rw_size);
|
(unsigned long)gbe_rw_size);
|
||||||
|
|
||||||
if (cmd->flags != O_RDONLY &&
|
_flag = (cmd->flags & O_ACCMODE);
|
||||||
cmd->flags != O_RDWR)
|
|
||||||
|
if (_flag != O_RDONLY &&
|
||||||
|
_flag != O_RDWR)
|
||||||
err(EINVAL, "invalid cmd.flags setting");
|
err(EINVAL, "invalid cmd.flags setting");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1206,7 +1210,7 @@ write_gbe_file(void)
|
|||||||
struct commands *cmd = &nv->cmd[nv->i];
|
struct commands *cmd = &nv->cmd[nv->i];
|
||||||
struct xfile *f = &nv->f;
|
struct xfile *f = &nv->f;
|
||||||
|
|
||||||
if (cmd->flags == O_RDONLY)
|
if ((cmd->flags & O_ACCMODE) == O_RDONLY)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (fstat(f->gbe_fd, &_gbe_st) == -1)
|
if (fstat(f->gbe_fd, &_gbe_st) == -1)
|
||||||
@@ -1374,7 +1378,7 @@ write_to_gbe_bin(void)
|
|||||||
|
|
||||||
struct commands *cmd = &nv->cmd[nv->i];
|
struct commands *cmd = &nv->cmd[nv->i];
|
||||||
|
|
||||||
if (cmd->flags != O_RDWR)
|
if ((cmd->flags & O_ACCMODE) != O_RDWR)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
write_gbe_file();
|
write_gbe_file();
|
||||||
|
|||||||
Reference in New Issue
Block a user