Skip to content

Commit

Permalink
sql: properly check result of decimal parsing
Browse files Browse the repository at this point in the history
This patch fixes a crash that can occur when SQL parses a decimal
literal that represents a number greater than or equal to 10^38.

Closes #9469

NO_DOC=bugfix

(cherry picked from commit 05551a5)
  • Loading branch information
ImeevMA authored and igormunkin committed Dec 22, 2023
1 parent f0f252f commit f54f59b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions changelogs/unreleased/gh-9469-too-big-decimal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## bugfix/sql

* Fixed a crash when a decimal literal representing a decimal number greater
than or equal to 10^38 was parsed in SQL (gh-9469).
1 change: 1 addition & 0 deletions src/box/errcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ struct errcode_record {
/*264 */_(ER_UNUSED18, "") \
/*265 */_(ER_UNUSED19, "") \
/*266 */_(ER_MISSING_SYSTEM_SPACES, "Snapshot has no system spaces") \
/*267 */_(ER_INVALID_DEC, "Invalid decimal: '%s'") \

/*
* !IMPORTANT! Please follow instructions at start of the file
Expand Down
1 change: 1 addition & 0 deletions src/box/sql/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -3382,6 +3382,7 @@ expr_code_dec(struct Parse *parser, struct Expr *expr, bool is_neg, int reg)
return;
error:
sqlDbFree(sql_get(), value);
diag_set(ClientError, ER_INVALID_DEC, str);
parser->is_aborted = true;
}

Expand Down
1 change: 1 addition & 0 deletions test/box/error.result
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ t;
| 245: box.error.OLD_TERM
| 246: box.error.INTERFERING_ELECTIONS
| 266: box.error.MISSING_SYSTEM_SPACES
| 267: box.error.INVALID_DEC
| ...

test_run:cmd("setopt delimiter ''");
Expand Down
29 changes: 29 additions & 0 deletions test/sql-luatest/gh_9469_too_big_decimals_test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
local server = require('luatest.server')
local t = require('luatest')

local g = t.group()

g.before_all(function()
g.server = server:new({alias = 'master'})
g.server:start()
end)

g.after_all(function()
g.server:stop()
end)

g.test_too_big_decimal = function()
g.server:exec(function()
local dec = '111111111111111111111111111111111111111.0'
local sql = ([[SELECT %s;]]):format(dec)
local exp = ([[Invalid decimal: '%s']]):format(dec)
local res, err = box.execute(sql)
t.assert(res == nil)
t.assert_equals(err.message, exp)

sql = ([[SELECT -%s;]]):format(dec)
res, err = box.execute(sql)
t.assert(res == nil)
t.assert_equals(err.message, exp)
end)
end

0 comments on commit f54f59b

Please sign in to comment.