Skip to contentSkip to conversation

syscall: fix compiler warnings (clang 5)

PATCH In review Philippe Mathieu-Daudé 3 participants 4 messages May 6, 2017 – May 10, 2017

lore
Share & tools
lore
#0 lore raw

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) {
        ^~~~~~~~~~~~~~~~
Reported-by Clang Static Analyzer
---
 linux-user/syscall.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/syscall.c +2 -2
index cec8428589..c541e22693 100644
@@ -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
#1 lore raw
Quoted 26 lines · Philippe Mathieu-Daudé

static code analyzer complain:

linux-user/syscall.c:5575:9: warning: Dereference of undefined pointer value

    if (*host_rt_dev_ptr != 0) {
        ^~~~~~~~~~~~~~~~
Reported-by Clang Static Analyzer
---
 linux-user/syscall.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/syscall.c +1 -1
index cec8428589..c541e22693 100644
@@ -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

#2 lore raw
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 value

    if (*host_rt_dev_ptr != 0) {
        ^~~~~~~~~~~~~~~~
Reported-by Clang Static Analyzer
---
 linux-user/syscall.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/syscall.c +1 -1
index cec8428589..c541e22693 100644
@@ -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 -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.

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

#3 lore raw
Quoted 7 lines
Quoted 5 lines

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.

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