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 d9608c9 commit 450da02
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 @@ -331,6 +331,7 @@ struct errcode_record {
/*276 */_(ER_UNUSED9, "") \
/*277 */_(ER_UNUSED10, "") \
/*278 */_(ER_IN_ANOTHER_PROMOTE, "box.ctl.promote() is already running") \
/*279 */_(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 @@ -3152,6 +3152,7 @@ expr_code_dec(struct Parse *parser, struct Expr *expr, bool is_neg, int reg)
return;
error:
sql_xfree(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 @@ -487,6 +487,7 @@ t;
| 272: box.error.SCHEMA_UPGRADE_IN_PROGRESS
| 274: box.error.UNCONFIGURED
| 278: box.error.IN_ANOTHER_PROMOTE
| 279: 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 450da02

Please sign in to comment.