PATCH: Fix wrong size argument to pg_strncasecmp

Started by Dominik Czarnotaabout 6 years ago2 messageshackers
Jump to latest
#1Dominik Czarnota
dominik.b.czarnota@gmail.com

Hello,

Please find a one-liner patch in the attachment.

This patch fixes a size parameter of `pg_strncasecmp` which compared a
"string" literal with a variable by passing a size of 5 while the "string"
literal has 6 bytes.

This issue can be observed with the following query (where 'X' is any
character other than 'g' and null byte):

select json_to_tsvector('"abc"'::json, '"strinX"')

Before this patch this query returns the `'abc':1` result instead of
failing with the following error:

wrong flag in flag array: "strinX"

By the way, the `strncasecmp` usages around the fixed line could use
`strcasecmp` which doesn't accept the `size_t n` argument.

---
Regards,
Disconnect3d

Attachments:

0001-Fix-wrong-size-argument-to-pg_strncasecmp.patchapplication/octet-stream; name=0001-Fix-wrong-size-argument-to-pg_strncasecmp.patchDownload+1-2
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dominik Czarnota (#1)
Re: PATCH: Fix wrong size argument to pg_strncasecmp

Dominik Czarnota <dominik.b.czarnota@gmail.com> writes:

This patch fixes a size parameter of `pg_strncasecmp` which compared a
"string" literal with a variable by passing a size of 5 while the "string"
literal has 6 bytes.

Pushed, thanks for the report!

By the way, the `strncasecmp` usages around the fixed line could use
`strcasecmp` which doesn't accept the `size_t n` argument.

Maybe. It's not clear to me that it's be okay to assume that the
variable input string is null-terminated.

regards, tom lane