Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

printk bug #4

Open
YWHyuk opened this issue Mar 16, 2020 · 1 comment
Open

printk bug #4

YWHyuk opened this issue Mar 16, 2020 · 1 comment

Comments

@YWHyuk
Copy link
Owner

YWHyuk commented Mar 16, 2020

printk %s format dosen't print correct string

@YWHyuk
Copy link
Owner Author

YWHyuk commented Mar 17, 2020

/kernel/vsprintf.c

165             len = strlen(s); <------------------------- Buggy
166             if (precision < 0)
167                 precision = len;
168             else if (len > precision)
169                 len = precision;
170
171             if (!(flags & LEFT))
172                 while (len < field_width--)
173                     *str++ = ' ';
174             for (i = 0; i < len; ++i)
175                 *str++ = *s++;
176             while (len < field_width--)
177                 *str++ = ' ';
178             break;
/kernel/vsprintf.dis

01 mov    (%edi),%edi
02 mov    $0xffffffff,%ecx
03 mov    $0x0,%eax
04 cld 
05 repnz scas %es:(%edi),%al 
06 not    %ecx
07 dec    %ecx 
08 mov    0x8(%esp),%eax
09 test   %eax,%eax
10 js     3da <vsprintf+0x1cd>
11 cmp    %eax,%ecx
12 jle    3da <vsprintf+0x1cd>
13 mov    %eax,%ecx
14 test   $0x10,%dl
15 je     416 <vsprintf+0x209>
16 test   %ecx,%ecx
17 jle    3f6 <vsprintf+0x1e9>
18 mov    $0x0,%eax
19 mov    (%edi,%eax,1),%dl
  1. In line 4, strlen inline function starts.
  2. In line 7, strlen inline function ends.

In line 5, edi register's value is changed. But edi(corrupted) is used in line 19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant