diff options
-rw-r--r-- | src/common/saslprep.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/common/saslprep.c b/src/common/saslprep.c index 315ccacd7ce..78f6fcbd805 100644 --- a/src/common/saslprep.c +++ b/src/common/saslprep.c @@ -1004,15 +1004,17 @@ 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 (*p) + while (len) { l = pg_utf_mblen(p); - if (!pg_utf8_islegal(p, l)) + if (len < l || !pg_utf8_islegal(p, l)) return -1; p += l; + len -= l; num_chars++; } |