o8vm / krabs

An x86 bootloader written in Rust.
Apache License 2.0
519 stars 22 forks source link

The printf command used in build.sh has a compatibility issue. #11

Closed o8vm closed 4 years ago

o8vm commented 4 years ago

Describe the bug The printf command used in build.sh has a compatibility issue. In POSIX, Hexadecimal escaping can be ambiguous. This causes build.sh to write fatally incorrect values ​​when writing parameters in build process. As a result, the following error occurs during the boot step:

Booting from Hard Disk...
Stage1: I/O error

Dash printf builtin does not honor \xNN to print hexadecimal:

# in dash
$ printf '\x41'
\x41

Bash printf builtin:

# in bash
$ printf '\x41'
A

How to fix According to POSIX, we have to use octal escaping when we want to output bytes with the printf command. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html

"\0ddd", where ddd is a zero, one, two, or three-digit octal number that shall be converted to a byte with the numeric value specified by the octal number