Subject: pkg/23532: openssl package fails to parse hex version number with awk
To: None <gnats-bugs@gnats.netbsd.org>
From: None <mlelstv@serpens.de>
List: netbsd-bugs
Date: 11/22/2003 11:47:24
>Number:         23532
>Category:       pkg
>Synopsis:       openssl package fails to parse hex version number with awk
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Nov 22 10:48:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Michael van Elst
>Release:        NetBSD 1.6.1_STABLE
>Organization:
-- 
                                Michael van Elst
Internet: mlelstv@serpens.de
                                "A potential Snark may lurk in every tree."
>Environment:
	
	
System: NetBSD pepew 1.6.1_STABLE NetBSD 1.6.1_STABLE (PEPEW) #38: Mon Sep 29 21:17:31 MEST 2003 src@pepew:/amd/fud/d/0/src/sys/arch/i386/compile/PEPEW i386
Architecture: i386
Machine: i386
>Description:
The buildlink2 script in the openssl package tries to synthesize a version
number for the openssl version distributed with the base system.

This is done by a small awk script that parses the OPENSSL_VERSION_NUMBER
macro in the /usr/include/openssl/opensslv.h header. That macro defines
a hexadecimal number that merges major, minor, teeny and patchlevel versions
into a single number and the script tries to split the constituents.

Unfortunately it treats each part as a decimal number, failing to parse
versions like 0x009060cfL where the patchlevel '0c' contains a non-digit.

>How-To-Repeat:
Patch base system to include openssl 0.9.6l and wonder why the package
system still tries to install openssl from the package system.

>Fix:

Index: buildlink2.mk
===================================================================
RCS file: /cvsroot/pkgsrc/security/openssl/buildlink2.mk,v
retrieving revision 1.11
diff -u -r1.11 buildlink2.mk
--- buildlink2.mk	2003/11/17 15:25:57	1.11
+++ buildlink2.mk	2003/11/22 10:45:33
@@ -38,24 +38,31 @@
 # version or if the built-in one is sufficient.
 #
 _OPENSSL_MAJOR!=							\
-	${AWK} '/\#define[ 	]*OPENSSL_VERSION_NUMBER/ {		\
-			print int(substr($$3, 3, 1)); exit 0;		\
+	${AWK} 'BEGIN { x="0123456789abcdef" }				\
+		/\#define[ 	]*OPENSSL_VERSION_NUMBER/ {		\
+			print index(x,substr($$3, 3, 1))		\
+				- 1;					\
+			exit 0;						\
 		}							\
 	' ${_OPENSSL_OPENSSLV_H}
 _OPENSSL_MINOR!=							\
-	${AWK} '/\#define[ 	]*OPENSSL_VERSION_NUMBER/ {		\
-			print "." int(substr($$3, 4, 2)); exit 0;	\
+	${AWK} 'BEGIN { x="0123456789abcdef" }				\
+		/\#define[ 	]*OPENSSL_VERSION_NUMBER/ {		\
+			print "." 16*index(x,substr($$3, 4, 1))+index(x,substr($$3, 5, 1))-17; \
+			exit 0;						\
 		}							\
 	' ${_OPENSSL_OPENSSLV_H}
 _OPENSSL_TEENY!=							\
-	${AWK} '/\#define[ 	]*OPENSSL_VERSION_NUMBER/ {		\
-			print "." int(substr($$3, 6, 2)); exit 0;	\
+	${AWK} 'BEGIN { x="0123456789abcdef" }				\
+		/\#define[ 	]*OPENSSL_VERSION_NUMBER/ {		\
+			print "." 16*index(x,substr($$3, 6, 1))+index(x,substr($$3, 7, 1))-17; \
 		}							\
 	' ${_OPENSSL_OPENSSLV_H}
 _OPENSSL_PATCHLEVEL!=							\
-	${AWK} 'BEGIN { split("abcdefghijklmnopqrstuvwxyz", alpha, "") } \
+	${AWK} 'BEGIN { split("abcdefghijklmnopqrstuvwxyz", alpha, "");	\
+			x="0123456789abcdef" }				\
 		/\#define[ 	]*OPENSSL_VERSION_NUMBER/ {		\
-			i = int(substr($$3, 8, 2));			\
+			i = 16*index(x,substr($$3, 8, 1))+index(x,substr($$3, 9, 1))-17; \
 			if (i == 0) {					\
 				print "";				\
 			} else if (i > 26) {				\

>Release-Note:
>Audit-Trail:
>Unformatted: