public inbox for linux-alpha@vger.kernel.org
 help / color / mirror / Atom feed
From: Maximilian Pezzullo via B4 Relay <devnull+maximilianpezzullo.gmail.com@kernel.org>
To: Richard Henderson <richard.henderson@linaro.org>,
	 Matt Turner <mattst88@gmail.com>,
	Magnus Lindholm <linmag7@gmail.com>
Cc: linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Maximilian Pezzullo <maximilianpezzullo@gmail.com>
Subject: [PATCH] alpha: objstrip: fix partial write() buffer pointer not advancing
Date: Tue, 03 Mar 2026 23:06:17 +0100	[thread overview]
Message-ID: <20260303-alpha-fix-v1-1-89abede2a585@gmail.com> (raw)

From: Maximilian Pezzullo <maximilianpezzullo@gmail.com>

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.

Closes: https://bugzilla.kernel.org/show_bug.cgi?id=221159
Signed-off-by: Maximilian Pezzullo <maximilianpezzullo@gmail.com>
---
 arch/alpha/boot/tools/objstrip.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/arch/alpha/boot/tools/objstrip.c b/arch/alpha/boot/tools/objstrip.c
index 7cf92d172dc..8da25c2584f 100644
--- a/arch/alpha/boot/tools/objstrip.c
+++ b/arch/alpha/boot/tools/objstrip.c
@@ -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,
-- 
Maximilian Pezzullo <maximilianpezzullo@gmail.com>



                 reply	other threads:[~2026-03-03 22:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260303-alpha-fix-v1-1-89abede2a585@gmail.com \
    --to=devnull+maximilianpezzullo.gmail.com@kernel.org \
    --cc=linmag7@gmail.com \
    --cc=linux-alpha@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mattst88@gmail.com \
    --cc=maximilianpezzullo@gmail.com \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox