summaryrefslogtreecommitdiff
path: root/src/common/saslprep.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-09-08 18:20:36 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2018-09-08 18:20:36 -0400
commit86d226ae5a3607b8bbde2487f821b8f8807da1c8 (patch)
treed19182f4993eac2fe08bc3a234b08448703a999c /src/common/saslprep.c
parent825f10fbda7a5d8a48d187b8193160e5e44e4011 (diff)
Minor cleanup/future-proofing for pg_saslprep().
Ensure that pg_saslprep() initializes its output argument to NULL in all failure paths, and then remove the redundant initialization that some (not all) of its callers did. This does not fix any live bug, but it reduces the odds of future bugs of omission. Also add a comment about why the existing failure-path coding is adequate. Back-patch so as to keep the function's API consistent across branches, again to forestall future bug introduction. Patch by me, reviewed by Michael Paquier Discussion: https://postgr.es/m/16558.1536407783@sss.pgh.pa.us
Diffstat (limited to 'src/common/saslprep.c')
-rw-r--r--src/common/saslprep.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/common/saslprep.c b/src/common/saslprep.c
index 271021550ad..4cf574fed87 100644
--- a/src/common/saslprep.c
+++ b/src/common/saslprep.c
@@ -1081,6 +1081,9 @@ pg_saslprep(const char *input, char **output)
unsigned char *p;
pg_wchar *wp;
+ /* Ensure we return *output as NULL on failure */
+ *output = NULL;
+
/* Check that the password isn't stupendously long */
if (strlen(input) > MAX_PASSWORD_LENGTH)
{
@@ -1112,10 +1115,7 @@ pg_saslprep(const char *input, char **output)
*/
input_size = pg_utf8_string_len(input);
if (input_size < 0)
- {
- *output = NULL;
return SASLPREP_INVALID_UTF8;
- }
input_chars = ALLOC((input_size + 1) * sizeof(pg_wchar));
if (!input_chars)
@@ -1246,6 +1246,11 @@ pg_saslprep(const char *input, char **output)
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++)
{