summaryrefslogtreecommitdiff
path: root/contrib/pgcrypto
diff options
context:
space:
mode:
authorTom Lane2004-05-07 00:24:59 +0000
committerTom Lane2004-05-07 00:24:59 +0000
commit0bd61548ab8d1ac5fee63f48ee9b384502a51ad6 (patch)
treeb0c63b75585d0c396e67a3acd204e226b13eae4b /contrib/pgcrypto
parent4d46274b33db52618ccf49550213b4d5ce4a7981 (diff)
Solve the 'Turkish problem' with undesirable locale behavior for case
conversion of basic ASCII letters. Remove all uses of strcasecmp and strncasecmp in favor of new functions pg_strcasecmp and pg_strncasecmp; remove most but not all direct uses of toupper and tolower in favor of pg_toupper and pg_tolower. These functions use the same notions of case folding already developed for identifier case conversion. I left the straight locale-based folding in place for situations where we are just manipulating user data and not trying to match it to built-in strings --- for example, the SQL upper() function is still locale dependent. Perhaps this will prove not to be what's wanted, but at the moment we can initdb and pass regression tests in Turkish locale.
Diffstat (limited to 'contrib/pgcrypto')
-rw-r--r--contrib/pgcrypto/internal.c4
-rw-r--r--contrib/pgcrypto/md5.c4
-rw-r--r--contrib/pgcrypto/mhash.c8
-rw-r--r--contrib/pgcrypto/pgcrypto.c33
-rw-r--r--contrib/pgcrypto/px-crypt.c4
-rw-r--r--contrib/pgcrypto/px.c4
-rw-r--r--contrib/pgcrypto/sha1.c10
7 files changed, 29 insertions, 38 deletions
diff --git a/contrib/pgcrypto/internal.c b/contrib/pgcrypto/internal.c
index 4dca6dba541..db7b46da067 100644
--- a/contrib/pgcrypto/internal.c
+++ b/contrib/pgcrypto/internal.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/internal.c,v 1.12 2003/11/29 22:39:28 pgsql Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/internal.c,v 1.13 2004/05/07 00:24:57 tgl Exp $
*/
@@ -561,7 +561,7 @@ px_find_digest(const char *name, PX_MD ** res)
PX_MD *h;
for (p = int_digest_list; p->name; p++)
- if (!strcasecmp(p->name, name))
+ if (pg_strcasecmp(p->name, name) == 0)
{
h = px_alloc(sizeof(*h));
p->init(h);
diff --git a/contrib/pgcrypto/md5.c b/contrib/pgcrypto/md5.c
index 35bbe787118..4a236178760 100644
--- a/contrib/pgcrypto/md5.c
+++ b/contrib/pgcrypto/md5.c
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/contrib/pgcrypto/md5.c,v 1.10 2003/11/29 22:39:28 pgsql Exp $ */
+/* $PostgreSQL: pgsql/contrib/pgcrypto/md5.c,v 1.11 2004/05/07 00:24:57 tgl Exp $ */
/* $KAME: md5.c,v 1.3 2000/02/22 14:01:17 itojun Exp $ */
/*
@@ -141,7 +141,7 @@ md5_init(md5_ctxt * ctxt)
ctxt->md5_stb = MD5_B0;
ctxt->md5_stc = MD5_C0;
ctxt->md5_std = MD5_D0;
- bzero(ctxt->md5_buf, sizeof(ctxt->md5_buf));
+ memset(ctxt->md5_buf, 0, sizeof(ctxt->md5_buf));
}
void
diff --git a/contrib/pgcrypto/mhash.c b/contrib/pgcrypto/mhash.c
index 1ecfca6bed1..934a83271df 100644
--- a/contrib/pgcrypto/mhash.c
+++ b/contrib/pgcrypto/mhash.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/mhash.c,v 1.9 2003/11/29 22:39:28 pgsql Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/mhash.c,v 1.10 2004/05/07 00:24:57 tgl Exp $
*/
#include <postgres.h>
@@ -217,9 +217,9 @@ find_hashid(const char *name)
mname = mhash_get_hash_name(i);
if (mname == NULL)
continue;
- b = strcasecmp(name, mname);
+ b = pg_strcasecmp(name, mname);
free(mname);
- if (!b)
+ if (b == 0)
{
res = i;
break;
@@ -312,7 +312,7 @@ px_find_cipher(const char *name, PX_Cipher ** res)
PX_Cipher *c;
- strcpy(nbuf, name);
+ StrNCpy(nbuf, name, sizeof(nbuf));
if ((p = strrchr(nbuf, '-')) != NULL)
{
diff --git a/contrib/pgcrypto/pgcrypto.c b/contrib/pgcrypto/pgcrypto.c
index 6efc044b007..f28f960ad05 100644
--- a/contrib/pgcrypto/pgcrypto.c
+++ b/contrib/pgcrypto/pgcrypto.c
@@ -26,13 +26,16 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgcrypto.c,v 1.15 2003/11/29 22:39:28 pgsql Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgcrypto.c,v 1.16 2004/05/07 00:24:57 tgl Exp $
*/
-#include <postgres.h>
-#include <fmgr.h>
+#include "postgres.h"
+
#include <ctype.h>
+#include "fmgr.h"
+#include "parser/scansup.h"
+
#include "px.h"
#include "px-crypt.h"
#include "pgcrypto.h"
@@ -554,26 +557,12 @@ find_provider(text *name,
char *desc, int silent)
{
void *res;
- char buf[PX_MAX_NAMELEN + 1],
- *p;
- unsigned len;
- unsigned i;
+ char *buf;
int err;
- len = VARSIZE(name) - VARHDRSZ;
- if (len > PX_MAX_NAMELEN)
- {
- if (silent)
- return NULL;
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("%s type does not exist (name too long)", desc)));
- }
-
- p = VARDATA(name);
- for (i = 0; i < len; i++)
- buf[i] = tolower((unsigned char) p[i]);
- buf[len] = 0;
+ buf = downcase_truncate_identifier(VARDATA(name),
+ VARSIZE(name) - VARHDRSZ,
+ false);
err = provider_lookup(buf, &res);
@@ -582,5 +571,7 @@ find_provider(text *name,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("%s type does not exist: \"%s\"", desc, buf)));
+ pfree(buf);
+
return err ? NULL : res;
}
diff --git a/contrib/pgcrypto/px-crypt.c b/contrib/pgcrypto/px-crypt.c
index 84a3e78f9d3..463d1ddf731 100644
--- a/contrib/pgcrypto/px-crypt.c
+++ b/contrib/pgcrypto/px-crypt.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/px-crypt.c,v 1.7 2003/11/29 22:39:28 pgsql Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/px-crypt.c,v 1.8 2004/05/07 00:24:57 tgl Exp $
*/
#include <postgres.h>
@@ -170,7 +170,7 @@ px_gen_salt(const char *salt_type, char *buf, int rounds)
for (i = 0; gen_list[i].name; i++)
{
g = &gen_list[i];
- if (strcasecmp(g->name, salt_type) != 0)
+ if (pg_strcasecmp(g->name, salt_type) != 0)
continue;
if (g->def_rounds)
diff --git a/contrib/pgcrypto/px.c b/contrib/pgcrypto/px.c
index 1f5aa434b4d..49c4bdc7317 100644
--- a/contrib/pgcrypto/px.c
+++ b/contrib/pgcrypto/px.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/px.c,v 1.8 2003/11/29 22:39:28 pgsql Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/px.c,v 1.9 2004/05/07 00:24:57 tgl Exp $
*/
#include <postgres.h>
@@ -39,7 +39,7 @@ px_resolve_alias(const PX_Alias * list, const char *name)
{
while (list->name)
{
- if (!strcasecmp(list->alias, name))
+ if (pg_strcasecmp(list->alias, name) == 0)
return list->name;
list++;
}
diff --git a/contrib/pgcrypto/sha1.c b/contrib/pgcrypto/sha1.c
index 21df9d6ff8b..0fc78bba437 100644
--- a/contrib/pgcrypto/sha1.c
+++ b/contrib/pgcrypto/sha1.c
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/contrib/pgcrypto/sha1.c,v 1.12 2003/11/29 22:39:28 pgsql Exp $ */
+/* $PostgreSQL: pgsql/contrib/pgcrypto/sha1.c,v 1.13 2004/05/07 00:24:57 tgl Exp $ */
/* $KAME: sha1.c,v 1.3 2000/02/22 14:01:18 itojun Exp $ */
/*
@@ -227,7 +227,7 @@ sha1_step(struct sha1_ctxt * ctxt)
H(3) = H(3) + d;
H(4) = H(4) + e;
- bzero(&ctxt->m.b8[0], 64);
+ memset(&ctxt->m.b8[0], 0, 64);
}
/*------------------------------------------------------------*/
@@ -235,7 +235,7 @@ sha1_step(struct sha1_ctxt * ctxt)
void
sha1_init(struct sha1_ctxt * ctxt)
{
- bzero(ctxt, sizeof(struct sha1_ctxt));
+ memset(ctxt, 0, sizeof(struct sha1_ctxt));
H(0) = 0x67452301;
H(1) = 0xefcdab89;
H(2) = 0x98badcfe;
@@ -255,14 +255,14 @@ sha1_pad(struct sha1_ctxt * ctxt)
padlen = 64 - padstart;
if (padlen < 8)
{
- bzero(&ctxt->m.b8[padstart], padlen);
+ memset(&ctxt->m.b8[padstart], 0, padlen);
COUNT += padlen;
COUNT %= 64;
sha1_step(ctxt);
padstart = COUNT % 64; /* should be 0 */
padlen = 64 - padstart; /* should be 64 */
}
- bzero(&ctxt->m.b8[padstart], padlen - 8);
+ memset(&ctxt->m.b8[padstart], 0, padlen - 8);
COUNT += (padlen - 8);
COUNT %= 64;
#if BYTE_ORDER == BIG_ENDIAN