Skip to content

Commit d43277c

Browse files
committed
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 <[email protected]>
1 parent 57a943c commit d43277c

File tree

5 files changed

+15
-23
lines changed

5 files changed

+15
-23
lines changed

block.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ static BlockDriver *find_protocol(const char *filename)
225225
{
226226
BlockDriver *drv1;
227227
char protocol[128];
228-
int len = strnlen(filename, 127)+1;
228+
int len = qemu_strnlen(filename, 127) + 1;
229229
const char *p;
230230

231231
#ifdef _WIN32

bsd-user/uaccess.c

-11
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,6 @@ abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len)
3737
return ret;
3838
}
3939

40-
/* XXX: use host strnlen if available ? */
41-
static int qemu_strnlen(const char *s, int max_len)
42-
{
43-
int i;
44-
for(i = 0; i < max_len; i++) {
45-
if (s[i] == '\0')
46-
break;
47-
}
48-
return i;
49-
}
50-
5140
/* Return the length of a string in target memory or -TARGET_EFAULT if
5241
access error */
5342
abi_long target_strlen(abi_ulong guest_addr1)

cutils.c

+13
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ int stristart(const char *str, const char *val, const char **ptr)
109109
return 1;
110110
}
111111

112+
/* XXX: use host strnlen if available ? */
113+
int qemu_strnlen(const char *s, int max_len)
114+
{
115+
int i;
116+
117+
for(i = 0; i < max_len; i++) {
118+
if (s[i] == '\0') {
119+
break;
120+
}
121+
}
122+
return i;
123+
}
124+
112125
time_t mktimegm(struct tm *tm)
113126
{
114127
time_t t;

linux-user/uaccess.c

-11
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,6 @@ abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len)
3737
return ret;
3838
}
3939

40-
/* XXX: use host strnlen if available ? */
41-
static int qemu_strnlen(const char *s, int max_len)
42-
{
43-
int i;
44-
for(i = 0; i < max_len; i++) {
45-
if (s[i] == '\0')
46-
break;
47-
}
48-
return i;
49-
}
50-
5140
/* Return the length of a string in target memory or -TARGET_EFAULT if
5241
access error */
5342
abi_long target_strlen(abi_ulong guest_addr1)

qemu-common.h

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ void pstrcpy(char *buf, int buf_size, const char *str);
109109
char *pstrcat(char *buf, int buf_size, const char *s);
110110
int strstart(const char *str, const char *val, const char **ptr);
111111
int stristart(const char *str, const char *val, const char **ptr);
112+
int qemu_strnlen(const char *s, int max_len);
112113
time_t mktimegm(struct tm *tm);
113114
int qemu_fls(int i);
114115

0 commit comments

Comments
 (0)