public inbox for debugedit@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: debugedit@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH] debugedit: check write to list_file succeeds
Date: Thu,  1 Jul 2021 17:17:59 +0200	[thread overview]
Message-ID: <20210701151759.329591-1-mark@klomp.org> (raw)

We didn't check, or ignored, errors writing to the list_file. Always
produce an error if we cannot write to the list_file.

	* debugedit.c (read_dwarf4_line): Produce error if write fails.
	(read_dwarf5_line_entries): Likewise.
	(edit_attributes): Likewise.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 tools/debugedit.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/tools/debugedit.c b/tools/debugedit.c
index 80b99fe..f07b6e1 100644
--- a/tools/debugedit.c
+++ b/tools/debugedit.c
@@ -1785,7 +1785,7 @@ read_dwarf4_line (DSO *dso, unsigned char *ptr, char *comp_dir,
 		{
 		  ssize_t ret = write (list_file_fd, p, size);
 		  if (ret == -1)
-		    break;
+		    error (1, errno, "Could not write to '%s'", list_file);
 		  size -= ret;
 		  p += ret;
 		}
@@ -2005,7 +2005,7 @@ read_dwarf5_line_entries (DSO *dso, unsigned char **ptrp,
 		    {
 		      ssize_t ret = write (list_file_fd, p, size);
 		      if (ret == -1)
-			break;
+			error (1, errno, "Could not write to '%s'", list_file);
 		      size -= ret;
 		      p += ret;
 		    }
@@ -2348,7 +2348,7 @@ edit_attributes (DSO *dso, unsigned char *ptr, struct abbrev_tag *t, int phase)
 	    {
 	      ssize_t ret = write (list_file_fd, p, size);
 	      if (ret == -1)
-		break;
+		error (1, errno, "Could not write to '%s'", list_file);
 	      size -= ret;
 	      p += ret;
 	    }
@@ -2356,10 +2356,13 @@ edit_attributes (DSO *dso, unsigned char *ptr, struct abbrev_tag *t, int phase)
 	     regular files. */
 	  if (size == 0)
 	    {
+	      ssize_t ret;
 	      if (*(p - 1) != '/')
-		write (list_file_fd, "/", 2);
+		ret = write (list_file_fd, "/", 2);
 	      else
-		write (list_file_fd, "", 1);
+		ret = write (list_file_fd, "", 1);
+	      if (ret == -1)
+		error (1, errno, "Could not write to '%s'", list_file);
 	    }
 	}
     }
-- 
2.32.0


             reply	other threads:[~2021-07-01 15:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-01 15:17 Mark Wielaard [this message]
2021-07-05 14:39 ` Mark Wielaard

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=20210701151759.329591-1-mark@klomp.org \
    --to=mark@klomp.org \
    --cc=debugedit@sourceware.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).