All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zdenek Kabelac <zkabelac@sourceware.org>
To: lvm-devel@redhat.com
Subject: master - pvck: add simple check for fwrite
Date: Tue,  1 Sep 2020 21:41:31 +0000 (GMT)	[thread overview]
Message-ID: <20200901214131.8BFC93870874@sourceware.org> (raw)

Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=11f08dacc920dba49d932ccdf378331a32bad9d9
Commit:        11f08dacc920dba49d932ccdf378331a32bad9d9
Parent:        66803586ef6d7ef7bcf4260b66e85ef2fa8c7022
Author:        Zdenek Kabelac <zkabelac@redhat.com>
AuthorDate:    Tue Sep 1 21:14:39 2020 +0200
Committer:     Zdenek Kabelac <zkabelac@redhat.com>
CommitterDate: Tue Sep 1 23:40:24 2020 +0200

pvck: add simple check for fwrite

Add at least very light check for result code of fwrite().
---
 tools/pvck.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/pvck.c b/tools/pvck.c
index 73ef6ceff..302c74621 100644
--- a/tools/pvck.c
+++ b/tools/pvck.c
@@ -846,6 +846,7 @@ static int _dump_meta_area(struct device *dev, struct devicefile *def, const cha
 {
 	FILE *fp;
 	char *meta_buf;
+	int ret = 1;
 
 	if (!tofile)
 		return_0;
@@ -866,7 +867,11 @@ static int _dump_meta_area(struct device *dev, struct devicefile *def, const cha
 		return 0;
 	}
 
-	fwrite(meta_buf, mda_size - 512, 1, fp);
+	if (fwrite(meta_buf, mda_size - 512, 1, fp) != 1) {
+		log_error("Failed to write file %s metadata area size %llu.",
+			  tofile, (unsigned long long)mda_size);
+		ret = 0;
+	}
 
 	free(meta_buf);
 
@@ -874,7 +879,7 @@ static int _dump_meta_area(struct device *dev, struct devicefile *def, const cha
 		stack;
 	if (fclose(fp))
 		stack;
-	return 1;
+	return ret;
 }
 
 /* all sizes and offsets in bytes */



                 reply	other threads:[~2020-09-01 21:41 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=20200901214131.8BFC93870874@sourceware.org \
    --to=zkabelac@sourceware.org \
    --cc=lvm-devel@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.