pgspider / influxdb_fdw

InfluxDB Foreign Data Wrapper for PostgreSQL.
Other
55 stars 13 forks source link

Wrong escape method for database name #50

Open AntoniJakubiak opened 3 months ago

AntoniJakubiak commented 3 months ago

Hi,

Please check this code.

https://github.com/pgspider/influxdb_fdw/blob/7bb0e4c9ce6541327f006cc7d2fab74721168788/query.cpp#L65

There is no escape for database name, it could not work if database name is for example my-db.

test02=# create extension influxdb_fdw ;
CREATE EXTENSION
test02=# CREATE SERVER influxdb_svr FOREIGN DATA WRAPPER influxdb_fdw OPTIONS (
  dbname 'my-db',  host 'http://172.17.0.1',  port '18086',  version '1');
CREATE SERVER
test02=# CREATE USER MAPPING FOR "xxx" SERVER influxdb_svr OPTIONS (  user 'xxx',  password 'xxx');
CREATE USER MAPPING
test02=# create schema "30d";
CREATE SCHEMA
test02=# IMPORT FOREIGN SCHEMA "30d" FROM SERVER influxdb_svr INTO "30d";
ERROR:  influxdb_fdw : influx-cxx [treatCurlResponse]: Bad request: CODE: invalid, MESSAGE: failed to parse query: found -, expected ; at line 1, char 29

The similar code is used on lines L65, L91, L489.

A similar bug could be also here: https://github.com/pgspider/influxdb_fdw/blob/7bb0e4c9ce6541327f006cc7d2fab74721168788/influxdb_fdw.c#L4256

There is also a function influxdb_quote_identifier - but it seems, it is implemented differently than the original InfluxDB quote identifier. https://github.com/pgspider/influxdb_fdw/blob/7bb0e4c9ce6541327f006cc7d2fab74721168788/deparse.c#L315

And also in go client. https://github.com/pgspider/influxdb_fdw/blob/7bb0e4c9ce6541327f006cc7d2fab74721168788/query.go#L162

Kind regards Antoni Jakubiak

AntoniJakubiak commented 3 months ago

Here is a link to InfluxDB (go) code for escaping idents: https://github.com/influxdata/influxql/blob/master/parser.go#L3124 https://github.com/influxdata/influxql/blob/master/parser_test.go#L4259

weiting1lee commented 2 months ago

Dear @AntoniJakubiak ,

Thank you for highlighting the escaping issue with database names in InfluxDB FDW and for your detailed report. We acknowledge the problem and appreciate your contribution to identifying it. Based on your report, we will investigate this issue further and aim to implement a fix in the next release of InfluxDB FDW.

Thank you once again for your contribution. We look forward to any further insights you might have in the future and appreciate your support in enhancing InfluxDB FDW.