mirror of
https://review.coreboot.org/flashrom.git
synced 2025-07-02 14:33:18 +02:00
tests: Mock the mode_t variant of open
open has a second form with a mode_t argument. When mocking without this argument a caller trying to O_CREAT would have their mode_t argument discarded and a random stack variable would be used instead. BUG=b:187647884 BRANCH=None TEST=meson test Change-Id: I8c134e6d36a248d0f51985e389085a9e585fb83d Signed-off-by: Evan Benn <evanbenn@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/69263 Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:

committed by
Anastasia Klimchuk

parent
35243fdd7d
commit
67a393b88a
@ -75,10 +75,10 @@ uint8_t __wrap_sio_read(uint16_t port, uint8_t reg)
|
||||
return (uint8_t)mock();
|
||||
}
|
||||
|
||||
static int mock_open(const char *pathname, int flags)
|
||||
static int mock_open(const char *pathname, int flags, mode_t mode)
|
||||
{
|
||||
if (get_io() && get_io()->iom_open)
|
||||
return get_io()->iom_open(get_io()->state, pathname, flags);
|
||||
return get_io()->iom_open(get_io()->state, pathname, flags, mode);
|
||||
|
||||
if (get_io() && get_io()->fallback_open_state) {
|
||||
struct io_mock_fallback_open_state *io_state;
|
||||
@ -96,22 +96,43 @@ static int mock_open(const char *pathname, int flags)
|
||||
return MOCK_FD;
|
||||
}
|
||||
|
||||
int __wrap_open(const char *pathname, int flags)
|
||||
int __wrap_open(const char *pathname, int flags, ...)
|
||||
{
|
||||
LOG_ME;
|
||||
return mock_open(pathname, flags);
|
||||
mode_t mode = 0;
|
||||
if (flags & O_CREAT) {
|
||||
va_list ap;
|
||||
va_start(ap, flags);
|
||||
mode = va_arg(ap, mode_t);
|
||||
va_end(ap);
|
||||
}
|
||||
return mock_open(pathname, flags, mode);
|
||||
}
|
||||
|
||||
int __wrap_open64(const char *pathname, int flags)
|
||||
int __wrap_open64(const char *pathname, int flags, ...)
|
||||
{
|
||||
LOG_ME;
|
||||
return mock_open(pathname, flags);
|
||||
mode_t mode = 0;
|
||||
if (flags & O_CREAT) {
|
||||
va_list ap;
|
||||
va_start(ap, flags);
|
||||
mode = va_arg(ap, mode_t);
|
||||
va_end(ap);
|
||||
}
|
||||
return mock_open(pathname, flags, mode);
|
||||
}
|
||||
|
||||
int __wrap___open64_2(const char *pathname, int flags)
|
||||
int __wrap___open64_2(const char *pathname, int flags, ...)
|
||||
{
|
||||
LOG_ME;
|
||||
return mock_open(pathname, flags);
|
||||
mode_t mode = 0;
|
||||
if (flags & O_CREAT) {
|
||||
va_list ap;
|
||||
va_start(ap, flags);
|
||||
mode = va_arg(ap, mode_t);
|
||||
va_end(ap);
|
||||
}
|
||||
return mock_open(pathname, flags, mode);
|
||||
}
|
||||
|
||||
int __wrap_ioctl(int fd, unsigned long int request, ...)
|
||||
|
Reference in New Issue
Block a user