All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yi-Yo Chiang <yochiang@google.com>
To: selinux@vger.kernel.org
Cc: Yi-Yo Chiang <yochiang@google.com>
Subject: [PATCH] secilc.c: Don't fail if input file is empty
Date: Wed, 14 Apr 2021 22:10:27 +0800	[thread overview]
Message-ID: <20210414141027.3494107-1-yochiang@google.com> (raw)

fread(3) returns zero if |size| is zero. This confuses secilc, and
causes it to fail with a "Failure reading file" error, even though there
is no error.

Add a shortcut that closes and skips an input file if file size is zero.

Signed-off-by: Yi-Yo Chiang <yochiang@google.com>
---
 secilc/secilc.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/secilc/secilc.c b/secilc/secilc.c
index 186c5a73..9c78e425 100644
--- a/secilc/secilc.c
+++ b/secilc/secilc.c
@@ -268,6 +268,12 @@ int main(int argc, char *argv[])
 		}
 		file_size = filedata.st_size;
 
+		if (!file_size) {
+			fclose(file);
+			file = NULL;
+			continue;
+		}
+
 		buffer = malloc(file_size);
 		rc = fread(buffer, file_size, 1, file);
 		if (rc != 1) {
-- 
2.31.1.295.g9ea45b61b8-goog


             reply	other threads:[~2021-04-14 14:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-14 14:10 Yi-Yo Chiang [this message]
2021-04-14 19:18 ` [PATCH] secilc.c: Don't fail if input file is empty James Carter
2021-04-19 14:33   ` James Carter

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=20210414141027.3494107-1-yochiang@google.com \
    --to=yochiang@google.com \
    --cc=selinux@vger.kernel.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 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.