From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id EBA546EFF8; Fri, 5 Jun 2026 18:19:19 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EBA546EFF8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1780672760; bh=cbDpzNxpc+oBZA4VtHAd0bjMeXTaQs3RTGk6ZJLoOeU=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=OaiwjfomKqexjMGgepPVhHmLhOCj2TGw5Hp9COAk/qeKX/mhduhroUN6kkdFUQxlR bKFg4psB2KEl0U3CLiOBdLy9Rzd/w+3DG8XmfdYAyjBXWYSnkR7IXCCakFLGX+DX9R BsAEtSi4kTMt1YyI/FlUWkU3E3e0hpGcf9Xz1/bY= Received: from mail-yw1-f180.google.com (mail-yw1-f180.google.com [209.85.128.180]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 8BE816EFF8 for ; Fri, 5 Jun 2026 18:19:19 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8BE816EFF8 Received: by mail-yw1-f180.google.com with SMTP id 00721157ae682-7dca5a81be2so18933367b3.2 for ; Fri, 05 Jun 2026 08:19:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780672757; x=1781277557; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Re0LoemHTh/jrrax27BvLPL7GfcAavAC0bHAJUHj4bk=; b=UxS1m4nauua/sh0+DtChKozzv+sKm2lAmWdQwu6BFrCVE2MAl2/yRp5HWtV3Ekohf0 kITIRNaLjMEG7qVBNUQVXFfxa6LWKcPyPDWY9b3qudZeO4XSmoTfn7mw4hleV0BzUeyt P0hPgNTboXgYpbbYUJE4+Q9e1Gl1UnHi05ZFxMJdgXuWgiymv672TeKu27rC/f5lqqrG fAgCvqLHxhOk01DUyv/oq+tUVi01OODikPwsL6ZjcoG2ft7suBQdfGLwhXC3MuDBa9EM tit7r2U0UuB7GG5MkWKjKztmNWq3I9HNWikYr9TM6WbEPf2Duw8FP7OjWQPwfkfVzeWm 6F8g== X-Gm-Message-State: AOJu0YzW7lVbIvqYXg01KnlUpsxHD55UhRmJxt5Lrm8rCH6XLWtrkzGh DgxdA/tfpGVProFjIwrN2s12wtm/dNrP5CwBMNUkdflszwUDdgUT+1yNwMir/CcSEes= X-Gm-Gg: Acq92OHDChMQ+4XdDbkDexAFEGSj+mm5cnQHpuJJbDKprqx4DAC4ry23HxO8pR6/+Jm vMSpO2aMlLlDe0WU8VAS7SVBP3Z8DvYg7H9bH/lb1UhnbYp2CVFIYTg9Dy0Yqim3clPdaoPejem 8UMcrAOdb8jKHEi01CcsajPzEAcWArYjSF2dOhEhI3jg/GMoj4HYr3+nG8DrkAN+O6klgKvM/1L G8msBUV7sLtq1sTFyjKHB9XfpR7VFM6Y0DVq7/PdxPGBRKDDq1dRTHEA4DodwNna9Pt1w8ZswP+ l/Xf5vqyi0VVnP9r9ELjDr2Ua0+bI6fjGtn80Jgv478pg2GdblMhqCIe+UBvyGsisSb0uwwbKMw gd5EAYFU4cE2bwC/+gFgyKHmNaKvVxwCIm+AEuySGwBNdPcMjhAa2fLcqohCD2NBATChbzbEHzE TeGKy5c4rMgFqmeHxSvf6zjpZSZWjF9WMwAJE610nENAx0Q+c4 X-Received: by 2002:a05:690c:4588:b0:7bd:7b2e:f079 with SMTP id 00721157ae682-7ed0daa3b34mr36094357b3.44.1780672756631; Fri, 05 Jun 2026 08:19:16 -0700 (PDT) Received: from localhost ([2a06:a780:1000:2::63b5:a598]) by smtp.gmail.com with ESMTPSA id 00721157ae682-7ea235885d1sm51549627b3.26.2026.06.05.08.19.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2026 08:19:16 -0700 (PDT) X-Google-Original-From: Sergey Bronnikov To: tarantool-patches@dev.tarantool.org, Sergey Kaplun , e.temirgaleev@tarantool.org Date: Fri, 5 Jun 2026 18:18:40 +0300 Message-ID: X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH luajit] Prevent sanitizer warning in os.time(). X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Mike Pall Reported by Sergey Bronnikov. (cherry picked from commit 86d414f5cae062b06998ec66b0696a47d4f6a0f0) The function `lj_cf_os_time()` calculates `tm_mon` and `tm_year` values using `get_field()` and when the helper function returns a negative value the resulted values may be negative as well. This is an undefined behaviour (signed integer overflow). The patch fixes that by adding a cast for the resulted value to returned by `get_field()`. Sergey Bronnikov: * added the description and the test for the problem Part of tarantool/tarantool#12480 --- Branch: https://github.com/tarantool/luajit/tree/ligurio/lj-1454-ub-os-time Related issues: * https://github.com/tarantool/tarantool/issues/12480 * https://github.com/LuaJIT/LuaJIT/issues/1454 src/lib_os.c | 4 ++-- test/tarantool-tests/lj-1454-os-time.test.lua | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 test/tarantool-tests/lj-1454-os-time.test.lua diff --git a/src/lib_os.c b/src/lib_os.c index ffbc3fdc..0feb0d47 100644 --- a/src/lib_os.c +++ b/src/lib_os.c @@ -239,8 +239,8 @@ LJLIB_CF(os_time) ts.tm_min = getfield(L, "min", 0); ts.tm_hour = getfield(L, "hour", 12); ts.tm_mday = getfield(L, "day", -1); - ts.tm_mon = getfield(L, "month", -1) - 1; - ts.tm_year = getfield(L, "year", -1) - 1900; + ts.tm_mon = (int)((unsigned int)getfield(L, "month", -1) - 1u); + ts.tm_year = (int)((unsigned int)getfield(L, "year", -1) - 1900u); ts.tm_isdst = getboolfield(L, "isdst"); t = mktime(&ts); } diff --git a/test/tarantool-tests/lj-1454-os-time.test.lua b/test/tarantool-tests/lj-1454-os-time.test.lua new file mode 100644 index 00000000..2a48750c --- /dev/null +++ b/test/tarantool-tests/lj-1454-os-time.test.lua @@ -0,0 +1,19 @@ +local tap = require('tap') + +-- The test file to demonstrate UBSan warning for `os.time()` with +-- a huge indices value for month and/or year. +-- See also: https://github.com/LuaJIT/LuaJIT/issues/1454. +local test = tap.test('lj-1454-os-time') + +test:plan(1) + +local INT_MIN = -2 ^ 31 + +local cur_time = os.time({ + day = 1, + month = INT_MIN, + year = INT_MIN, +}) +test:is(cur_time, nil, 'os.time() with INT_MIN') + +test:done(true) -- 2.43.0