Skip to contentSkip to conversation

linux-user: fix bugs reported by Clang Static Analyzer

PATCH RESEND New Philippe Mathieu-Daudé 1 participant 3 messages Jun 4, 2018

lore
Share & tools
lore
#0 lore raw

v2 cover linux-user: fix bugs reported by Clang Static Analyzer

This is a resend of v1 resend ... not sure what happened previously, MTA sent:

550 8-bit characters not allowed in subject (see RFC 2822, sections 3.6.5, 2.2.1)

v1 here:
http://lists.nongnu.org/archive/html/qemu-devel/2017-07/msg07453.html

Philippe Mathieu-Daudé (2):
linux-user: Export use is_error(), use it to avoid warnings
linux-user: Use is_error() to avoid warnings and make the code clearer

 linux-user/qemu.h     |  5 +++++
 linux-user/flatload.c | 15 +++++++++------
 linux-user/syscall.c  |  5 -----
 3 files changed, 14 insertions(+), 11 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH RESEND v2 1/2 linux-user: Export use is_error(), use it to avoid warnings

This fixes:

linux-user/flatload.c:740:9: warning: Loss of sign in implicit conversion

      if (res > (unsigned long)-4096)
          ^~~
Reported-by Clang Static Analyzer
---
 linux-user/qemu.h    | 5 +++++
 linux-user/syscall.c | 5 -----
 2 files changed, 5 insertions(+), 5 deletions(-)
linux-user/qemu.h +5 -0
index c55c8e294b..4eeffe3c76 100644
@@ -618,6 +618,11 @@ static inline void *lock_user_string(abi_ulong guest_addr)
 
 #include <pthread.h>
 
+static inline int is_error(abi_long ret)
+{
+    return (abi_ulong)ret >= (abi_ulong)(-4096);
+}
+
 /* Include target-specific struct and function definitions;
  * they may need access to the target-independent structures
  * above, so include them last.
linux-user/syscall.c +0 -5
index d02c16bbc6..5e122dbdda 100644
@@ -906,11 +906,6 @@ static inline abi_long get_errno(abi_long ret)
         return ret;
 }
 
-static inline int is_error(abi_long ret)
-{
-    return (abi_ulong)ret >= (abi_ulong)(-4096);
-}
-
 const char *target_strerror(int err)
 {
     if (err == TARGET_ERESTARTSYS) {
Signature · 1 line
2.17.1
#2 lore raw

PATCH RESEND v2 2/2 linux-user: Use is_error() to avoid warnings and make the code clearer

In reply to Philippe Mathieu-Daudé

This fixes:

linux-user/flatload.c:740:9: warning: Loss of sign in implicit conversion

      if (res > (unsigned long)-4096)
          ^~~
Reported-by Clang Static Analyzer
---
 linux-user/flatload.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
linux-user/flatload.c +9 -6
index a35a560904..10c529910f 100644
@@ -224,8 +224,9 @@ static int decompress_exec(
 		ret = bprm->file->f_op->read(bprm->file, buf, LBUFSIZE, &fpos);
 		if (ret <= 0)
 			break;
-		if (ret >= (unsigned long) -4096)
+                if (is_error(ret)) {
 			break;
+                }
 		len -= ret;
 
 		strm.next_in = buf;
@@ -283,8 +284,7 @@ calc_reloc(abi_ulong r, struct lib_info *p, int curid, int internalp)
                     "in same module (%d != %d)\n",
                     (unsigned) r, curid, id);
             goto failed;
-        } else if ( ! p[id].loaded &&
-                    load_flat_shared_library(id, p) > (unsigned long) -4096) {
+        } else if (!p[id].loaded && is_error(load_flat_shared_library(id, p))) {
             fprintf(stderr, "BINFMT_FLAT: failed to load library %d\n", id);
             goto failed;
         }
@@ -523,9 +523,10 @@ static int load_flat_file(struct linux_binprm * bprm,
                 fpos = 0;
                 result = bprm->file->f_op->read(bprm->file,
                                 (char *) textpos, text_len, &fpos);
-                if (result < (unsigned long) -4096)
+                if (!is_error(result)) {
                         result = decompress_exec(bprm, text_len, (char *) datapos,
                                          data_len + (relocs * sizeof(unsigned long)), 0);
+                }
         }
         else
 #endif
@@ -693,8 +694,9 @@ static int load_flat_shared_library(int id, struct lib_info *libs)
 
 	res = prepare_binprm(&bprm);
 
-	if (res <= (unsigned long)-4096)
+        if (!is_error(res)) {
 		res = load_flat_file(&bprm, libs, id, NULL);
+        }
 	if (bprm.file) {
 		allow_write_access(bprm.file);
 		fput(bprm.file);
@@ -737,8 +739,9 @@ int load_flt_binary(struct linux_binprm *bprm, struct image_info *info)
 
 
     res = load_flat_file(bprm, libinfo, 0, &stack_len);
-    if (res > (unsigned long)-4096)
+    if (is_error(res)) {
             return res;
+    }
 
     /* Update data segment pointers for all libraries */
     for (i=0; i<MAX_SHARED_LIBS; i++) {
Signature · 1 line
2.17.1