From patchwork Thu Aug 1 06:52:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1967492 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20230601 header.b=swp1HTmP; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::53d; helo=mail-ed1-x53d.google.com; envelope-from=swupdate+bncbd2zdgn6sekrbrpbvs2qmgqemdnoudq@googlegroups.com; receiver=patchwork.ozlabs.org) Received: from mail-ed1-x53d.google.com (mail-ed1-x53d.google.com [IPv6:2a00:1450:4864:20::53d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WZKRJ2xDgz1yYq for ; Thu, 1 Aug 2024 16:52:59 +1000 (AEST) Received: by mail-ed1-x53d.google.com with SMTP id 4fb4d7f45d1cf-5a2d4fb1e73sf6627686a12.2 for ; Wed, 31 Jul 2024 23:52:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1722495176; cv=pass; d=google.com; s=arc-20160816; b=h4lPnoYipIRU331RHxsuTVBRoZ4N20xHJNxaQDHLhjGNKr4nJM6fX5jOY534knxUMI AFeECKwv2QXEZ0EXLgx3P4uZv5ncHPsFxIicuQGAgwNkebWknuU5Qwr7aP8NaPHDqqVH dmHgWRAz2PyRzTwm/pVY/rrh0+Z3n/h0B3st94KyZkHnRDYdADvjX4fc8jGOgHBpCweY 9kRNOHlMxuwSpI70IiDd4IiTYcQ5uqlbnVAdcp40vc+Q8kwt+y3KRmRS2JCiOFhB8Smq brUkuRzTDer7DZRMi1HfU8NjckjQjE4cTsFEQmzgHl12pjwCaa3oEBLO/mKasUX0mxUo ac1Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:ui-outboundreport:mime-version :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=Y2Jp9dzddk1XEUdxN/9W0D1japAfCxvoOcBFPfYJIQI=; fh=58eShLZcuHL3FteJw6Yz765ff+z7tCrsKjK/WcJi9NM=; b=oLW5siy4+O1qgKRS4NA2EJEa6gTOhVclzG3g8Q1VFGBitkk7VYEjs1vKYkUP2H0Y1F DcCfiCpFovXKMydsiKcofSAAcdQgHPubtrMZUqsE/9nfzkoKLdwIkENEqnO3e582CaHC 3K/f/sorkiJy1hKm01wLT7DuAD/uox7q48yLdlwbUeMP5b5xzNxjXlw3UTNBd2jV3X1s 3rOL9iPYIx/JSGbvKy3QU6stkEyIJZ00gaSgx1DTV5HhdxhntW2om7hUoAQaZxyU4DoE oPAdI2hkOUn5Riix2SiWniSIBUcqaKFaZCL1e4vPqkZWIXeFf0OwZsoC3mQt5cUHim63 OuIw==; darn=patchwork.ozlabs.org ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@swupdate.org header.s=s1-ionos header.b=QtrzffRZ; spf=pass (google.com: domain of stefano.babic@swupdate.org designates 212.227.126.131 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1722495176; x=1723099976; darn=patchwork.ozlabs.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:ui-outboundreport:mime-version:message-id:date :subject:cc:to:from:sender:from:to:cc:subject:date:message-id :reply-to; bh=Y2Jp9dzddk1XEUdxN/9W0D1japAfCxvoOcBFPfYJIQI=; b=swp1HTmPr4PewELy/5pJm24xBMdyt9EjGikPPv6HCsp6iu/mjjERC5GtdTQj2V57At sfjcDSOMpydyPiGvc2AzNwloypBFp068oUMx5y+YVNDMbjvxGyiM9yoC1WFEP7GmDMUO JMRMC38ohX6RlVmNK5I6AqSuuY7f2R8mHMPuU0CR4mxIvQ6P0rfB24dRFjpRcPXC7ERg f5OArRC5FNWJeY/YKbXKYIwij4pE9SsK/u/g5cNCxFUcG0eZBP6HrxbgfVR5PUpRheVs jsApBJ3FhcexDR1r8EvqHEBKziT5hd+U50hRXq39wcB60qlayKL9xubEJSUN5b928iwX 3mCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722495176; x=1723099976; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender :ui-outboundreport:mime-version:message-id:date:subject:cc:to:from :x-beenthere:x-gm-message-state:sender:from:to:cc:subject:date :message-id:reply-to; bh=Y2Jp9dzddk1XEUdxN/9W0D1japAfCxvoOcBFPfYJIQI=; b=ZUJ+07cPJUtQcLG59VweUaFiwv/ro19XyWdNoWzXwh1URV017Il7CyC1vVHKGX6it7 +0wD2BW4C61c2ZYmx1E6MUvie5J2QhL9rbRTy6Ayh1Ac8KDSfdMcc/N3R5SJ2NRtZglG YqPJkybdXn/pUBFC8yEmTZYFnWHE9qp7ny/t1a2Jf+j12fkLDy9VIvgX2oI6pOoWfHhV Uv4vApdpcvN6RUDV53VsvWn2RNzEHSLn9p1wpfIzOr/wPdj9h5vMEPAQ3JKNk3cbz3I9 G4zafpx4sXh/D/RdRr4bXLXhXQ0kBSeEjmJaZ7j0R8DzAt5t2YHn5nujf/W3Lcuf2sXq hYdw== Sender: swupdate@googlegroups.com X-Forwarded-Encrypted: i=2; AJvYcCX9J2PHFLfz1F2Stlltroz6WU0daK2BWWBmcqLQmDgZF472wKHu8+1sFpg2XNXn8H1JaccTeAjrXchMMwJJnvpfvOnntWncsR2goi0ZbQ== X-Gm-Message-State: AOJu0YwTLCJVtNLLPWQtCaUmCg8hlp4SkQPkjsGJmZg8MbUyVQqN0aTh eNQud1jXFVTJ8zftEvQ/Y4+uS5KgHtRrPkhbyofiiVtl67uqLlip X-Google-Smtp-Source: AGHT+IHENY0JUwOYuNjic8AxkvTkoBilQBo4KVuEnXOA27cvhuxv7yH+20C1THaHj2fzu9pqLNntYg== X-Received: by 2002:a05:6402:33ce:b0:5a1:c43:82bd with SMTP id 4fb4d7f45d1cf-5b6ff3e9be0mr873416a12.19.1722495174681; Wed, 31 Jul 2024 23:52:54 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:6402:4017:b0:58f:749f:1c6c with SMTP id 4fb4d7f45d1cf-5ac0d0ecc46ls801703a12.1.-pod-prod-01-eu; Wed, 31 Jul 2024 23:52:52 -0700 (PDT) X-Received: by 2002:a05:6402:33ce:b0:5a1:c43:82bd with SMTP id 4fb4d7f45d1cf-5b6ff3e9be0mr873327a12.19.1722495171821; Wed, 31 Jul 2024 23:52:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1722495171; cv=none; d=google.com; s=arc-20160816; b=lbhYzNYkKVNRWT8eTtX3lA43mYqK+TmPZQ/Lerdl0gGyd7UcbdvgX24CzbhhK+olQe s6yQTrS8ErJh74IBEVz7wLU801a7S3zj42s5z9mSTkgaR5Z77VPVtZ8iZ1Rg7kbFwors lvSpjT5vjVgsyVVrF+pxjQWxOBZ+Co4nMcFP+U0KpDIKLA0yWT63lOJl5A/yN/1UrIk5 AH6x6JxD/ir2H9t99pVAv4fz2sfOvuIpU8RCBggNjDOOp18uW1IvRxCgw8A6fU5JXsjb mUX+2+kOScSSIEXVgTdtJQTPePTD1BXnls/5x2gBhjS4Cqcntta2TRjXdhNmDT+cf37p +7og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-transfer-encoding:mime-version:message-id :date:subject:cc:to:from:dkim-signature; bh=ra2f1dJcf6OY6o1zdDFlDa3/2+M4+NooKpJ9GEq5434=; fh=TiEWcqMcKpHk5s7uErzpntoONrNfOXwKpI5P8bIlggk=; b=B/NFPwuqtxoMf6S1bGysUHf1kVu6nU+4yWMXMVQypawTaglWtmVL2jZ36XqfAHgC3Q OGQzCqwOlI0rjHZLo6svdoce6LNVNWo7/wisRRWCwIzRK5SMSO6IgO3+/PtylFe92CoO gTQtFa5+VMLZlBtyY4/uksWN+hKgFNyZKwL7zsN0QSlyF26b5j+mzjH/lp9IoQvBjk8w 6G8pScFDG/oK6/fr9f6EySItbnYCVIRTR6HNSOWRUWBKMM6kl4JSEq6xV9staEK7KosP 8IOHAZNGXFU2rY0+siUsAmF6K3t/udxHI3ER/iGeg7heACxBc6fmyIcuGQe3qoqKeYVJ dkCA==; dara=google.com ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@swupdate.org header.s=s1-ionos header.b=QtrzffRZ; spf=pass (google.com: domain of stefano.babic@swupdate.org designates 212.227.126.131 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org Received: from mout.kundenserver.de (mout.kundenserver.de. [212.227.126.131]) by gmr-mx.google.com with ESMTPS id 4fb4d7f45d1cf-5b4961b3d15si162885a12.0.2024.07.31.23.52.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jul 2024 23:52:51 -0700 (PDT) Received-SPF: pass (google.com: domain of stefano.babic@swupdate.org designates 212.227.126.131 as permitted sender) client-ip=212.227.126.131; X-UI-Sender-Class: 55c96926-9e95-11ee-ae09-1f7a4046a0f6 Received: from paperino.fritz.box ([88.217.136.221]) by mrelayeu.kundenserver.de (mreue012 [213.165.67.97]) with ESMTPSA (Nemesis) id 1N2BQM-1s7YEv1Nde-011LHR; Thu, 01 Aug 2024 08:52:51 +0200 From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH] Lua: evaluate return code for image read callback Date: Thu, 1 Aug 2024 08:52:49 +0200 Message-Id: <20240801065249.206967-1-stefano.babic@swupdate.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Provags-ID: V03:K1:6mwcNB6C3N7sDm1UVuYKulvwCL4vdevN2SwDsRz7FCsIer0Wxmf 6TfNoajnmemAv3dj/i0CnyM5+z5M9/ybwGKuBUdLT5oqJL90TTV9e7R+I60cUZUpEEV4A/9 YSwUvlVm+kuCmmLfUlCxOyv5QzBKRjNRAbIcrKzhyqpTHso6jTx/rOEtL9oYZWYgTBhat1W EzPWwBiWxazDnNMrEFdnw== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:lFbBWe52TsU=;dflruvNvofVxKgkzEAc5XwKxYSk mYBF88sp+VrZ78YY91C9rmeN5PA1UwGEbkPCRPT4JdOcn/wCOI1Skq4KUYE6lxUaqgOB3TB43 Fch1mERtIZRmVYIqRczaFuWaYCFNwC54lpMzAg+6fm5m2n6nQ1kKh+316req9n6ATbtfBQMct 7+3Dh9F89WkPfnBrHnh6IeqTwnrN8DLZYmojuRDQjE4TlERYZouGM42rha2x/kCH71ZHz3+aN DUx32KocBh7xnl8Piv2+NfJpqwEpyerZFguS6NPVY1On03eymCAdLEgDoF9j54SzPAj7Jsq1J qmkwRDOi2Th6vnpioVwvGsbtfGfk4KWlmtpdkfaNsNzD5GUx/4lONQvfGmtaim6/tIOqX0lTS pgIgT3qt/5njzO875JrDM6cpLiF1XW11f7BuDpzgxjWArGO6WAoC9ljn2c11Dj48s1L6EgXZr 7oGitHYjUtMmWF09V21HTYZbBbqOwUUVd3My12ilc4d1FPV3vRKy6fKgD+ljQW+FfmQXBLJrx tNZSr9wDiC5n3F9SxQI2bm/ex9wEmT9Y74mnzd7PaS24AASWu8cmaKwXIxL0Q69k4Bi3/hEgf 0VtCQaPploH86bZ8d70eOhj8wNGP4r2lxoXtrEx59bKqICQCv4h7H05rwjbQtrWdPK4O9LfcW 9qcJJG5X07rlVISdTM7SGC0eRECZhesyA5XDA95CVqmspnvYbdj2HuJf+SpUj+q0dBavySYo7 DlhtGuLllfQHetweeK6TrPTfB1nshHu5A== X-Original-Sender: stefano.babic@swupdate.org X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@swupdate.org header.s=s1-ionos header.b=QtrzffRZ; spf=pass (google.com: domain of stefano.babic@swupdate.org designates 212.227.126.131 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , On custom design handler, a Lua callback can be set when an image should be read. The lua interface just checks that the Lua callback can be executed, but it does not check if the callback returns with an error code, and SWUpdate cannot detect this. Check return code in istream_read_callback instead of just returning success. Signed-off-by: Stefano Babic --- corelib/lua_interface.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) -- 2.34.1 diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c index f2ef849f..35433b9c 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -424,6 +424,7 @@ copyfile_exit: static int istream_read_callback(void *out, const void *buf, size_t len) { lua_State* L = (lua_State*)out; + lua_Number result; if (len > LUAL_BUFFERSIZE) { ERROR("I/O buffer size is larger than Lua's buffer size %d", LUAL_BUFFERSIZE); return -1; @@ -438,12 +439,23 @@ static int istream_read_callback(void *out, const void *buf, size_t len) memcpy(buffer, buf, len); luaL_addsize(&lbuffer, len); luaL_pushresult(&lbuffer); - if (lua_pcall(L, 1, 0, 0) != LUA_OK) { + if (lua_pcall(L, 1, 1, 0) != LUA_OK) { ERROR("Lua error in callback: %s", lua_tostring(L, -1)); lua_pop(L, 1); return -1; } - return 0; + + /* retrieve result */ + if (!lua_isnumber(L, -1)) { + ERROR("Lua Callback must return a number"); + lua_pop(L, 1); + return -1; + } + + result = lua_tonumber(L, -1); + lua_pop(L, 1); + + return (int) result; } static int l_istream_read(lua_State* L)