mirror of
https://github.com/postgres/postgres.git
synced 2025-05-28 05:21:27 +03:00
This commit adds fmtIdEnc() and fmtQualifiedIdEnc(), which allow to specify the encoding as an explicit argument. Additionally setFmtEncoding() is provided, which defines the encoding when no explicit encoding is provided, to avoid breaking all code using fmtId(). All users of fmtId()/fmtQualifiedId() are either converted to the explicit version or a call to setFmtEncoding() has been added. This commit does not yet utilize the now well-defined encoding, that will happen in a subsequent commit. Reviewed-by: Noah Misch <noah@leadboat.com> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Backpatch-through: 13 Security: CVE-2025-1094
70 lines
2.7 KiB
C
70 lines
2.7 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* String-processing utility routines for frontend code
|
|
*
|
|
* Utility functions that interpret backend output or quote strings for
|
|
* assorted contexts.
|
|
*
|
|
*
|
|
* Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* src/include/fe_utils/string_utils.h
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#ifndef STRING_UTILS_H
|
|
#define STRING_UTILS_H
|
|
|
|
#include "libpq-fe.h"
|
|
#include "pqexpbuffer.h"
|
|
|
|
/* Global variables controlling behavior of fmtId() and fmtQualifiedId() */
|
|
extern PGDLLIMPORT int quote_all_identifiers;
|
|
extern PQExpBuffer (*getLocalPQExpBuffer) (void);
|
|
|
|
/* Functions */
|
|
extern const char *fmtId(const char *rawid);
|
|
extern const char *fmtIdEnc(const char *rawid, int encoding);
|
|
extern const char *fmtQualifiedId(const char *schema, const char *id);
|
|
extern const char *fmtQualifiedIdEnc(const char *schema, const char *id, int encoding);
|
|
extern void setFmtEncoding(int encoding);
|
|
|
|
extern char *formatPGVersionNumber(int version_number, bool include_minor,
|
|
char *buf, size_t buflen);
|
|
|
|
extern void appendStringLiteral(PQExpBuffer buf, const char *str,
|
|
int encoding, bool std_strings);
|
|
extern void appendStringLiteralConn(PQExpBuffer buf, const char *str,
|
|
PGconn *conn);
|
|
extern void appendStringLiteralDQ(PQExpBuffer buf, const char *str,
|
|
const char *dqprefix);
|
|
extern void appendByteaLiteral(PQExpBuffer buf,
|
|
const unsigned char *str, size_t length,
|
|
bool std_strings);
|
|
|
|
extern void appendShellString(PQExpBuffer buf, const char *str);
|
|
extern bool appendShellStringNoError(PQExpBuffer buf, const char *str);
|
|
extern void appendConnStrVal(PQExpBuffer buf, const char *str);
|
|
extern void appendPsqlMetaConnect(PQExpBuffer buf, const char *dbname);
|
|
|
|
extern bool parsePGArray(const char *atext, char ***itemarray, int *nitems);
|
|
extern void appendPGArray(PQExpBuffer buffer, const char *value);
|
|
|
|
extern bool appendReloptionsArray(PQExpBuffer buffer, const char *reloptions,
|
|
const char *prefix, int encoding, bool std_strings);
|
|
|
|
extern bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf,
|
|
const char *pattern,
|
|
bool have_where, bool force_escape,
|
|
const char *schemavar, const char *namevar,
|
|
const char *altnamevar, const char *visibilityrule,
|
|
PQExpBuffer dbnamebuf, int *dotcnt);
|
|
|
|
extern void patternToSQLRegex(int encoding, PQExpBuffer dbnamebuf,
|
|
PQExpBuffer schemabuf, PQExpBuffer namebuf,
|
|
const char *pattern, bool force_escape,
|
|
bool want_literal_dbname, int *dotcnt);
|
|
|
|
#endif /* STRING_UTILS_H */
|