Skip to content

Commit af085ba

Browse files
committed
Remove head -c for cut, as head -c is not POSIX-compliant
`tail -c` is however. Since we used `head -c-`, to cut off characters from the end, the POSIX-compliant `wc -c` is used for a `strlen` we can proceed to do the necessary arithmetic off of. Credit to @PlasmaPower for identifying this non-compliant behavior which necessitated this fix in response.
1 parent d881421 commit af085ba

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

orchestration/increase_default_stack_size.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ write_bytes() {
3333
POS=$1
3434
BYTES=$2
3535
while [ ! "$BYTES" = "" ]; do
36-
NEXT=$(printf "%s" "$BYTES" | head -c2)
36+
NEXT=$(printf "%s" "$BYTES" | cut -c-2)
3737
# Advance to the third byte, as in, after the first two bytes
3838
BYTES=$(printf "%s" "$BYTES" | tail -c+3)
3939

@@ -106,9 +106,13 @@ swap_native_endian() {
106106
return
107107
fi
108108

109-
while [ ! "$BYTES" = "" ]; do
109+
while :; do
110110
printf "%s" "$BYTES" | tail -c2
111-
BYTES=$(printf "%s" "$BYTES" | head -c-2)
111+
NEW_LENGTH=$(( $(printf "%s" "$BYTES" | wc -c) - 2 ))
112+
if [ "$NEW_LENGTH" -eq 0 ]; then
113+
break
114+
fi
115+
BYTES=$(printf "%s" "$BYTES" | cut -c-$NEW_LENGTH)
112116
done
113117
}
114118

@@ -149,7 +153,7 @@ while [ "$NEXT_PROGRAM_HEADER" -ne -1 ]; do
149153
NEXT_PROGRAM_HEADER=$(( NEXT_PROGRAM_HEADER - 1 ))
150154
PROGRAM_HEADER=$(read_program_header "$THIS_PROGRAM_HEADER")
151155

152-
HEADER_TYPE=$(printf "%s" "$PROGRAM_HEADER" | head -c8)
156+
HEADER_TYPE=$(printf "%s" "$PROGRAM_HEADER" | cut -c-8)
153157
HEADER_TYPE=$(swap_native_endian "$HEADER_TYPE")
154158
# `PT_GNU_STACK`
155159
# https://github.com/torvalds/linux/blob/c2f2b01b74be8b40a2173372bcd770723f87e7b2/include/uapi/linux/elf.h#L41

0 commit comments

Comments
 (0)