Skip to content

Commit

Permalink
More safety checks around comments (#722)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkuku authored Dec 19, 2024
1 parent 6d9e2ca commit c3097f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/postgrex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ defmodule Postgrex do
@timeout 15_000

@comment_validation_error Postgrex.Error.exception(
message: "`:comment` option cannot contain sequence \"*/\""
message:
"`:comment` option cannot contain null bytes and \"*/\" sequence"
)

### PUBLIC API ###
Expand Down Expand Up @@ -336,7 +337,7 @@ defmodule Postgrex do
true

comment when is_binary(comment) ->
if String.contains?(comment, "*/") do
if String.contains?(comment, [<<0>>, "*/"]) do
raise @comment_validation_error
else
false
Expand Down
4 changes: 4 additions & 0 deletions test/query_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1857,6 +1857,10 @@ defmodule QueryTest do
assert_raise Postgrex.Error, fn ->
query("select 123", [], comment: "*/ DROP TABLE 123 --")
end

assert_raise Postgrex.Error, fn ->
query("select 123", [], comment: <<0>> <> "comment")
end
end

@tag :big_binary
Expand Down

0 comments on commit c3097f4

Please sign in to comment.