Thread (41 messages) flat view 41 messages, 6 authors, 1d ago
DORMANTno replies

Revision v2 of 2 in this series.

Revisions (2)
  1. rfc [diff vs current]
  2. v2 current

[PATCH v2 5/7] object-name: use hexval

From: brian m. carlson <hidden>
Date: 2026-09-07 20:00:01
Subsystem: the rest · Maintainer: Linus Torvalds

We've open-coded a different implementation of parsing hex values here
when we already have a perfectly good one in hexval.  This
implementation will almost certainly be slower because it isn't
table-driven, unlike the other one, and since it's not constant time it
has no other advantages either.  To tidy things up and prepare for
future work, switch to hexval in this case.

Because hexval returns an unsigned int, check to see if the value is
invalid by looking for any bits beyond a single unsigned character.  In
addition, be sure to continue to force the hexadecimal value to
lowercase.

Signed-off-by: brian m. carlson <redacted>
---
 object-name.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
diff --git a/object-name.c b/object-name.c
index 4eda8c8eac..8f2da51547 100644
--- a/object-name.c
+++ b/object-name.c
@@ -236,20 +236,13 @@ static int parse_oid_prefix(const char *name, int len,
 {
 	for (int i = 0; i < len; i++) {
 		unsigned char c = name[i];
-		unsigned char val;
-		if (c >= '0' && c <= '9') {
-			val = c - '0';
-		} else if (c >= 'a' && c <= 'f') {
-			val = c - 'a' + 10;
-		} else if (c >= 'A' && c <='F') {
-			val = c - 'A' + 10;
-			c -= 'A' - 'a';
-		} else {
+		int val = hexval(c, HEX_KIND_OID);
+
+		if (val & ~0xff)
 			return -1;
-		}
 
 		if (hex_out)
-			hex_out[i] = c;
+			hex_out[i] = tolower(c);
 		if (oid_out) {
 			if (!(i & 1))
 				val <<= 4;
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help