[Bug 1441421] Re: compatibility issue in libc6:i386
Seth Arnold
1441421 at bugs.launchpad.net
Wed Apr 8 03:51:47 UTC 2015
The problem is you're relying upon undefined behaviour for memcpy(3):
size_t skip = strlen(other);
ssize_t index = 1;
ssize_t next = 87;
size_t tail = 1;
memcpy(buf + tail, buf + index + skip, next - index - skip);
The memory areas overlap, which invokes the undefined behaviour; see the
standard definition here
http://pubs.opengroup.org/onlinepubs/009695399/functions/memcpy.html and
a common manpage used for the glibc implementation here
http://man7.org/linux/man-pages/man3/memcpy.3.html
If you wish to use overlapping source and destination, then you should
use memmove(3) instead.
Thanks
** Changed in: glibc (Ubuntu)
Status: New => Invalid
--
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to glibc in Ubuntu.
https://bugs.launchpad.net/bugs/1441421
Title:
compatibility issue in libc6:i386
Status in glibc package in Ubuntu:
Invalid
Bug description:
Host: Linux Mars 3.19.0-12-generic #12-Ubuntu SMP Fri Apr 3 04:03:26 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=15.04
DISTRIB_CODENAME=vivid
DISTRIB_DESCRIPTION="Ubuntu Vivid Vervet (development branch)"
[Issue description]
memcpy() gets different result when run the same code under x86_64 mode and i386 mode.
[Details]
code and program output runs as the following, the behavior under x86_64 is right.
qin at Mars:tmp$ cat mm.c
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
const char other[] = "@SystemApi";
char data[] = " @SystemApi Allow an application to read and write the cache partition.\n @hide ";
char *buf = data;
size_t skip = strlen(other);
size_t len = strlen(data);
ssize_t index = 1;
ssize_t next = 87;
size_t tail = 1;
fprintf(stderr, "<\"%s\"\n", data);
memcpy(buf + tail, buf + index + skip, next - index - skip);
fprintf(stderr, ">\"%s\"\n", data);
return 0;
}
qin at Mars:tmp$ gcc mm.c -o mm.6
qin at Mars:tmp$ ./mm.6
<" @SystemApi Allow an application to read and write the cache partition.
@hide "
>" Allow an application to read and write the cache partition.
@hide @hide "
qin at Mars:tmp$ ldd mm.6
linux-vdso.so.1 => (0x00007fffe55d3000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc881155000)
/lib64/ld-linux-x86-64.so.2 (0x00007fc88154a000)
qin at Mars:tmp$
qin at Mars:tmp$ gcc mm.c -m32 -o mm.3
qin at Mars:tmp$ ./mm.3
<" @SystemApi Allow an application to read and write the cache partition.
@hide "
>" Allow an apto read anto read and cache
@hid @hide @hide "
qin at Mars:tmp$ ldd mm.3
linux-gate.so.1 => (0xf76fd000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xf7514000)
/lib/ld-linux.so.2 (0xf76fe000)
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/1441421/+subscriptions
More information about the foundations-bugs
mailing list