From bcbf22a316baf9c159b286ca774b27b21102b53f Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 5 May 2013 18:01:12 +0200 Subject: [PATCH] x86[-64]: Fix arch_cpu_user_strlcpy() for small buffers The case for small buffers was broken, since scasb operates on edi/rdi, not esi/rsi. --- src/system/kernel/arch/x86/32/arch.S | 3 +++ src/system/kernel/arch/x86/64/arch.S | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/system/kernel/arch/x86/32/arch.S b/src/system/kernel/arch/x86/32/arch.S index 90ef56b363..68d7038be8 100644 --- a/src/system/kernel/arch/x86/32/arch.S +++ b/src/system/kernel/arch/x86/32/arch.S @@ -264,9 +264,12 @@ FUNCTION(arch_cpu_user_strlcpy): /* count remaining bytes in src */ .L_user_strlcpy_source_count: not %ecx + # %ecx was 0 and is now max xor %al,%al + movl %esi,%edi repnz scasb + movl %edi,%esi .L_user_strlcpy_source_done: movl %esi,%eax diff --git a/src/system/kernel/arch/x86/64/arch.S b/src/system/kernel/arch/x86/64/arch.S index 3f07b957d2..baf8d09f4e 100644 --- a/src/system/kernel/arch/x86/64/arch.S +++ b/src/system/kernel/arch/x86/64/arch.S @@ -251,9 +251,12 @@ FUNCTION(arch_cpu_user_strlcpy): .L_user_strlcpy_source_count: // Count remaining bytes in src not %rcx + # %rcx was 0 and is now max xor %al, %al + movl %rsi, %rdi repnz scasb + movl %rdi, %rsi .L_user_strlcpy_source_done: // Restore the old fault handler