alpha: objstrip: fix partial write() buffer pointer not advancing
PATCH 1/1 alpha: objstrip: fix partial write() buffer pointer not advancing
In the main copy loop, on a partial write() the inner do-while retried write(ofd, buf, n) always from the start of buf, while only n was decremented. This caused already-written data to be re-written, corrupting the output file on systems where write() returns less than the requested byte count.
Fix by introducing a pointer 'p' that tracks the current write position within buf and advances it by nwritten on each iteration.
Signed-off-by Maximilian Pezzullo <[email protected]>
--- arch/alpha/boot/tools/objstrip.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
arch/alpha/boot/tools/objstrip.c +12 -8
@@ -246,14 +246,18 @@ main (int argc, char *argv[])perror ("read" );exit (1 ); } -do { - nwritten =write (ofd, buf, n); -if ((ssize_t ) nwritten ==-1 ) { -perror ("write" ); -exit (1 ); - } - n -= nwritten; - }while (n >0 ); + { +char *p = buf; +do { + nwritten =write (ofd, p, n); +if ((ssize_t ) nwritten ==-1 ) { +perror ("write" ); +exit (1 ); + } + p += nwritten; + n -= nwritten; + }while (n >0 ); + } }if (pad) {
---
base-commit: af4e9ef3d78420feb8fe58cd9a1ab80c501b3c08
change-id: 20260303-alpha-fix-ce5f70ee801d
Best regards,
Signature · 1 line
Maximilian Pezzullo <[email protected]>