{"id":3927,"url":"https://patchwork.libcamera.org/api/patches/3927/?format=json","web_url":"https://patchwork.libcamera.org/patch/3927/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200605074856.83927-1-email@uajain.com>","date":"2020-06-05T07:49:00","name":"[libcamera-devel] libcamera: ipa_module: Fix implicit sign-extension in eflLoadSymbol","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"33919c8d0db39319be023ebac06868ffb60e8906","submitter":{"id":1,"url":"https://patchwork.libcamera.org/api/people/1/?format=json","name":"Umang Jain","email":"email@uajain.com"},"delegate":{"id":12,"url":"https://patchwork.libcamera.org/api/users/12/?format=json","username":"uajain","first_name":"Umang","last_name":"Jain","email":"umang.jain@ideasonboard.com"},"mbox":"https://patchwork.libcamera.org/patch/3927/mbox/","series":[{"id":954,"url":"https://patchwork.libcamera.org/api/series/954/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=954","date":"2020-06-05T07:49:00","name":"[libcamera-devel] libcamera: ipa_module: Fix implicit sign-extension in eflLoadSymbol","version":1,"mbox":"https://patchwork.libcamera.org/series/954/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3927/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3927/checks/","tags":{},"headers":{"Return-Path":"<bounces+15657259-5c31-libcamera-devel=lists.libcamera.org@em7280.uajain.com>","Received":["from o1.f.az.sendgrid.net (o1.f.az.sendgrid.net [208.117.55.132])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8D463603C7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  5 Jun 2020 09:49:02 +0200 (CEST)","by filterdrecv-p3mdw1-6f5df8956d-dtkn2 with SMTP id\n\tfilterdrecv-p3mdw1-6f5df8956d-dtkn2-21-5ED9F8EC-47\n\t2020-06-05 07:49:00.93805191 +0000 UTC m=+128116.757044355","from mail.uajain.com (unknown)\n\tby ismtpd0002p1maa1.sendgrid.net (SG) with ESMTP id\n\t_7ei12dHRFO00p4xYnD31A for <libcamera-devel@lists.libcamera.org>;\n\tFri, 05 Jun 2020 07:49:00.304 +0000 (UTC)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=uajain.com\n\theader.i=@uajain.com header.b=\"cL11k7zk\"; \n\tdkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=uajain.com;\n\th=from:subject:mime-version:to:cc:content-transfer-encoding:\n\tcontent-type;\n\ts=s1; bh=h0C/WAYbKCnoEOJNIRxm36J5k2YWuJnVw3N3ykbrvAo=;\n\tb=cL11k7zk7DaTLtr27TDicP2oI9ykRH0XNMT9A5aK71JLbtswugpfGB3yr3yYuqH4QqYB\n\tve+3lnirqL/aOSfavHJPyBLPh1/pglYznZKoxWMWywrrINRV3pSJExAhQYLuKVJKpSpGNP\n\tmOKoNhceZyN7Y1sBEoMEn3fvCMLTdZtaU=","From":"Umang Jain <email@uajain.com>","Date":"Fri, 05 Jun 2020 07:49:00 +0000 (UTC)","Message-Id":"<20200605074856.83927-1-email@uajain.com>","Mime-Version":"1.0","X-SG-EID":"1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPc9vLW9W8H4bP+KZ0PPVtunwq9uf3kT61EILS3J9eMP4vzfBA46vY0T19v8UKFtYkyMSNLlrZnc+mGBF/sBfUu/SXST1DJn9BKNLNSMyvNq0o8qBHShe4itCxmYzLcnZDK4q/wL0xWIwpraBMOKv8Q+zNPLFEyTTvc6xeFEejPOzNlkxxX1s0x+FbAwgVukiLtP7K6H9QSEfGyP9Okv3Mx0Q==","To":"libcamera-devel@lists.libcamera.org","Content-Transfer-Encoding":"7bit","Content-Type":"text/plain; charset=us-ascii","Subject":"[libcamera-devel] [PATCH] libcamera: ipa_module: Fix implicit\n\tsign-extension in eflLoadSymbol","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Fri, 05 Jun 2020 07:49:03 -0000"},"content":"This sub-expression of two (16 bits, unsigned) operands\n\t(targetSymbol->st_shndx * eHdr->e_shentsize)\nis promoted to type int (32 bits, signed) for multiplication and then\nadded to eHdr->e_shoff, which is of the type long (64 bits, unsigned).\nSince eHdr->e_shoff is unsigned, the integer conversion rules dictates\nthat the other signed operand(i.e. the resultant of aforementioned\nsub-expression) will be converted to unsigned type too. This causes\nsign-extension for both of the above operands to match eHdr->e_shoff's\ntype and should be avoided.\n\nThe solution is to explicitly cast one of the operands of the\nsub-expression with unsigned int type. Hence, the other operand will be\ninteger promoted and the resultant will also be of unsigned int type,\nnot requiring to bother about a sign-extension.\n\nReported-by: Coverity CID=280008\nReported-by: Coverity CID=280009\nReported-by: Coverity CID=280010\nSigned-off-by: Umang Jain <email@uajain.com>\n---\n src/libcamera/ipa_module.cpp | 6 ++++--\n 1 file changed, 4 insertions(+), 2 deletions(-)","diff":"diff --git a/src/libcamera/ipa_module.cpp b/src/libcamera/ipa_module.cpp\nindex 91534b6..dd7538b 100644\n--- a/src/libcamera/ipa_module.cpp\n+++ b/src/libcamera/ipa_module.cpp\n@@ -102,7 +102,8 @@ Span<uint8_t> elfLoadSymbol(Span<uint8_t> elf, const char *symbol)\n \tif (!eHdr)\n \t\treturn {};\n \n-\toff_t offset = eHdr->e_shoff + eHdr->e_shentsize * eHdr->e_shstrndx;\n+\toff_t offset = eHdr->e_shoff + ((uint64_t)eHdr->e_shentsize *\n+\t\t\t\t\teHdr->e_shstrndx);\n \tElfW(Shdr) *sHdr = elfPointer<ElfW(Shdr)>(elf, offset);\n \tif (!sHdr)\n \t\treturn {};\n@@ -167,7 +168,8 @@ Span<uint8_t> elfLoadSymbol(Span<uint8_t> elf, const char *symbol)\n \t/* Locate and return data of symbol. */\n \tif (targetSymbol->st_shndx >= eHdr->e_shnum)\n \t\treturn {};\n-\toffset = eHdr->e_shoff + targetSymbol->st_shndx * eHdr->e_shentsize;\n+\toffset = eHdr->e_shoff + ((uint64_t)targetSymbol->st_shndx *\n+\t\t\t\t  eHdr->e_shentsize);\n \tsHdr = elfPointer<ElfW(Shdr)>(elf, offset);\n \tif (!sHdr)\n \t\treturn {};\n","prefixes":["libcamera-devel"]}