From: Dan Carpenter <dan.carpenter@oracle.com>
To: Tyler Hicks <tyhicks@canonical.com>
Cc: ecryptfs@vger.kernel.org
Subject: Re: is size correct in ecryptfs_parse_packet_length()
Date: Wed, 22 Oct 2014 10:58:30 +0300 [thread overview]
Message-ID: <20141022075830.GE26918@mwanda> (raw)
In-Reply-To: <20141021212952.GA18270@boyd>
On Tue, Oct 21, 2014 at 05:29:53PM -0400, Tyler Hicks wrote:
> > 101 if (data[0] < 192) {
> > 102 /* One-byte length */
> > 103 (*size) = (unsigned char)data[0];
> > 104 (*length_size) = 1;
> > 105 } else if (data[0] < 224) {
> > 106 /* Two-byte length */
> > 107 (*size) = (((unsigned char)(data[0]) - 192) * 256);
> > ^^^^^^^^^^^^^^^
> > 108 (*size) += ((unsigned char)(data[1]) + 192);
> > ^^^^^^^^^^^^^^^
> > These casts are no-ops because they are "data" is an unsigned char
> > pointer already. Then the value is type promoted to int, we subtract
> > 192 giving a negative number and we multiply by 256 giving a slightly
> > larger negative then we save it as a very large positive.
>
> Subtracting 192 from data[0] should never result in a negative number.
> We know that data[0] is greater than or equal to 192 (and less than 224)
> because the previous conditional was false.
>
Oh right. Duh... Thanks.
We could remove the casting though because it's a no-op?
regards,
dan carpenter
next prev parent reply other threads:[~2014-10-22 7:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-21 12:04 is size correct in ecryptfs_parse_packet_length() Dan Carpenter
2014-10-21 21:29 ` Tyler Hicks
2014-10-22 7:58 ` Dan Carpenter [this message]
2014-10-23 14:38 ` [PATCH] eCryptfs: Remove unnecessary casts when parsing packet lengths Tyler Hicks
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=20141022075830.GE26918@mwanda \
--to=dan.carpenter@oracle.com \
--cc=ecryptfs@vger.kernel.org \
--cc=tyhicks@canonical.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.