@@ -304,17 +304,30 @@ libpqrcv_startstreaming(WalReceiverConn *conn,
304304 {
305305 char * pubnames_str ;
306306 List * pubnames ;
307+ char * pubnames_literal ;
307308
308309 appendStringInfoString (& cmd , " (" );
310+
309311 appendStringInfo (& cmd , "proto_version '%u'" ,
310312 options -> proto .logical .proto_version );
313+
311314 pubnames = options -> proto .logical .publication_names ;
312315 pubnames_str = stringlist_to_identifierstr (conn -> streamConn , pubnames );
313- appendStringInfo (& cmd , ", publication_names %s" ,
314- PQescapeLiteral (conn -> streamConn , pubnames_str ,
315- strlen (pubnames_str )));
316- appendStringInfoChar (& cmd , ')' );
316+ if (!pubnames_str )
317+ ereport (ERROR ,
318+ (errmsg ("could not start WAL streaming: %s" ,
319+ PQerrorMessage (conn -> streamConn ))));
320+ pubnames_literal = PQescapeLiteral (conn -> streamConn , pubnames_str ,
321+ strlen (pubnames_str ));
322+ if (!pubnames_literal )
323+ ereport (ERROR ,
324+ (errmsg ("could not start WAL streaming: %s" ,
325+ PQerrorMessage (conn -> streamConn ))));
326+ appendStringInfo (& cmd , ", publication_names %s" , pubnames_literal );
327+ PQfreemem (pubnames_literal );
317328 pfree (pubnames_str );
329+
330+ appendStringInfoChar (& cmd , ')' );
318331 }
319332 else
320333 appendStringInfo (& cmd , " TIMELINE %u" ,
@@ -736,14 +749,21 @@ stringlist_to_identifierstr(PGconn *conn, List *strings)
736749 foreach (lc , strings )
737750 {
738751 char * val = strVal (lfirst (lc ));
752+ char * val_escaped ;
739753
740754 if (first )
741755 first = false;
742756 else
743757 appendStringInfoChar (& res , ',' );
744758
745- appendStringInfoString (& res ,
746- PQescapeIdentifier (conn , val , strlen (val )));
759+ val_escaped = PQescapeIdentifier (conn , val , strlen (val ));
760+ if (!val_escaped )
761+ {
762+ free (res .data );
763+ return NULL ;
764+ }
765+ appendStringInfoString (& res , val_escaped );
766+ PQfreemem (val_escaped );
747767 }
748768
749769 return res .data ;
0 commit comments