From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6E7A73857C48; Thu, 28 Jul 2022 11:30:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E7A73857C48 From: "bww9643 at gmail dot com" To: glibc-bugs@sourceware.org Subject: [Bug string/29422] New: unexpected result occured in strcpy function (i386, with __strcpy_sse2) Date: Thu, 28 Jul 2022 11:30:32 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: string X-Bugzilla-Version: unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: bww9643 at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: glibc-bugs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-bugs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Jul 2022 11:30:32 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D29422 Bug ID: 29422 Summary: unexpected result occured in strcpy function (i386, with __strcpy_sse2) Product: glibc Version: unspecified Status: UNCONFIRMED Severity: normal Priority: P2 Component: string Assignee: unassigned at sourceware dot org Reporter: bww9643 at gmail dot com Target Milestone: --- function related with "sse" register or instruction can copy more than 4byt= es with xmm() register. However, unexpected error occured with this testcase: ``` Linux ubuntu 5.15.0-41-generic #44~20.04.1-Ubuntu SMP Fri Jun 24 13:27:29 U= TC 2022 x86_64 x86_64 x86_64 GNU/Linux ~ > cat test.c #include #include #include char a[1024]; int main(){ strcpy(a,"0123456789abcd"); printf("%s\n", a); strcpy(a,a+2); printf("%s\n", a); strcpy(a,a+2); printf("%s\n", a); strcpy(a,a+2); printf("%s", a); return 0; } ~ > gcc -m32 -o test test.c ~ > ./test 0123456789abcd 23456989abcd 456989abcd 6989abcd% ``` expected result: 0123456789abcd 23456789abcd 456789abcd 6789abcd root cause: !> register environment before execute following instructions: ecx is ptr of a+2 edx is ptr of a 0xf7d60580 <__strcpy_sse2+1408> movlpd xmm0, QWORD PTR [ecx] 0xf7d60584 <__strcpy_sse2+1412> movlpd QWORD PTR [edx], xmm0 0xf7d60588 <__strcpy_sse2+1416> movlpd xmm0, QWORD PTR [ecx+0x5] 0xf7d6058d <__strcpy_sse2+1421> movlpd QWORD PTR [edx+0x5], xmm0 in mode -m32, `strcpy` use specific function `__strcpy_sse2`. This function is operated with raw assembly code. (ext: .S) it applys this following process: 1. check string's length and jmp to each case. 2. instruction pointer jumps exact line when string's length is 14. 3. save xmm0 to "23456789" (start with ptr+2) and overwrite ptr result : "2345678989abcd" 4. save xmm0 to "989abcd\0" (start with ptr+7) and overwrite ptr+5 result : "23456989abcd" (unexpected!) Idk why this code should be written with this flow. --=20 You are receiving this mail because: You are on the CC list for the bug.=