postgresql/src/include/common/base64.h
Michael Paquier cfc40d384a Introduce safer encoding and decoding routines for base64.c
This is a follow-up refactoring after 09ec55b and b674211, which has
proved that the encoding and decoding routines used by SCRAM have a
poor interface when it comes to check after buffer overflows.  This adds
an extra argument in the shape of the length of the result buffer for
each routine, which is used for overflow checks when encoding or
decoding an input string.  The original idea comes from Tom Lane.

As a result of that, the encoding routine can now fail, so all its
callers are adjusted to generate proper error messages in case of
problems.

On failure, the result buffer gets zeroed.

Author: Michael Paquier
Reviewed-by: Daniel Gustafsson
Discussion: https://postgr.es/m/20190623132535.GB1628@paquier.xyz
2019-07-04 16:08:09 +09:00

19 lines
515 B
C

/*
* base64.h
* Encoding and decoding routines for base64 without whitespace
* support.
*
* Portions Copyright (c) 2001-2019, PostgreSQL Global Development Group
*
* src/include/common/base64.h
*/
#ifndef BASE64_H
#define BASE64_H
/* base 64 */
extern int pg_b64_encode(const char *src, int len, char *dst, int dstlen);
extern int pg_b64_decode(const char *src, int len, char *dst, int dstlen);
extern int pg_b64_enc_len(int srclen);
extern int pg_b64_dec_len(int srclen);
#endif /* BASE64_H */