Browse Source

Fix missing strnlen problems

Fix missing strnlen (a GNU extension) problems by using qemu_strnlen
used for user emulators also for system emulators.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
Blue Swirl 16 years ago
parent
commit
d43277c534
5 changed files with 15 additions and 23 deletions
  1. 1 1
      block.c
  2. 0 11
      bsd-user/uaccess.c
  3. 13 0
      cutils.c
  4. 0 11
      linux-user/uaccess.c
  5. 1 0
      qemu-common.h

+ 1 - 1
block.c

@@ -225,7 +225,7 @@ static BlockDriver *find_protocol(const char *filename)
 {
 {
     BlockDriver *drv1;
     BlockDriver *drv1;
     char protocol[128];
     char protocol[128];
-    int len = strnlen(filename, 127)+1;
+    int len = qemu_strnlen(filename, 127) + 1;
     const char *p;
     const char *p;
 
 
 #ifdef _WIN32
 #ifdef _WIN32

+ 0 - 11
bsd-user/uaccess.c

@@ -37,17 +37,6 @@ abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len)
     return ret;
     return ret;
 }
 }
 
 
-/* XXX: use host strnlen if available ? */
-static int qemu_strnlen(const char *s, int max_len)
-{
-    int i;
-    for(i = 0; i < max_len; i++) {
-        if (s[i] == '\0')
-            break;
-    }
-    return i;
-}
-
 /* Return the length of a string in target memory or -TARGET_EFAULT if
 /* Return the length of a string in target memory or -TARGET_EFAULT if
    access error  */
    access error  */
 abi_long target_strlen(abi_ulong guest_addr1)
 abi_long target_strlen(abi_ulong guest_addr1)

+ 13 - 0
cutils.c

@@ -109,6 +109,19 @@ int stristart(const char *str, const char *val, const char **ptr)
     return 1;
     return 1;
 }
 }
 
 
+/* XXX: use host strnlen if available ? */
+int qemu_strnlen(const char *s, int max_len)
+{
+    int i;
+
+    for(i = 0; i < max_len; i++) {
+        if (s[i] == '\0') {
+            break;
+        }
+    }
+    return i;
+}
+
 time_t mktimegm(struct tm *tm)
 time_t mktimegm(struct tm *tm)
 {
 {
     time_t t;
     time_t t;

+ 0 - 11
linux-user/uaccess.c

@@ -37,17 +37,6 @@ abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len)
     return ret;
     return ret;
 }
 }
 
 
-/* XXX: use host strnlen if available ? */
-static int qemu_strnlen(const char *s, int max_len)
-{
-    int i;
-    for(i = 0; i < max_len; i++) {
-        if (s[i] == '\0')
-            break;
-    }
-    return i;
-}
-
 /* Return the length of a string in target memory or -TARGET_EFAULT if
 /* Return the length of a string in target memory or -TARGET_EFAULT if
    access error  */
    access error  */
 abi_long target_strlen(abi_ulong guest_addr1)
 abi_long target_strlen(abi_ulong guest_addr1)

+ 1 - 0
qemu-common.h

@@ -109,6 +109,7 @@ void pstrcpy(char *buf, int buf_size, const char *str);
 char *pstrcat(char *buf, int buf_size, const char *s);
 char *pstrcat(char *buf, int buf_size, const char *s);
 int strstart(const char *str, const char *val, const char **ptr);
 int strstart(const char *str, const char *val, const char **ptr);
 int stristart(const char *str, const char *val, const char **ptr);
 int stristart(const char *str, const char *val, const char **ptr);
+int qemu_strnlen(const char *s, int max_len);
 time_t mktimegm(struct tm *tm);
 time_t mktimegm(struct tm *tm);
 int qemu_fls(int i);
 int qemu_fls(int i);