/*-------------------------------------------------------------------------
* saslprep . c
* SASLprep normalization , for SCRAM authentication
*
* The SASLprep algorithm is used to process a user - supplied password into
* canonical form . For more details , see :
*
* [ RFC3454 ] Preparation of Internationalized Strings ( " stringprep " ) ,
* http : //www.ietf.org/rfc/rfc3454.txt
*
* [ RFC4013 ] SASLprep : Stringprep Profile for User Names and Passwords
* http : //www.ietf.org/rfc/rfc4013.txt
*
*
* Portions Copyright ( c ) 2017 - 2025 , PostgreSQL Global Development Group
*
* IDENTIFICATION
* src / common / saslprep . c
*
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
#ifndef FRONTEND
#include "postgres.h"
#include "utils/memutils.h"
#else
#include "postgres_fe.h"
#endif
#include "common/saslprep.h"
#include "common/string.h"
#include "common/unicode_norm.h"
#include "mb/pg_wchar.h"
/*
* In backend , we will use palloc / pfree . In frontend , use malloc , and
* return SASLPREP_OOM on out - of - memory .
*/
#ifndef FRONTEND
#define STRDUP(s) pstrdup(s)
#define ALLOC(size) palloc(size)
#define FREE(size) pfree(size)
#else
#define STRDUP(s) strdup(s)
#define ALLOC(size) malloc(size)
#define FREE(size) free(size)
#endif
/* Prototypes for local functions */
static int codepoint_range_cmp(const void *a, const void *b);
static bool is_code_in_table(pg_wchar code, const pg_wchar *map, int mapsize);
static int pg_utf8_string_len(const char *source);
/*
* Stringprep Mapping Tables .
*
* The stringprep specification includes a number of tables of Unicode
* codepoints , used in different parts of the algorithm . They are below ,
* as arrays of codepoint ranges . Each range is a pair of codepoints ,
* for the first and last codepoint included the range ( inclusive ! ) .
*/
/*
* C . 1 . 2 Non - ASCII space characters
*
* These are all mapped to the ASCII space character ( U + 00 A0 ) .
*/
static const pg_wchar non_ascii_space_ranges[] =
{
0 x00A0, 0 x00A0,
0 x1680, 0 x1680,
0 x2000, 0 x200B,
0 x202F, 0 x202F,
0 x205F, 0 x205F,
0 x3000, 0 x3000
};
/*
* B . 1 Commonly mapped to nothing
*
* If any of these appear in the input , they are removed .
*/
static const pg_wchar commonly_mapped_to_nothing_ranges[] =
{
0 x00AD, 0 x00AD,
0 x034F, 0 x034F,
0 x1806, 0 x1806,
0 x180B, 0 x180D,
0 x200B, 0 x200D,
0 x2060, 0 x2060,
0 xFE00, 0 xFE0F,
0 xFEFF, 0 xFEFF
};
/*
* prohibited_output_ranges is a union of all the characters from
* the following tables :
*
* C . 1 . 2 Non - ASCII space characters
* C . 2 . 1 ASCII control characters
* C . 2 . 2 Non - ASCII control characters
* C . 3 Private Use characters
* C . 4 Non - character code points
* C . 5 Surrogate code points
* C . 6 Inappropriate for plain text characters
* C . 7 Inappropriate for canonical representation characters
* C . 7 Change display properties or deprecated characters
* C . 8 Tagging characters
*
* These are the tables that are listed as " prohibited output "
* characters in the SASLprep profile .
*
* The comment after each code range indicates which source table
* the code came from . Note that there is some overlap in the source
* tables , so one code might originate from multiple source tables .
* Adjacent ranges have also been merged together , to save space .
*/
static const pg_wchar prohibited_output_ranges[] =
{
0 x0000, 0 x001F, /* C.2.1 */
0 x007F, 0 x00A0, /* C.1.2, C.2.1, C.2.2 */
0 x0340, 0 x0341, /* C.8 */
0 x06DD, 0 x06DD, /* C.2.2 */
0 x070F, 0 x070F, /* C.2.2 */
0 x1680, 0 x1680, /* C.1.2 */
0 x180E, 0 x180E, /* C.2.2 */
0 x2000, 0 x200F, /* C.1.2, C.2.2, C.8 */
0 x2028, 0 x202F, /* C.1.2, C.2.2, C.8 */
0 x205F, 0 x2063, /* C.1.2, C.2.2 */
0 x206A, 0 x206F, /* C.2.2, C.8 */
0 x2FF0, 0 x2FFB, /* C.7 */
0 x3000, 0 x3000, /* C.1.2 */
0 xD800, 0 xF8FF, /* C.3, C.5 */
0 xFDD0, 0 xFDEF, /* C.4 */
0 xFEFF, 0 xFEFF, /* C.2.2 */
0 xFFF9, 0 xFFFF, /* C.2.2, C.4, C.6 */
0 x1D173, 0 x1D17A, /* C.2.2 */
0 x1FFFE, 0 x1FFFF, /* C.4 */
0 x2FFFE, 0 x2FFFF, /* C.4 */
0 x3FFFE, 0 x3FFFF, /* C.4 */
0 x4FFFE, 0 x4FFFF, /* C.4 */
0 x5FFFE, 0 x5FFFF, /* C.4 */
0 x6FFFE, 0 x6FFFF, /* C.4 */
0 x7FFFE, 0 x7FFFF, /* C.4 */
0 x8FFFE, 0 x8FFFF, /* C.4 */
0 x9FFFE, 0 x9FFFF, /* C.4 */
0 xAFFFE, 0 xAFFFF, /* C.4 */
0 xBFFFE, 0 xBFFFF, /* C.4 */
0 xCFFFE, 0 xCFFFF, /* C.4 */
0 xDFFFE, 0 xDFFFF, /* C.4 */
0 xE0001, 0 xE0001, /* C.9 */
0 xE0020, 0 xE007F, /* C.9 */
0 xEFFFE, 0 xEFFFF, /* C.4 */
0 xF0000, 0 xFFFFF, /* C.3, C.4 */
0 x100000, 0 x10FFFF /* C.3, C.4 */
};
/* A.1 Unassigned code points in Unicode 3.2 */
static const pg_wchar unassigned_codepoint_ranges[] =
{
0 x0221, 0 x0221,
0 x0234, 0 x024F,
0 x02AE, 0 x02AF,
0 x02EF, 0 x02FF,
0 x0350, 0 x035F,
0 x0370, 0 x0373,
0 x0376, 0 x0379,
0 x037B, 0 x037D,
0 x037F, 0 x0383,
0 x038B, 0 x038B,
0 x038D, 0 x038D,
0 x03A2, 0 x03A2,
0 x03CF, 0 x03CF,
0 x03F7, 0 x03FF,
0 x0487, 0 x0487,
0 x04CF, 0 x04CF,
0 x04F6, 0 x04F7,
0 x04FA, 0 x04FF,
0 x0510, 0 x0530,
0 x0557, 0 x0558,
0 x0560, 0 x0560,
0 x0588, 0 x0588,
0 x058B, 0 x0590,
0 x05A2, 0 x05A2,
0 x05BA, 0 x05BA,
0 x05C5, 0 x05CF,
0 x05EB, 0 x05EF,
0 x05F5, 0 x060B,
0 x060D, 0 x061A,
0 x061C, 0 x061E,
0 x0620, 0 x0620,
0 x063B, 0 x063F,
0 x0656, 0 x065F,
0 x06EE, 0 x06EF,
0 x06FF, 0 x06FF,
0 x070E, 0 x070E,
0 x072D, 0 x072F,
0 x074B, 0 x077F,
0 x07B2, 0 x0900,
0 x0904, 0 x0904,
0 x093A, 0 x093B,
0 x094E, 0 x094F,
0 x0955, 0 x0957,
0 x0971, 0 x0980,
0 x0984, 0 x0984,
0 x098D, 0 x098E,
0 x0991, 0 x0992,
0 x09A9, 0 x09A9,
0 x09B1, 0 x09B1,
0 x09B3, 0 x09B5,
0 x09BA, 0 x09BB,
0 x09BD, 0 x09BD,
0 x09C5, 0 x09C6,
0 x09C9, 0 x09CA,
0 x09CE, 0 x09D6,
0 x09D8, 0 x09DB,
0 x09DE, 0 x09DE,
0 x09E4, 0 x09E5,
0 x09FB, 0 x0A01,
0 x0A03, 0 x0A04,
0 x0A0B, 0 x0A0E,
0 x0A11, 0 x0A12,
0 x0A29, 0 x0A29,
0 x0A31, 0 x0A31,
0 x0A34, 0 x0A34,
0 x0A37, 0 x0A37,
0 x0A3A, 0 x0A3B,
0 x0A3D, 0 x0A3D,
0 x0A43, 0 x0A46,
0 x0A49, 0 x0A4A,
0 x0A4E, 0 x0A58,
0 x0A5D, 0 x0A5D,
0 x0A5F, 0 x0A65,
0 x0A75, 0 x0A80,
0 x0A84, 0 x0A84,
0 x0A8C, 0 x0A8C,
0 x0A8E, 0 x0A8E,
0 x0A92, 0 x0A92,
0 x0AA9, 0 x0AA9,
0 x0AB1, 0 x0AB1,
0 x0AB4, 0 x0AB4,
0 x0ABA, 0 x0ABB,
0 x0AC6, 0 x0AC6,
0 x0ACA, 0 x0ACA,
0 x0ACE, 0 x0ACF,
0 x0AD1, 0 x0ADF,
0 x0AE1, 0 x0AE5,
0 x0AF0, 0 x0B00,
0 x0B04, 0 x0B04,
0 x0B0D, 0 x0B0E,
0 x0B11, 0 x0B12,
0 x0B29, 0 x0B29,
0 x0B31, 0 x0B31,
0 x0B34, 0 x0B35,
0 x0B3A, 0 x0B3B,
0 x0B44, 0 x0B46,
0 x0B49, 0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 x0DB2,
0 x0DBC, 0 x0DBC,
0 x0DBE, 0 x0DBF,
0 x0DC7, 0 x0DC9,
0 x0DCB, 0 x0DCE,
0 x0DD5, 0 x0DD5,
0 x0DD7, 0 x0DD7,
0 x0DE0, 0 x0DF1,
0 x0DF5, 0 x0E00,
0 x0E3B, 0 x0E3E,
0 x0E5C, 0 x0E80,
0 x0E83, 0 x0E83,
0 x0E85, 0 x0E86,
0 x0E89, 0 x0E89,
0 x0E8B, 0 x0E8C,
0 x0E8E, 0 x0E93,
0 x0E98, 0 x0E98,
0 x0EA0, 0 x0EA0,
0 x0EA4, 0 x0EA4,
0 x0EA6, 0 x0EA6,
0 x0EA8, 0 x0EA9,
0 x0EAC, 0 x0EAC,
0 x0EBA, 0 x0EBA,
0 x0EBE, 0 x0EBF,
0 x0EC5, 0 x0EC5,
0 x0EC7, 0 x0EC7,
0 x0ECE, 0 x0ECF,
0 x0EDA, 0 x0EDB,
0 x0EDE, 0 x0EFF,
0 x0F48, 0 x0F48,
0 x0F6B, 0 x0F70,
0 x0F8C, 0 x0F8F,
0 x0F98, 0 x0F98,
0 x0FBD, 0 x0FBD,
0 x0FCD, 0 x0FCE,
0 x0FD0, 0 x0FFF,
0 x1022, 0 x1022,
0 x1028, 0 x1028,
0 x102B, 0 x102B,
0 x1033, 0 x1035,
0 x103A, 0 x103F,
0 x105A, 0 x109F,
0 x10C6, 0 x10CF,
0 x10F9, 0 x10FA,
0 x10FC, 0 x10FF,
0 x115A, 0 x115E,
0 x11A3, 0 x11A7,
0 x11FA, 0 x11FF,
0 x1207, 0 x1207,
0 x1247, 0 x1247,
0 x1249, 0 x1249,
0 x124E, 0 x124F,
0 x1257, 0 x1257,
0 x1259, 0 x1259,
0 x125E, 0 x125F,
0 x1287, 0 x1287,
0 x1289, 0 x1289,
0 x128E, 0 x128F,
0 x12AF, 0 x12AF,
0 x12B1, 0 x12B1,
0 x12B6, 0 x12B7,
0 x12BF, 0 x12BF,
0 x12C1, 0 x12C1,
0 x12C6, 0 x12C7,
0 x12CF, 0 x12CF,
0 x12D7, 0 x12D7,
0 x12EF, 0 x12EF,
0 x130F, 0 x130F,
0 x1311, 0 x1311,
0 x1316, 0 x1317,
0 x131F, 0 x131F,
0 x1347, 0 x1347,
0 x135B, 0 x1360,
0 x137D, 0 x139F,
0 x13F5, 0 x1400,
0 x1677, 0 x167F,
0 x169D, 0 x169F,
0 x16F1, 0 x16FF,
0 x170D, 0 x170D,
0 x1715, 0 x171F,
0 x1737, 0 x173F,
0 x1754, 0 x175F,
0 x176D, 0 x176D,
0 x1771, 0 x1771,
0 x1774, 0 x177F,
0 x17DD, 0 x17DF,
0 x17EA, 0 x17FF,
0 x180F, 0 x180F,
0 x181A, 0 x181F,
0 x1878, 0 x187F,
0 x18AA, 0 x1DFF,
0 x1E9C, 0 x1E9F,
0 x1EFA, 0 x1EFF,
0 x1F16, 0 x1F17,
0 x1F1E, 0 x1F1F,
0 x1F46, 0 x1F47,
0 x1F4E, 0 x1F4F,
0 x1F58, 0 x1F58,
0 x1F5A, 0 x1F5A,
0 x1F5C, 0 x1F5C,
0 x1F5E, 0 x1F5E,
0 x1F7E, 0 x1F7F,
0 x1FB5, 0 x1FB5,
0 x1FC5, 0 x1FC5,
0 x1FD4, 0 x1FD5,
0 x1FDC, 0 x1FDC,
0 x1FF0, 0 x1FF1,
0 x1FF5, 0 x1FF5,
0 x1FFF, 0 x1FFF,
0 x2053, 0 x2056,
0 x2058, 0 x205E,
0 x2064, 0 x2069,
0 x2072, 0 x2073,
0 x208F, 0 x209F,
0 x20B2, 0 x20CF,
0 x20EB, 0 x20FF,
0 x213B, 0 x213C,
0 x214C, 0 x2152,
0 x2184, 0 x218F,
0 x23CF, 0 x23FF,
0 x2427, 0 x243F,
0 x244B, 0 x245F,
0 x24FF, 0 x24FF,
0 x2614, 0 x2615,
0 x2618, 0 x2618,
0 x267E, 0 x267F,
0 x268A, 0 x2700,
0 x2705, 0 x2705,
0 x270A, 0 x270B,
0 x2728, 0 x2728,
0 x274C, 0 x274C,
0 x274E, 0 x274E,
0 x2753, 0 x2755,
0 x2757, 0 x2757,
0 x275F, 0 x2760,
0 x2795, 0 x2797,
0 x27B0, 0 x27B0,
0 x27BF, 0 x27CF,
0 x27EC, 0 x27EF,
0 x2B00, 0 x2E7F,
0 x2E9A, 0 x2E9A,
0 x2EF4, 0 x2EFF,
0 x2FD6, 0 x2FEF,
0 x2FFC, 0 x2FFF,
0 x3040, 0 x3040,
0 x3097, 0 x3098,
0 x3100, 0 x3104,
0 x312D, 0 x3130,
0 x318F, 0 x318F,
0 x31B8, 0 x31EF,
0 x321D, 0 x321F,
0 x3244, 0 x3250,
0 x327C, 0 x327E,
0 x32CC, 0 x32CF,
0 x32FF, 0 x32FF,
0 x3377, 0 x337A,
0 x33DE, 0 x33DF,
0 x33FF, 0 x33FF,
0 x4DB6, 0 x4DFF,
0 x9FA6, 0 x9FFF,
0 xA48D, 0 xA48F,
0 xA4C7, 0 xABFF,
0 xD7A4, 0 xD7FF,
0 xFA2E, 0 xFA2F,
0 xFA6B, 0 xFAFF,
0 xFB07, 0 xFB12,
0 xFB18, 0 xFB1C,
0 xFB37, 0 xFB37,
0 xFB3D, 0 xFB3D,
0 xFB3F, 0 xFB3F,
0 xFB42, 0 xFB42,
0 xFB45, 0 xFB45,
0 xFBB2, 0 xFBD2,
0 xFD40, 0 xFD4F,
0 xFD90, 0 xFD91,
0 xFDC8, 0 xFDCF,
0 xFDFD, 0 xFDFF,
0 xFE10, 0 xFE1F,
0 xFE24, 0 xFE2F,
0 xFE47, 0 xFE48,
0 xFE53, 0 xFE53,
0 xFE67, 0 xFE67,
0 xFE6C, 0 xFE6F,
0 xFE75, 0 xFE75,
0 xFEFD, 0 xFEFE,
0 xFF00, 0 xFF00,
0 xFFBF, 0 xFFC1,
0 xFFC8, 0 xFFC9,
0 xFFD0, 0 xFFD1,
0 xFFD8, 0 xFFD9,
0 xFFDD, 0 xFFDF,
0 xFFE7, 0 xFFE7,
0 xFFEF, 0 xFFF8,
0 x10000, 0 x102FF,
0 x1031F, 0 x1031F,
0 x10324, 0 x1032F,
0 x1034B, 0 x103FF,
0 x10426, 0 x10427,
0 x1044E, 0 x1CFFF,
0 x1D0F6, 0 x1D0FF,
0 x1D127, 0 x1D129,
0 x1D1DE, 0 x1D3FF,
0 x1D455, 0 x1D455,
0 x1D49D, 0 x1D49D,
0 x1D4A0, 0 x1D4A1,
0 x1D4A3, 0 x1D4A4,
0 x1D4A7, 0 x1D4A8,
0 x1D4AD, 0 x1D4AD,
0 x1D4BA, 0 x1D4BA,
0 x1D4BC, 0 x1D4BC,
0 x1D4C1, 0 x1D4C1,
0 x1D4C4, 0 x1D4C4,
0 x1D506, 0 x1D506,
0 x1D50B, 0 x1D50C,
0 x1D515, 0 x1D515,
0 x1D51D, 0 x1D51D,
0 x1D53A, 0 x1D53A,
0 x1D53F, 0 x1D53F,
0 x1D545, 0 x1D545,
0 x1D547, 0 x1D549,
0 x1D551, 0 x1D551,
0 x1D6A4, 0 x1D6A7,
0 x1D7CA, 0 x1D7CD,
0 x1D800, 0 x1FFFD,
0 x2A6D7, 0 x2F7FF,
0 x2FA1E, 0 x2FFFD,
0 x30000, 0 x3FFFD,
0 x40000, 0 x4FFFD,
0 x50000, 0 x5FFFD,
0 x60000, 0 x6FFFD,
0 x70000, 0 x7FFFD,
0 x80000, 0 x8FFFD,
0 x90000, 0 x9FFFD,
0 xA0000, 0 xAFFFD,
0 xB0000, 0 xBFFFD,
0 xC0000, 0 xCFFFD,
0 xD0000, 0 xDFFFD,
0 xE0000, 0 xE0000,
0 xE0002, 0 xE001F,
0 xE0080, 0 xEFFFD
};
/* D.1 Characters with bidirectional property "R" or "AL" */
static const pg_wchar RandALCat_codepoint_ranges[] =
{
0 x05BE, 0 x05BE,
0 x05C0, 0 x05C0,
0 x05C3, 0 x05C3,
0 x05D0, 0 x05EA,
0 x05F0, 0 x05F4,
0 x061B, 0 x061B,
0 x061F, 0 x061F,
0 x0621, 0 x063A,
0 x0640, 0 x064A,
0 x066D, 0 x066F,
0 x0671, 0 x06D5,
0 x06DD, 0 x06DD,
0 x06E5, 0 x06E6,
0 x06FA, 0 x06FE,
0 x0700, 0 x070D,
0 x0710, 0 x0710,
0 x0712, 0 x072C,
0 x0780, 0 x07A5,
0 x07B1, 0 x07B1,
0 x200F, 0 x200F,
0 xFB1D, 0 xFB1D,
0 xFB1F, 0 xFB28,
0 xFB2A, 0 xFB36,
0 xFB38, 0 xFB3C,
0 xFB3E, 0 xFB3E,
0 xFB40, 0 xFB41,
0 xFB43, 0 xFB44,
0 xFB46, 0 xFBB1,
0 xFBD3, 0 xFD3D,
0 xFD50, 0 xFD8F,
0 xFD92, 0 xFDC7,
0 xFDF0, 0 xFDFC,
0 xFE70, 0 xFE74,
0 xFE76, 0 xFEFC
};
/* D.2 Characters with bidirectional property "L" */
static const pg_wchar LCat_codepoint_ranges[] =
{
0 x0041, 0 x005A,
0 x0061, 0 x007A,
0 x00AA, 0 x00AA,
0 x00B5, 0 x00B5,
0 x00BA, 0 x00BA,
0 x00C0, 0 x00D6,
0 x00D8, 0 x00F6,
0 x00F8, 0 x0220,
0 x0222, 0 x0233,
0 x0250, 0 x02AD,
0 x02B0, 0 x02B8,
0 x02BB, 0 x02C1,
0 x02D0, 0 x02D1,
0 x02E0, 0 x02E4,
0 x02EE, 0 x02EE,
0 x037A, 0 x037A,
0 x0386, 0 x0386,
0 x0388, 0 x038A,
0 x038C, 0 x038C,
0 x038E, 0 x03A1,
0 x03A3, 0 x03CE,
0 x03D0, 0 x03F5,
0 x0400, 0 x0482,
0 x048A, 0 x04CE,
0 x04D0, 0 x04F5,
0 x04F8, 0 x04F9,
0 x0500, 0 x050F,
0 x0531, 0 x0556,
0 x0559, 0 x055F,
0 x0561, 0 x0587,
0 x0589, 0 x0589,
0 x0903, 0 x0903,
0 x0905, 0 x0939,
0 x093D, 0 x0940,
0 x0949, 0 x094C,
0 x0950, 0 x0950,
0 x0958, 0 x0961,
0 x0964, 0 x0970,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0 x0E84, 0 x0E84,
0 x0E87, 0 x0E88,
0 x0E8A, 0 x0E8A,
0 x0E8D, 0 x0E8D,
0 x0E94, 0 x0E97,
0 x0E99, 0 x0E9F,
0 x0EA1, 0 x0EA3,
0 x0EA5, 0 x0EA5,
0 x0EA7, 0 x0EA7,
0 x0EAA, 0 x0EAB,
0 x0EAD, 0 x0EB0,
0 x0EB2, 0 x0EB3,
0 x0EBD, 0 x0EBD,
0 x0EC0, 0 x0EC4,
0 x0EC6, 0 x0EC6,
0 x0ED0, 0 x0ED9,
0 x0EDC, 0 x0EDD,
0 x0F00, 0 x0F17,
0 x0F1A, 0 x0F34,
0 x0F36, 0 x0F36,
0 x0F38, 0 x0F38,
0 x0F3E, 0 x0F47,
0 x0F49, 0 x0F6A,
0 x0F7F, 0 x0F7F,
0 x0F85, 0 x0F85,
0 x0F88, 0 x0F8B,
0 x0FBE, 0 x0FC5,
0 x0FC7, 0 x0FCC,
0 x0FCF, 0 x0FCF,
0 x1000, 0 x1021,
0 x1023, 0 x1027,
0 x1029, 0 x102A,
0 x102C, 0 x102C,
0 x1031, 0 x1031,
0 x1038, 0 x1038,
0 x1040, 0 x1057,
0 x10A0, 0 x10C5,
0 x10D0, 0 x10F8,
0 x10FB, 0 x10FB,
0 x1100, 0 x1159,
0 x115F, 0 x11A2,
0 x11A8, 0 x11F9,
0 x1200, 0 x1206,
0 x1208, 0 x1246,
0 x1248, 0 x1248,
0 x124A, 0 x124D,
0 x1250, 0 x1256,
0 x1258, 0 x1258,
0 x125A, 0 x125D,
0 x1260, 0 x1286,
0 x1288, 0 x1288,
0 x128A, 0 x128D,
0 x1290, 0 x12AE,
0 x12B0, 0 x12B0,
0 x12B2, 0 x12B5,
0 x12B8, 0 x12BE,
0 x12C0, 0 x12C0,
0 x12C2, 0 x12C5,
0 x12C8, 0 x12CE,
0 x12D0, 0 x12D6,
0 x12D8, 0 x12EE,
0 x12F0, 0 x130E,
0 x1310, 0 x1310,
0 x1312, 0 x1315,
0 x1318, 0 x131E,
0 x1320, 0 x1346,
0 x1348, 0 x135A,
0 x1361, 0 x137C,
0 x13A0, 0 x13F4,
0 x1401, 0 x1676,
0 x1681, 0 x169A,
0 x16A0, 0 x16F0,
0 x1700, 0 x170C,
0 x170E, 0 x1711,
0 x1720, 0 x1731,
0 x1735, 0 x1736,
0 x1740, 0 x1751,
0 x1760, 0 x176C,
0 x176E, 0 x1770,
0 x1780, 0 x17B6,
0 x17BE, 0 x17C5,
0 x17C7, 0 x17C8,
0 x17D4, 0 x17DA,
0 x17DC, 0 x17DC,
0 x17E0, 0 x17E9,
0 x1810, 0 x1819,
0 x1820, 0 x1877,
0 x1880, 0 x18A8,
0 x1E00, 0 x1E9B,
0 x1EA0, 0 x1EF9,
0 x1F00, 0 x1F15,
0 x1F18, 0 x1F1D,
0 x1F20, 0 x1F45,
0 x1F48, 0 x1F4D,
0 x1F50, 0 x1F57,
0 x1F59, 0 x1F59,
0 x1F5B, 0 x1F5B,
0 x1F5D, 0 x1F5D,
0 x1F5F, 0 x1F7D,
0 x1F80, 0 x1FB4,
0 x1FB6, 0 x1FBC,
0 x1FBE, 0 x1FBE,
0 x1FC2, 0 x1FC4,
0 x1FC6, 0 x1FCC,
0 x1FD0, 0 x1FD3,
0 x1FD6, 0 x1FDB,
0 x1FE0, 0 x1FEC,
0 x1FF2, 0 x1FF4,
0 x1FF6, 0 x1FFC,
0 x200E, 0 x200E,
0 x2071, 0 x2071,
0 x207F, 0 x207F,
0 x2102, 0 x2102,
0 x2107, 0 x2107,
0 x210A, 0 x2113,
0 x2115, 0 x2115,
0 x2119, 0 x211D,
0 x2124, 0 x2124,
0 x2126, 0 x2126,
0 x2128, 0 x2128,
0 x212A, 0 x212D,
0 x212F, 0 x2131,
0 x2133, 0 x2139,
0 x213D, 0 x213F,
0 x2145, 0 x2149,
0 x2160, 0 x2183,
0 x2336, 0 x237A,
0 x2395, 0 x2395,
0 x249C, 0 x24E9,
0 x3005, 0 x3007,
0 x3021, 0 x3029,
0 x3031, 0 x3035,
0 x3038, 0 x303C,
0 x3041, 0 x3096,
0 x309D, 0 x309F,
0 x30A1, 0 x30FA,
0 x30FC, 0 x30FF,
0 x3105, 0 x312C,
0 x3131, 0 x318E,
0 x3190, 0 x31B7,
0 x31F0, 0 x321C,
0 x3220, 0 x3243,
0 x3260, 0 x327B,
0 x327F, 0 x32B0,
0 x32C0, 0 x32CB,
0 x32D0, 0 x32FE,
0 x3300, 0 x3376,
0 x337B, 0 x33DD,
0 x33E0, 0 x33FE,
0 x3400, 0 x4DB5,
0 x4E00, 0 x9FA5,
0 xA000, 0 xA48C,
0 xAC00, 0 xD7A3,
0 xD800, 0 xFA2D,
0 xFA30, 0 xFA6A,
0 xFB00, 0 xFB06,
0 xFB13, 0 xFB17,
0 xFF21, 0 xFF3A,
0 xFF41, 0 xFF5A,
0 xFF66, 0 xFFBE,
0 xFFC2, 0 xFFC7,
0 xFFCA, 0 xFFCF,
0 xFFD2, 0 xFFD7,
0 xFFDA, 0 xFFDC,
0 x10300, 0 x1031E,
0 x10320, 0 x10323,
0 x10330, 0 x1034A,
0 x10400, 0 x10425,
0 x10428, 0 x1044D,
0 x1D000, 0 x1D0F5,
0 x1D100, 0 x1D126,
0 x1D12A, 0 x1D166,
0 x1D16A, 0 x1D172,
0 x1D183, 0 x1D184,
0 x1D18C, 0 x1D1A9,
0 x1D1AE, 0 x1D1DD,
0 x1D400, 0 x1D454,
0 x1D456, 0 x1D49C,
0 x1D49E, 0 x1D49F,
0 x1D4A2, 0 x1D4A2,
0 x1D4A5, 0 x1D4A6,
0 x1D4A9, 0 x1D4AC,
0 x1D4AE, 0 x1D4B9,
0 x1D4BB, 0 x1D4BB,
0 x1D4BD, 0 x1D4C0,
0 x1D4C2, 0 x1D4C3,
0 x1D4C5, 0 x1D505,
0 x1D507, 0 x1D50A,
0 x1D50D, 0 x1D514,
0 x1D516, 0 x1D51C,
0 x1D51E, 0 x1D539,
0 x1D53B, 0 x1D53E,
0 x1D540, 0 x1D544,
0 x1D546, 0 x1D546,
0 x1D54A, 0 x1D550,
0 x1D552, 0 x1D6A3,
0 x1D6A8, 0 x1D7C9,
0 x20000, 0 x2A6D6,
0 x2F800, 0 x2FA1D,
0 xF0000, 0 xFFFFD,
0 x100000, 0 x10FFFD
};
/* End of stringprep tables */
/* Is the given Unicode codepoint in the given table of ranges? */
#define IS_CODE_IN_TABLE(code, map) is_code_in_table(code, map, lengthof(map))
static int
codepoint_range_cmp(const void *a, const void *b)
{
const pg_wchar *key = (const pg_wchar *) a;
const pg_wchar *range = (const pg_wchar *) b;
if (*key < range[0 ])
return -1 ; /* less than lower bound */
if (*key > range[1 ])
return 1 ; /* greater than upper bound */
return 0 ; /* within range */
}
static bool
is_code_in_table(pg_wchar code, const pg_wchar *map, int mapsize)
{
Assert(mapsize % 2 == 0 );
if (code < map[0 ] || code > map[mapsize - 1 ])
return false ;
if (bsearch(&code, map, mapsize / 2 , sizeof (pg_wchar) * 2 ,
codepoint_range_cmp))
return true ;
else
return false ;
}
/*
* Calculate the length in characters of a null - terminated UTF - 8 string .
*
* Returns - 1 if the input is not valid UTF - 8 .
*/
static int
pg_utf8_string_len(const char *source)
{
const unsigned char *p = (const unsigned char *) source;
int l;
int num_chars = 0 ;
size_t len = strlen(source);
while (len)
{
l = pg_utf_mblen(p);
if (len < l || !pg_utf8_islegal(p, l))
return -1 ;
p += l;
len -= l;
num_chars++;
}
return num_chars;
}
/*
* pg_saslprep - Normalize a password with SASLprep .
*
* SASLprep requires the input to be in UTF - 8 encoding , but PostgreSQL
* supports many encodings , so we don ' t blindly assume that . pg_saslprep
* will check if the input looks like valid UTF - 8 , and returns
* SASLPREP_INVALID_UTF8 if not .
*
* If the string contains prohibited characters ( or more precisely , if the
* output string would contain prohibited characters after normalization ) ,
* returns SASLPREP_PROHIBITED .
*
* On success , returns SASLPREP_SUCCESS , and the normalized string in
* * output .
*
* In frontend , the normalized string is malloc ' d , and the caller is
* responsible for freeing it . If an allocation fails , returns
* SASLPREP_OOM . In backend , the normalized string is palloc ' d instead ,
* and a failed allocation leads to ereport ( ERROR ) .
*/
pg_saslprep_rc
pg_saslprep(const char *input, char **output)
{
pg_wchar *input_chars = NULL;
pg_wchar *output_chars = NULL;
int input_size;
char *result;
int result_size;
int count;
int i;
bool contains_RandALCat;
unsigned char *p;
pg_wchar *wp;
/* Ensure we return *output as NULL on failure */
*output = NULL;
/*
* Quick check if the input is pure ASCII . An ASCII string requires no
* further processing .
*/
if (pg_is_ascii(input))
{
*output = STRDUP(input);
if (!(*output))
goto oom;
return SASLPREP_SUCCESS;
}
/*
* Convert the input from UTF - 8 to an array of Unicode codepoints .
*
* This also checks that the input is a legal UTF - 8 string .
*/
input_size = pg_utf8_string_len(input);
if (input_size < 0 )
return SASLPREP_INVALID_UTF8;
if (input_size >= MaxAllocSize / sizeof (pg_wchar))
goto oom;
input_chars = ALLOC((input_size + 1 ) * sizeof (pg_wchar));
if (!input_chars)
goto oom;
p = (unsigned char *) input;
for (i = 0 ; i < input_size; i++)
{
input_chars[i] = utf8_to_unicode(p);
p += pg_utf_mblen(p);
}
input_chars[i] = (pg_wchar) '\0' ;
/*
* The steps below correspond to the steps listed in [ RFC3454 ] , Section
* " 2 . Preparation Overview "
*/
/*
* 1 ) Map - - For each character in the input , check if it has a mapping
* and , if so , replace it with its mapping .
*/
count = 0 ;
for (i = 0 ; i < input_size; i++)
{
pg_wchar code = input_chars[i];
if (IS_CODE_IN_TABLE(code, non_ascii_space_ranges))
input_chars[count++] = 0 x0020;
else if (IS_CODE_IN_TABLE(code, commonly_mapped_to_nothing_ranges))
{
/* map to nothing */
}
else
input_chars[count++] = code;
}
input_chars[count] = (pg_wchar) '\0' ;
input_size = count;
if (input_size == 0 )
goto prohibited; /* don't allow empty password */
/*
* 2 ) Normalize - - Normalize the result of step 1 using Unicode
* normalization .
*/
output_chars = unicode_normalize(UNICODE_NFKC, input_chars);
if (!output_chars)
goto oom;
/*
* 3 ) Prohibit - - Check for any characters that are not allowed in the
* output . If any are found , return an error .
*/
for (i = 0 ; i < input_size; i++)
{
pg_wchar code = input_chars[i];
if (IS_CODE_IN_TABLE(code, prohibited_output_ranges))
goto prohibited;
if (IS_CODE_IN_TABLE(code, unassigned_codepoint_ranges))
goto prohibited;
}
/*
* 4 ) Check bidi - - Possibly check for right - to - left characters , and if
* any are found , make sure that the whole string satisfies the
* requirements for bidirectional strings . If the string does not satisfy
* the requirements for bidirectional strings , return an error .
*
* [ RFC3454 ] , Section " 6 . Bidirectional Characters " explains in more
* detail what that means :
*
* " In any profile that specifies bidirectional character handling , all
* three of the following requirements MUST be met :
*
* 1 ) The characters in section 5 . 8 MUST be prohibited .
*
* 2 ) If a string contains any RandALCat character , the string MUST NOT
* contain any LCat character .
*
* 3 ) If a string contains any RandALCat character , a RandALCat character
* MUST be the first character of the string , and a RandALCat character
* MUST be the last character of the string . "
*/
contains_RandALCat = false ;
for (i = 0 ; i < input_size; i++)
{
pg_wchar code = input_chars[i];
if (IS_CODE_IN_TABLE(code, RandALCat_codepoint_ranges))
{
contains_RandALCat = true ;
break ;
}
}
if (contains_RandALCat)
{
pg_wchar first = input_chars[0 ];
pg_wchar last = input_chars[input_size - 1 ];
for (i = 0 ; i < input_size; i++)
{
pg_wchar code = input_chars[i];
if (IS_CODE_IN_TABLE(code, LCat_codepoint_ranges))
goto prohibited;
}
if (!IS_CODE_IN_TABLE(first, RandALCat_codepoint_ranges) ||
!IS_CODE_IN_TABLE(last, RandALCat_codepoint_ranges))
goto prohibited;
}
/*
* Finally , convert the result back to UTF - 8 .
*/
result_size = 0 ;
for (wp = output_chars; *wp; wp++)
{
unsigned char buf[4 ];
unicode_to_utf8(*wp, buf);
result_size += pg_utf_mblen(buf);
}
result = ALLOC(result_size + 1 );
if (!result)
goto oom;
/*
* There are no error exits below here , so the error exit paths don ' t need
* to worry about possibly freeing " result " .
*/
p = (unsigned char *) result;
for (wp = output_chars; *wp; wp++)
{
unicode_to_utf8(*wp, p);
p += pg_utf_mblen(p);
}
Assert((char *) p == result + result_size);
*p = '\0' ;
FREE(input_chars);
FREE(output_chars);
*output = result;
return SASLPREP_SUCCESS;
prohibited:
if (input_chars)
FREE(input_chars);
if (output_chars)
FREE(output_chars);
return SASLPREP_PROHIBITED;
oom:
if (input_chars)
FREE(input_chars);
if (output_chars)
FREE(output_chars);
return SASLPREP_OOM;
}
Messung V0.5 in Prozent C=95 H=74 G=84
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.25Bemerkung:
(vorverarbeitet am 2026-08-06)
¤
*Bot Zugriff