From: Vitaly Chikunov <vt@altlinux.org>
To: Mimi Zohar <zohar@linux.ibm.com>
Cc: Mimi Zohar <zohar@linux.vnet.ibm.com>,
Dmitry Kasatkin <dmitry.kasatkin@gmail.com>,
linux-integrity@vger.kernel.org
Subject: Re: [PATCH v1 4/5] ima-evm-utils: Fix file2bin stat and fopen relations
Date: Mon, 15 Jul 2019 23:04:07 +0300 [thread overview]
Message-ID: <20190715200407.dfltjurut4ennd6g@altlinux.org> (raw)
In-Reply-To: <1563217774.4539.146.camel@linux.ibm.com>
Mimi,
On Mon, Jul 15, 2019 at 03:09:34PM -0400, Mimi Zohar wrote:
> On Sat, 2019-07-13 at 00:28 +0300, Vitaly Chikunov wrote:
> > @@ -186,18 +187,32 @@ static unsigned char *file2bin(const char *file, const char *ext, int *size)
> >
> > log_info("Reading to %s\n", name);
> >
> > - len = get_filesize(name);
> > fp = fopen(name, "r");
> > if (!fp) {
> > log_err("Failed to open: %s\n", name);
> > return NULL;
> > }
> > + if (fstat(fileno(fp), &stats) == -1) {
> > + log_err("Failed to fstat: %s (%s)\n", name, strerror(errno));
> > + fclose(fp);
> > + return NULL;
> > + }
> > + len = stats.st_size;
> > +
> > data = malloc(len);
> > - if (!fread(data, len, 1, fp))
> > - len = 0;
> > + if (!data) {
> > + log_err("Failed to malloc %zu bytes: %s\n", len, name);
>
> Missing "free(data)"
In the next patch set I will apply all your suggestions except this one,
because this is return where data was not allocated.
> > + fclose(fp);
> > + return NULL;
> > + }
> > + if (fread(data, len, 1, fp) != len) {
> > + log_err("Failed to fread %zu bytes: %s\n", len, name);
> > + fclose(fp);
>
> and here
> > + return NULL;
> > + }
> > fclose(fp);
> >
> > - *size = len;
> > + *size = (int)len;
> > return data;
> > }
> >
next prev parent reply other threads:[~2019-07-15 20:04 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-12 21:28 [PATCH v1 1/5] ima-evm-utils: Fix null dereference from file2bin to memcpy Vitaly Chikunov
2019-07-12 21:28 ` [PATCH v1 2/5] ima-evm-utils: Fix possible strcpy overflow Vitaly Chikunov
2019-07-15 19:08 ` Mimi Zohar
2019-07-15 20:05 ` Vitaly Chikunov
2019-07-12 21:28 ` [PATCH v1 3/5] ima-evm-utils: Fix memory leak in get_password Vitaly Chikunov
2019-07-12 21:28 ` [PATCH v1 4/5] ima-evm-utils: Fix file2bin stat and fopen relations Vitaly Chikunov
2019-07-15 19:09 ` Mimi Zohar
2019-07-15 20:04 ` Vitaly Chikunov [this message]
2019-07-12 21:28 ` [PATCH v1 5/5] ima-evm-utils: Add more error checking in add_file_hash Vitaly Chikunov
2019-07-15 19:08 ` [PATCH v1 1/5] ima-evm-utils: Fix null dereference from file2bin to memcpy Mimi Zohar
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=20190715200407.dfltjurut4ennd6g@altlinux.org \
--to=vt@altlinux.org \
--cc=dmitry.kasatkin@gmail.com \
--cc=linux-integrity@vger.kernel.org \
--cc=zohar@linux.ibm.com \
--cc=zohar@linux.vnet.ibm.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 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 NNTP newsgroup(s).