mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: Andrew Morton <akpm@linux-foundation.org>, zzz <abc0eichs@qq.com>
Cc: linux-kernel@vger.kernel.org, Jarkko Sakkinen <jarkko@kernel.org>,
	David Howells <dhowells@redhat.com>,
	keyrings@vger.kernel.org, linux-integrity@vger.kernel.org
Subject: Re: [PATCH] lib/asn1_encoder: fix encoding of zero OID components
Date: Tue, 24 Nov 2026 08:56:59 -0500	[thread overview]
Message-ID: <b4c2860a41daafb789a2386f2779e5f9f8741d8e.camel@HansenPartnership.com> (raw)
In-Reply-To: <20261123220311.9ee34b6c33545185d41d09ce@linux-foundation.org>

On Mon, 2026-11-23 at 22:03 -0800, Andrew Morton wrote:
> On Fri, 20 Nov 2026 21:00:55 +0800 zzz <abc0eichs@qq.com> wrote:
> > --- a/lib/asn1_encoder.c
> > +++ b/lib/asn1_encoder.c
> > @@ -97,7 +97,7 @@ static int asn1_encode_oid_digit(unsigned char
> > **_data, int *data_len, u32 oid)
> >  
> >  	/* quick case */
> >  	if (oid == 0) {
> > -		*data++ = 0x80;
> > +		*data++ = 0;
> >  		(*data_len)--;
> >  		goto out;
> >  	}

Yes, well, I was just thinking about the single case when I wrote it.
Actually, wouldn't getting rid of all the special casing make this code
more maintainable.  Something like

diff --git a/lib/asn1_encoder.c b/lib/asn1_encoder.c
index 92f35aae13b1..fc97cb4d27fa 100644
--- a/lib/asn1_encoder.c
+++ b/lib/asn1_encoder.c
@@ -92,15 +92,9 @@ static int asn1_encode_oid_digit(unsigned char
**_data, int *data_len, u32 oid)
 	int start = 7 + 7 + 7 + 7;
 	int ret = 0;
 
-	if (*data_len < 1)
-		return -EINVAL;
-
 	/* quick case */
-	if (oid == 0) {
-		*data++ = 0x80;
-		(*data_len)--;
-		goto out;
-	}
+	if (oid >> 7 == 0)
+		goto encode_last;
 
 	while (oid >> start == 0)
 		start -= 7;
@@ -116,6 +110,7 @@ static int asn1_encode_oid_digit(unsigned char
**_data, int *data_len, u32 oid)
 		(*data_len)--;
 	}
 
+ encode_last:
 	if (*data_len > 0) {
 		*data++ = oid;
 		(*data_len)--;
@@ -123,7 +118,6 @@ static int asn1_encode_oid_digit(unsigned char
**_data, int *data_len, u32 oid)
 		ret = -EINVAL;
 	}
 
- out:
 	*_data = data;
 	return ret;
 }

?

James

      parent reply	other threads:[~2026-11-24 13:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 13:00 zzz
2026-11-24  6:03 ` Andrew Morton
2026-11-24  9:21   ` Jarkko Sakkinen
2026-11-24 13:56   ` James Bottomley [this message]

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=b4c2860a41daafb789a2386f2779e5f9f8741d8e.camel@HansenPartnership.com \
    --to=james.bottomley@hansenpartnership.com \
    --cc=abc0eichs@qq.com \
    --cc=akpm@linux-foundation.org \
    --cc=dhowells@redhat.com \
    --cc=jarkko@kernel.org \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®