Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit430ce18

Browse files
committed
libpq: Discard leading and trailing spaces for parameters and values in URIs
Integer values applied a parsing rule through pqParseIntParam() thatmade URIs like this one working, even if these include spaces aroundvalues:"postgresql://localhost:5432/postgres?keepalives=1 &keepalives_idle=1 "This commit changes the parsing so as spaces before and after parametersand values are discarded, offering more consistency with the parsingthat already applied to libpq for integer values in URIs.Note that %20 can be used in a URI for a space character. ECPGconnect()has been discarded leading and trailing spaces around parameters andvalues that for a long time, as well. Likef22e84d, this is doneas a HEAD-only change.Reviewed-by: Yuto SasakiDiscussion:https://postgr.es/m/Zv3oWOfcrHTph7JK@paquier.xyz
1 parent68dfecb commit430ce18

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

‎src/interfaces/libpq/fe-connect.c

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6763,9 +6763,9 @@ conninfo_uri_parse_params(char *params,
67636763
staticchar*
67646764
conninfo_uri_decode(constchar*str,PQExpBuffererrorMessage)
67656765
{
6766-
char*buf;
6767-
char*p;
6768-
constchar*q=str;
6766+
char*buf;/* result */
6767+
char*p;/* output location */
6768+
constchar*q=str;/* input location */
67696769

67706770
buf=malloc(strlen(str)+1);
67716771
if (buf==NULL)
@@ -6775,13 +6775,23 @@ conninfo_uri_decode(const char *str, PQExpBuffer errorMessage)
67756775
}
67766776
p=buf;
67776777

6778+
/* skip leading whitespaces */
6779+
for (constchar*s=q;*s==' ';s++)
6780+
{
6781+
q++;
6782+
continue;
6783+
}
6784+
67786785
for (;;)
67796786
{
67806787
if (*q!='%')
67816788
{
6782-
/* copy and check for NUL terminator */
6783-
if (!(*(p++)=*(q++)))
6784-
break;
6789+
/* if found a whitespace or NUL, the string ends */
6790+
if (*q==' '||*q=='\0')
6791+
gotoend;
6792+
6793+
/* copy character */
6794+
*(p++)=*(q++);
67856795
}
67866796
else
67876797
{
@@ -6817,6 +6827,26 @@ conninfo_uri_decode(const char *str, PQExpBuffer errorMessage)
68176827
}
68186828
}
68196829

6830+
end:
6831+
6832+
/* skip trailing whitespaces */
6833+
for (constchar*s=q;*s==' ';s++)
6834+
{
6835+
q++;
6836+
continue;
6837+
}
6838+
6839+
/* Not at the end of the string yet? Fail. */
6840+
if (*q!='\0')
6841+
{
6842+
libpq_append_error(errorMessage,"trailing data found: \"%s\"",str);
6843+
free(buf);
6844+
returnNULL;
6845+
}
6846+
6847+
/* Copy NUL terminator */
6848+
*p='\0';
6849+
68206850
returnbuf;
68216851
}
68226852

‎src/interfaces/libpq/t/001_uri.pl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,24 @@
8686
q{user='uri-user' host='host' (inet)},
8787
q{},
8888
],
89+
[
90+
# Leading and trailing spaces, works.
91+
q{postgresql://host? user = uri-user & port = 12345},
92+
q{user='uri-user' host='host' port='12345' (inet)},
93+
q{},
94+
],
95+
[
96+
# Trailing data in parameter.
97+
q{postgresql://host? user user = uri & port = 12345 12},
98+
q{},
99+
q{libpq_uri_regress: trailing data found: " user user "},
100+
],
101+
[
102+
# Trailing data in value.
103+
q{postgresql://host? user = uri-user & port = 12345 12},
104+
q{},
105+
q{libpq_uri_regress: trailing data found: " 12345 12 "},
106+
],
89107
[q{postgresql://host?},q{host='host' (inet)},q{}, ],
90108
[
91109
q{postgresql://[::1]:12345/db},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp