From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 664CAA0546; Wed, 26 May 2021 23:43:55 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E5D2240150; Wed, 26 May 2021 23:43:54 +0200 (CEST) Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) by mails.dpdk.org (Postfix) with ESMTP id 87EF840143 for ; Wed, 26 May 2021 23:43:53 +0200 (CEST) Received: by mail-lf1-f51.google.com with SMTP id a2so4745939lfc.9 for ; Wed, 26 May 2021 14:43:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ho5bQZCWukXU3pasjPEaFWCT+Q9nQ4bTjGxRtu71WDQ=; b=lvhC15KdVggXrfl6ur4BKu/PkyaUmYSxRIBhXgLSR42IFYmoCnFoNRoDF26n58uIaU Z6kYN0yn7FpO/Ysf6lp85iFa8c166ibhgUXFv1DoZWvrHU4yXM7xpF6UpAwKolIVragr Kiqc3vVNxGdtmRCkAPLDwib4GAk3k84nFyxVRwdCFwRBDejc7d7ah2WZoUaxX+bJdrcM sfg0L6zG6lRZ4qiCCHGfV0DLyxF5LATnbjORjOZxDmgxvczRNP4BYvSiviEpmgIg5l/a kXGT6Xk1xK4e0S/FN41TMchfholSeZT1+cTz7HGU/U8nQnofom1rjr/KZ9XUGP+a1HUE 9Q4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ho5bQZCWukXU3pasjPEaFWCT+Q9nQ4bTjGxRtu71WDQ=; b=tX5e+y9eTvI6yGQcMlDKNVW8C7p1ABBfeTjwvZ/C6Ijts7tjwQp469d5VpZuEOPXBe vp+DqndMInE5qdRqxclBJ1TWtCswrypdrSWQ2AMeTwgWhoy5/QhfsffBdYdcFECtsiCf cp4hq5pYO36VsiLPWOMVfqofmyyEBbzqNv2utge+yefHPyO1qXly9N3nNdgrxhy4w6zh l1xlBPxFpXoHNM1ABDYuCjskajp7py+UBnPFd6E73I1XMPViVquDiyTVLO/on1Xozuvl Gvi/PMsM+SOvk/wzHbCCwmn/3RFCFN3fs2y/qCRNNV0x7Df+8aaHhaxxUsY2yPnjNm86 JoeA== X-Gm-Message-State: AOAM530HM+UEJgHaoYhK9ez0ZBkb4ZgzXA+CDJ70UuL58X5hMYik4YJ4 Cax1DR6totAzJdj7ZMAbuqcaGz6kpBRGZg== X-Google-Smtp-Source: ABdhPJwfmc2ibhJsDWYaId3wJmBK4zoUbSpP4/qwd7toTfYcygTOe72icAkLiKtrrMIFiMfkLrY+Cw== X-Received: by 2002:ac2:4e8f:: with SMTP id o15mr104258lfr.527.1622065432761; Wed, 26 May 2021 14:43:52 -0700 (PDT) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id q8sm20172lfu.197.2021.05.26.14.43.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 May 2021 14:43:52 -0700 (PDT) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Zhihong Peng , Dmitry Kozlyuk , Neil Horman Date: Thu, 27 May 2021 00:43:43 +0300 Message-Id: <20210526214343.31352-1-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH] pmdinfogen: allow padding after NUL terminator X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Size of string constant symbol may be larger than its length measured up to NUL terminator. In this case pmdinfogen included padding bytes after NUL terminator in generated source, yielding incorrect code. Always trim string data to NUL terminator while reading ELF. It was already done for COFF because there's no symbol size. Bugzilla ID: 720 Fixes: f0f93a7adfee ("buildtools: use Python pmdinfogen") Signed-off-by: Dmitry Kozlyuk --- buildtools/coff.py | 6 ------ buildtools/pmdinfogen.py | 10 ++++++++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/buildtools/coff.py b/buildtools/coff.py index 86fb0602b7..a7b6c37e32 100644 --- a/buildtools/coff.py +++ b/buildtools/coff.py @@ -146,9 +146,3 @@ def get_section_data(self, number): def get_string(self, offset): return decode_asciiz(self._strings[offset:]) - - -def decode_asciiz(data): - index = data.find(b'\x00') - end = index if index >= 0 else len(data) - return data[:end].decode() diff --git a/buildtools/pmdinfogen.py b/buildtools/pmdinfogen.py index 7a739ec7d4..8bb59699b8 100755 --- a/buildtools/pmdinfogen.py +++ b/buildtools/pmdinfogen.py @@ -19,6 +19,12 @@ import coff +def decode_asciiz(data): + index = data.find(b'\x00') + end = index if index >= 0 else len(data) + return data[:end].decode() + + class ELFSymbol: def __init__(self, image, symbol): self._image = image @@ -28,7 +34,7 @@ def __init__(self, image, symbol): def string_value(self): size = self._symbol["st_size"] value = self.get_value(0, size) - return value[:-1].decode() if value else "" + return decode_asciiz(value) if value else "" def get_value(self, offset, size): section = self._symbol["st_shndx"] @@ -86,7 +92,7 @@ def get_value(self, offset, size): @property def string_value(self): value = self._symbol.get_value(0) - return coff.decode_asciiz(value) if value else '' + return decode_asciiz(value) if value else "" class COFFImage: -- 2.29.3