Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1elqBr-0002ni-Fr for pgsql-bugs@arkaria.postgresql.org; Wed, 14 Feb 2018 06:05:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1elqBq-0005ZY-4J for pgsql-bugs@arkaria.postgresql.org; Wed, 14 Feb 2018 06:05:10 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1elqBp-0005Z0-Kq for pgsql-bugs@lists.postgresql.org; Wed, 14 Feb 2018 06:05:09 +0000 Received: from new1-smtp.messagingengine.com ([66.111.4.221]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1elqBl-0000Az-PJ for pgsql-bugs@postgresql.org; Wed, 14 Feb 2018 06:05:08 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.nyi.internal (Postfix) with ESMTP id 2CBB613A6; Wed, 14 Feb 2018 01:05:04 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Wed, 14 Feb 2018 01:05:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=3/CMYzGh3+YXZv7gxGyz7WOWwjxMe 09bFmErKAMdgtk=; b=lIVaAUT7ZyoUz1R6HQ6PxQTOloeO0dzh36zh5bXv/dSjo SOwjDJyJKoczsD1ZuhcUARKOGx6/lG2H9yjPi9G0IDDLeiHAi3EEpNfyaqvq3J2g LgGMr6aDwVphhbsAWQTWlN6WLHZbV9+138+n5Z29hWAs1MHzPy7vIsYVa2xL3cuC wNMjczMpdUU6Kp5coz/UOCr9gRyQm+sFzegF/Z5WBl3J0E5AhAUwkIT6pG7ZtRoy lgWEOMR3PAkmg6I6PyC3CQxs0fJeBSairv2VKKxWxKj94s9bAESUltVgVBMWJ6Cg MC/QbqyTY4GY9vGByhYn4xWVcxfM2mnJoJevulDVQ== X-ME-Sender: Received: from paquier.xyz (c137162.net61215.cablenet.ne.jp [61.215.137.162]) by mail.messagingengine.com (Postfix) with ESMTPA id 58A802469C; Wed, 14 Feb 2018 01:05:02 -0500 (EST) Date: Wed, 14 Feb 2018 15:04:54 +0900 From: Michael Paquier To: Postgres bugs Cc: Rainer Orth Subject: Re: Conflicting declarations for b64_encode etc. on Solaris 11.4 Beta Message-ID: <20180214060454.GA4544@paquier.xyz> References: <20180124015251.GA14001@paquier.xyz> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="uZ3hkaAS1mZxFaxD" Content-Disposition: inline In-Reply-To: <20180124015251.GA14001@paquier.xyz> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --uZ3hkaAS1mZxFaxD Content-Type: multipart/mixed; boundary="45Z9DzgjV8m4Oswq" Content-Disposition: inline --45Z9DzgjV8m4Oswq Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jan 24, 2018 at 11:16:11AM +0900, Michael Paquier wrote: > I am not much a fan of using the same function name for both the > static functions in pgcrypto and encode.c, as well as what is in > src/common/. In order to avoid any conflicts, why not just changing at > least the prefix from "b64" to "base64"? That's not completely > problem-proof for the problem either, as php has a base64_encode for > example. So my suggestion would be to change the prefix on all > branches and to append pg_ to all the routines in encode.c for > consistency. Better naming suggestions welcome.=20 Attached is an updated patch which does a bit more consistency work. I have renamed the base64 functions with pg_base64_ as prefix in encode.c, to avoid any conflicts in encode.c. pgp-armor.c also gets the same treatment. There is no real point in renaming the other functions is not necessary, and hex_encode/hex_decode are publicly available, so renaming them would cause breakage for any callers of them in plugins. It is a bit sad that both pgcrypto and encode.c hold copies of base64 functions. If one looks closely, they use the same logic for pg_base64_encode, pg_base64_enc_len and pg_base64_dec_len. Each pg_b64_decode uses different code paths for error handling, but they actually have the same conversion logic (see b64_test.c attached which emulates both, I was too lazy to read and compare b64lookup). One way to remove the duplication is to extend the _decode API with a path to not complain with elog and return a status code, then have encode.c use a wrapper on top of it, but that may not be worth the complication, and both code copies are not going to change anyway. At the end, just the attached would do the work. Rainer, could you double-check if this solves your problem with Solaris 11? If you expect this OS to be supported, it would be nice if you could add a buildfarm machine: https://wiki.postgresql.org/wiki/PostgreSQL_Buildfarm_Howto https://buildfarm.postgresql.org/ There are currently two machines running Solaris 10, maintained by Dave Page: protosciurus and castoroides. But there is nothing for Solaris 11. I am adding that to the next commit fest for consideration as well under my name. I'll take care of any reviews and/or feedback. I'll add as well your name as author if I can find your community account, I hope you don't mind. -- Michael --45Z9DzgjV8m4Oswq Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="solaris-11-compile-v2.patch" Content-Transfer-Encoding: quoted-printable diff --git a/contrib/pgcrypto/pgp-armor.c b/contrib/pgcrypto/pgp-armor.c index 5c8355808a..aa5b563a31 100644 --- a/contrib/pgcrypto/pgp-armor.c +++ b/contrib/pgcrypto/pgp-armor.c @@ -42,7 +42,7 @@ static const unsigned char _base64[] =3D "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; =20 static int -b64_encode(const uint8 *src, unsigned len, uint8 *dst) +pg_base64_encode(const uint8 *src, unsigned len, uint8 *dst) { uint8 *p, *lend =3D dst + 76; @@ -92,7 +92,7 @@ b64_encode(const uint8 *src, unsigned len, uint8 *dst) =20 /* probably should use lookup table */ static int -b64_decode(const uint8 *src, unsigned len, uint8 *dst) +pg_base64_decode(const uint8 *src, unsigned len, uint8 *dst) { const uint8 *srcend =3D src + len, *s =3D src; @@ -160,7 +160,7 @@ b64_decode(const uint8 *src, unsigned len, uint8 *dst) } =20 static unsigned -b64_enc_len(unsigned srclen) +pg_base64_enc_len(unsigned srclen) { /* * 3 bytes will be converted to 4, linefeed after 76 chars @@ -169,7 +169,7 @@ b64_enc_len(unsigned srclen) } =20 static unsigned -b64_dec_len(unsigned srclen) +pg_base64_dec_len(unsigned srclen) { return (srclen * 3) >> 2; } @@ -218,11 +218,11 @@ pgp_armor_encode(const uint8 *src, unsigned len, Stri= ngInfo dst, appendStringInfo(dst, "%s: %s\n", keys[n], values[n]); appendStringInfoChar(dst, '\n'); =20 - /* make sure we have enough room to b64_encode() */ - b64len =3D b64_enc_len(len); + /* make sure we have enough room to pg_base64_encode() */ + b64len =3D pg_base64_enc_len(len); enlargeStringInfo(dst, (int) b64len); =20 - res =3D b64_encode(src, len, (uint8 *) dst->data + dst->len); + res =3D pg_base64_encode(src, len, (uint8 *) dst->data + dst->len); if (res > b64len) elog(FATAL, "overflow - encode estimate too small"); dst->len +=3D res; @@ -358,14 +358,14 @@ pgp_armor_decode(const uint8 *src, int len, StringInf= o dst) goto out; =20 /* decode crc */ - if (b64_decode(p + 1, 4, buf) !=3D 3) + if (pg_base64_decode(p + 1, 4, buf) !=3D 3) goto out; crc =3D (((long) buf[0]) << 16) + (((long) buf[1]) << 8) + (long) buf[2]; =20 /* decode data */ - blen =3D (int) b64_dec_len(len); + blen =3D (int) pg_base64_dec_len(len); enlargeStringInfo(dst, blen); - res =3D b64_decode(base64_start, base64_end - base64_start, (uint8 *) dst= ->data); + res =3D pg_base64_decode(base64_start, base64_end - base64_start, (uint8 = *) dst->data); if (res > blen) elog(FATAL, "overflow - decode estimate too small"); if (res >=3D 0) diff --git a/src/backend/utils/adt/encode.c b/src/backend/utils/adt/encode.c index f527ee2a43..56438382f6 100644 --- a/src/backend/utils/adt/encode.c +++ b/src/backend/utils/adt/encode.c @@ -215,7 +215,7 @@ static const int8 b64lookup[128] =3D { }; =20 static unsigned -b64_encode(const char *src, unsigned len, char *dst) +pg_base64_encode(const char *src, unsigned len, char *dst) { char *p, *lend =3D dst + 76; @@ -262,7 +262,7 @@ b64_encode(const char *src, unsigned len, char *dst) } =20 static unsigned -b64_decode(const char *src, unsigned len, char *dst) +pg_base64_decode(const char *src, unsigned len, char *dst) { const char *srcend =3D src + len, *s =3D src; @@ -332,14 +332,14 @@ b64_decode(const char *src, unsigned len, char *dst) =20 =20 static unsigned -b64_enc_len(const char *src, unsigned srclen) +pg_base64_enc_len(const char *src, unsigned srclen) { /* 3 bytes will be converted to 4, linefeed after 76 chars */ return (srclen + 2) * 4 / 3 + srclen / (76 * 3 / 4); } =20 static unsigned -b64_dec_len(const char *src, unsigned srclen) +pg_base64_dec_len(const char *src, unsigned srclen) { return (srclen * 3) >> 2; } @@ -532,7 +532,7 @@ static const struct { "base64", { - b64_enc_len, b64_dec_len, b64_encode, b64_decode + pg_base64_enc_len, pg_base64_dec_len, pg_base64_encode, pg_base64_decode } }, { --45Z9DzgjV8m4Oswq Content-Type: text/x-csrc; charset=us-ascii Content-Disposition: attachment; filename="b64_test.c" #include #define ASCII_NUM 128 static const int b64lookup[ASCII_NUM] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, }; int main() { int i; /* Compare the logic of both tables */ for (i = 0; i < ASCII_NUM; i++) { char c = i; int b_table, b_compare; /* method from pgcrypto */ if (c >= 'A' && c <= 'Z') b_compare = c - 'A'; else if (c >= 'a' && c <= 'z') b_compare = c - 'a' + 26; else if (c >= '0' && c <= '9') b_compare = c - '0' + 52; else if (c == '+') b_compare = 62; else if (c == '/') b_compare = 63; else { /* * Can be space, \t, \n, \r or invalid data, who cares. */ continue; } /* method from encode.c */ b_table = -1; if (c > 0 && c < 127) b_table = b64lookup[c]; if (b_table != b_compare) fprintf(stderr, "Incorrect conversion at char %c\n", c); } return 0; } --45Z9DzgjV8m4Oswq-- --uZ3hkaAS1mZxFaxD Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAlqD0YYACgkQnvQgOdby QH0UmRAApJdKHeiXkF9hTGyH0kTd3PfmpwSep06jSGRTZxqViiw+RxxwsaqA6muJ bPe7jRX19kOV1zTdPjFYYsqqyp0hWPFlrrBW4nvWC2s2gbj21hY4cFnlwqzYOrgU KEJjDfcQH16eJC5BZuOG1cRyo9bgEEpWvURtQpSf/VWBMs+gsIx62iKXh2tx/Ih8 5wZkJFmaXuXChoNwTbDuIvQ4HCoH26rNPMUN8ZufE3xvFJvOSeqkdZIuiYTmCU98 rThCvSPvgATXN6BtXjxhOxeFsKeQs8Bmrj1wntpVuQgvK2UfjEILLBs1t2tGGU2R 4/Xw6AfRwdyRqH4PaqCd6718llKg3bv/M2d2hMHgEz6wksd8+TVoKxex8tc75wDV MLMXzJNvMZRiFaZ6aqA+3WqSJq6ooXLN2g2Z0OoxDUbXAyCPzcYOG3VgtvYCGUiU IpQCFrhpfwG1izhzAk0AHhK5g5jfmXijSK3n4GzOaSgb1GfFYOx6+t3RmrSLbDl1 ThKTEER0DyAFr5faSRaNPdUii/kUvpfEKyCpcV/SyxowNSPSemM/JoZRG6OAf+GF RkCFbDW6oP2Lv3q5K30j9u7bAqPOn8tdCrk4EgwhOgs25q4ebV6ro5o1iAtwoz5i 1l0dEB62MMinP89Y0g+NaV164YoXa/YeWo4syrV38llzy1jDvPA= =rwPh -----END PGP SIGNATURE----- --uZ3hkaAS1mZxFaxD--