Skip to content

Commit c3097f4

Browse files
authored
More safety checks around comments (#722)
1 parent 6d9e2ca commit c3097f4

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/postgrex.ex

+3-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ defmodule Postgrex do
6868
@timeout 15_000
6969

7070
@comment_validation_error Postgrex.Error.exception(
71-
message: "`:comment` option cannot contain sequence \"*/\""
71+
message:
72+
"`:comment` option cannot contain null bytes and \"*/\" sequence"
7273
)
7374

7475
### PUBLIC API ###
@@ -336,7 +337,7 @@ defmodule Postgrex do
336337
true
337338

338339
comment when is_binary(comment) ->
339-
if String.contains?(comment, "*/") do
340+
if String.contains?(comment, [<<0>>, "*/"]) do
340341
raise @comment_validation_error
341342
else
342343
false

test/query_test.exs

+4
Original file line numberDiff line numberDiff line change
@@ -1857,6 +1857,10 @@ defmodule QueryTest do
18571857
assert_raise Postgrex.Error, fn ->
18581858
query("select 123", [], comment: "*/ DROP TABLE 123 --")
18591859
end
1860+
1861+
assert_raise Postgrex.Error, fn ->
1862+
query("select 123", [], comment: <<0>> <> "comment")
1863+
end
18601864
end
18611865

18621866
@tag :big_binary

0 commit comments

Comments
 (0)