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 4485C389747; Fri, 17 Mar 2023 14:21:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4485C389747 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1679052091; bh=tDr4ftEQHa64KACj42dcxEMEJfMjR5wjU5hcxwlJqtE=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=HodSCFZqaUDEJkk5fnFsMBI0auaHcGT05tKm5I4tvc9tMvHgZBl3UEBogtd2LBGxN CAeUW/t/TigXjWhUAIQdKT6wfX0VUFRytSgdo+Y+F60vi4cLse6ocjUMmm8o6t1uJo fk+aeyYGoLziGvAvnCoupuGQ7IQt5NGMQ5W6+RIs= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id D4B4B14BD7D for ; Fri, 17 Mar 2023 14:21:29 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D4B4B14BD7D Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1pd89I-0000Ey-SH; Fri, 17 Mar 2023 14:21:29 +0300 Date: Fri, 17 Mar 2023 14:17:45 +0300 To: Maksim Kokryashkin Message-ID: References: <20230316161720.78669-1-max.kokryashkin@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230316161720.78669-1-max.kokryashkin@gmail.com> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9303C7CA6F8B0D1AB72854D396726309E7E7BABA9A978E7F3182A05F5380850404BAE83DCE29DB00F39ABFE5632FADF75FD994A014F54902F836DD5957F14E2FF X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7E50EC9128971FD6EEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637F97367C191A19EB28638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D808D3B0188A3DEDAF50439AC214631CA7117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC6BA66BB79834B351A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F4460429728776938767073520CCD848CCB6FE560CCB629EEF1311BF91D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B613439FA09F3DCB32089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34806D3522FB05EB395AE274F0DBBEFB21D8F3A1E7A6E725DF2F38FB1AA667EB51A0217747021085551D7E09C32AA3244C0271EF2BC375F28B415499F295B5B6B03A92A9747B6CC886927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojBy9lRm6Il0tTHRbLxD6krA== X-DA7885C5: 4EFAD9C1E8CF8947FBA599D237AE1FE7F55E502E57F7CEABE1A3A178C7D377FE262E2D401490A4A0DB037EFA58388B346E8BC1A9835FDE71 X-Mailru-Sender: 689FA8AB762F73933AF1F914F131DBF5AA8C7899BF435DB933EEAAAD3C9F52E10FBE9A32752B8C9C2AA642CC12EC09F1FB559BB5D741EB962F61BD320559CF1EFD657A8799238ED55FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Limit path length passed to C library loader. 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 Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Maksim! Thanks for the patch! LGTM, except a few minor nits regarding the commit message and the comment. On 16.03.23, Maksim Kokryashkin wrote: > From: Mike Pall > > (cherry-picked from commit 90e65514dda3994253c1e3007f63da7ace8f6b7b) > > C library loader uses `dlopen` under the hood, which fails, if Typo: s/C library loader/The C library loader/ > provided library path is longer than PATH_MAX. PATH_MAX is > 4096 bytes by default, so a corresponsing check is added to Typo: s/corresponsing/corresponding/ > `ll_loadfunc`. > > Maxim Kokryashkin: > * added the description and the test for the problem > > Part of tarantool/tarantool#8069 > --- > Side note: Still no adequate constants like PATH_MAX... > Side note: There is no test for successfull loadlib, since > there is one in the PUC-Rio suite. > > Branch: https://github.com/tarantool/luajit/tree/fckxorg/c-library-path-length > PR: https://github.com/tarantool/tarantool/pull/8449 > > src/lib_package.c | 7 ++++++- > test/tarantool-tests/c-library-path-length.test.lua | 13 +++++++++++++ > 2 files changed, 19 insertions(+), 1 deletion(-) > create mode 100644 test/tarantool-tests/c-library-path-length.test.lua > > diff --git a/src/lib_package.c b/src/lib_package.c > index 8573b9f9..67959a10 100644 > --- a/src/lib_package.c > +++ b/src/lib_package.c > @@ -215,7 +215,12 @@ static const char *mksymname(lua_State *L, const char *modname, > > static int ll_loadfunc(lua_State *L, const char *path, const char *name, int r) > { > - void **reg = ll_register(L, path); > + void **reg; > + if (strlen(path) >= 4096) { Side note: Why don't just use PATH_MAX here? AFAIK, it may be less than 4096 bytes. Just complaining. > + lua_pushliteral(L, "path too long"); > + return PACKAGE_ERR_LIB; > + } > + reg = ll_register(L, path); > if (*reg == NULL) *reg = ll_load(L, path, (*name == '*')); > if (*reg == NULL) { > return PACKAGE_ERR_LIB; /* Unable to load library. */ > diff --git a/test/tarantool-tests/c-library-path-length.test.lua b/test/tarantool-tests/c-library-path-length.test.lua > new file mode 100644 > index 00000000..11dd0cf4 > --- /dev/null > +++ b/test/tarantool-tests/c-library-path-length.test.lua > @@ -0,0 +1,13 @@ > +local tap = require('tap') > +local test = tap.test('c-library-path-length') > +test:plan(2) > + > +-- It doesn't really matter how long that string is, if it is longer than 4096. Minor: comment line is longer than 66 symbols. > +local long_path = string.rep('/path', 1024) > +package.cpath = long_path > + > +local res, err = package.loadlib(long_path, 'func') > +test:ok(res == nil, 'loaded library with a too large path') > +test:like(err, 'path too long', 'incorrect error') > + > +os.exit(test:check() and 0 or 1) > -- > 2.37.1 (Apple Git-137.1) > -- Best regards, Sergey Kaplun