Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
efivarfs: fix some minor immutability bugs
Signed-off-by: Peter Jones <pjones@redhat.com>
  • Loading branch information
vathpela committed Jun 8, 2018
1 parent 8a6c3d2 commit aa2a584
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/efivarfs.c
Expand Up @@ -126,15 +126,16 @@ efivarfs_set_fd_immutable(int fd, int immutable)
}

static int
efivarfs_make_fd_mutable(int fd, unsigned *orig_attrs)
efivarfs_make_fd_mutable(int fd, unsigned long *orig_attrs)
{
unsigned mutable_attrs;
unsigned long mutable_attrs = 0;

*orig_attrs = 0;
if (ioctl(fd, FS_IOC_GETFLAGS, orig_attrs) == -1)
return -1;
if ((*orig_attrs & FS_IMMUTABLE_FL) == 0)
return 0;
mutable_attrs = *orig_attrs & ~(unsigned)FS_IMMUTABLE_FL;
mutable_attrs = *orig_attrs & ~(unsigned long)FS_IMMUTABLE_FL;
if (ioctl(fd, FS_IOC_SETFLAGS, &mutable_attrs) == -1)
return -1;
return 0;
Expand Down Expand Up @@ -321,7 +322,7 @@ efivarfs_set_variable(efi_guid_t guid, const char *name, uint8_t *data,
uint8_t *buf;
int rfd = -1;
struct stat rfd_stat;
unsigned orig_attrs = 0;
unsigned long orig_attrs = 0;
int restore_immutable_fd = -1;
int wfd = -1;
int open_wflags;
Expand Down Expand Up @@ -446,8 +447,12 @@ efivarfs_set_variable(efi_guid_t guid, const char *name, uint8_t *data,
efi_error("failed to unlink %s", path);

ioctl(restore_immutable_fd, FS_IOC_SETFLAGS, &orig_attrs);
close(wfd);
close(rfd);

if (wfd >= 0)
close(wfd);
if (rfd >= 0)
close(rfd);

free(buf);
free(path);

Expand Down

0 comments on commit aa2a584

Please sign in to comment.