syscall: fix compiler warnings (clang 5)
PATCH 1/1 syscall: fix compiler warnings (clang 5)
static code analyzer complain:
linux-user/syscall.c:5575:9: warning: Dereference of undefined pointer value
if (*host_rt_dev_ptr != 0) {
^~~~~~~~~~~~~~~~--- linux-user/syscall.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/syscall.c +2 -2
@@ -5526,7 +5526,7 @@ static abi_long do_ioctl_rt(const IOCTLEntry *ie, uint8_t *buf_temp,int target_size;void *argptr;abi_ulong *target_rt_dev_ptr; -unsigned long *host_rt_dev_ptr; +unsigned long *host_rt_dev_ptr =NULL ;abi_long ret;int i;
@@ -5572,7 +5572,7 @@ static abi_long do_ioctl_rt(const IOCTLEntry *ie, uint8_t *buf_temp,unlock_user (argptr, arg,0 ); ret =get_errno (safe_ioctl (fd, ie->host_cmd, buf_temp)); -if (*host_rt_dev_ptr !=0 ) { +if (host_rt_dev_ptr !=NULL && *host_rt_dev_ptr !=0 ) {unlock_user ((void *)*host_rt_dev_ptr, *target_rt_dev_ptr,0 ); }
Signature · 1 line
2.11.0
Quoted 26 lines · Philippe Mathieu-Daudé
static code analyzer complain:
linux-user/syscall.c:5575:9: warning: Dereference of undefined pointer valueif (*host_rt_dev_ptr != 0) { ^~~~~~~~~~~~~~~~Reported-by Clang Static AnalyzerSigned-off-by Philippe Mathieu-Daudé <[email protected]>--- linux-user/syscall.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)linux-user/syscall.c +1
-1@@ -5526,7 +5526,7 @@ static abi_long do_ioctl_rt(const IOCTLEntry *ie, uint8_t *buf_temp,int target_size;void *argptr;abi_ulong *target_rt_dev_ptr; -unsigned long *host_rt_dev_ptr; +unsigned long *host_rt_dev_ptr =NULL ;abi_long ret;int i;
linux-user/syscall.c static abi_long do_ioctl_rt(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5574
Quoted 3 lines
linux-user/syscall.c +0
-0@@ -5572,7 +5572,7 @@ static abi_long do_ioctl_rt(const IOCTLEntry *ie, uint8_t *buf_temp,unlock_user (argptr, arg,0 ); ret =get_errno (safe_ioctl (fd, ie->host_cmd, buf_temp));
I think we should "assert(host_rt_dev_ptr)" here. It's a bug if host_rt_dev_ptr is not set.
The "for" loop scans the structure to find the rt_dev field, and we should always enter in the first "if", so "host_rt_dev_ptr" is always set.
linux-user/syscall.c static abi_long do_ioctl_rt(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5578
Quoted 6 lines
linux-user/syscall.c +1
-1-if (*host_rt_dev_ptr !=0 ) { +if (host_rt_dev_ptr !=NULL && *host_rt_dev_ptr !=0 ) {unlock_user ((void *)*host_rt_dev_ptr, *target_rt_dev_ptr,0 ); }
Laurent
Quoted 29 lines · Laurent Vivier
Quoted 28 lines · Philippe Mathieu-Daudé
static code analyzer complain:
linux-user/syscall.c:5575:9: warning: Dereference of undefined pointer valueif (*host_rt_dev_ptr != 0) { ^~~~~~~~~~~~~~~~Reported-by Clang Static AnalyzerSigned-off-by Philippe Mathieu-Daudé <[email protected]>--- linux-user/syscall.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)linux-user/syscall.c +1
-1@@ -5526,7 +5526,7 @@ static abi_long do_ioctl_rt(const IOCTLEntry *ie, uint8_t *buf_temp,int target_size;void *argptr;abi_ulong *target_rt_dev_ptr; -unsigned long *host_rt_dev_ptr; +unsigned long *host_rt_dev_ptr =NULL ;abi_long ret;int i;@@ -5572,7 +5572,7 @@ static abi_long do_ioctl_rt(const IOCTLEntry *ie, uint8_t *buf_temp,unlock_user (argptr, arg,0 );
Quoted 7 lines
linux-user/syscall.c static abi_long do_ioctl_rt(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5574
Quoted 1 line
linux-user/syscall.c +0
-0ret =get_errno (safe_ioctl (fd, ie->host_cmd, buf_temp));I think we should "
assert(host_rt_dev_ptr)" here. It's a bug ifhost_rt_dev_ptris not set.The "for" loop scans the structure to find the
rt_devfield, and we should always enter in the first "if", so "host_rt_dev_ptr" is always set.
It's better indeed, I'll use g_assert_nonnull() and resend.
Thanks!
Quoted 10 lines
linux-user/syscall.c static abi_long do_ioctl_rt(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5578
Quoted 7 lines
linux-user/syscall.c +1
-1-if (*host_rt_dev_ptr !=0 ) { +if (host_rt_dev_ptr !=NULL && *host_rt_dev_ptr !=0 ) {unlock_user ((void *)*host_rt_dev_ptr, *target_rt_dev_ptr,0 ); }Laurent
Quoted 7 lines
Quoted 5 lines
The "for" loop scans the structure to find the
rt_devfield, and we should always enter in the first "if", so "host_rt_dev_ptr" is always set.It's better indeed, I'll use
g_assert_nonnull()and resend.
Careful - we haven't yet resolved whether g_assert_nonnull() is safe to use.
https://lists.gnu.org/archive/html/qemu-devel/2017-04/msg05499.html
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org