From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 0440E3851C01 for ; Wed, 26 Jan 2022 10:09:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0440E3851C01 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-262-KCV1PJHOMmuq1IKedCJ01A-1; Wed, 26 Jan 2022 05:09:40 -0500 X-MC-Unique: KCV1PJHOMmuq1IKedCJ01A-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 42F92100CCC0; Wed, 26 Jan 2022 10:09:39 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.8]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A0B5573165; Wed, 26 Jan 2022 10:09:22 +0000 (UTC) From: Florian Weimer To: Adhemerval Zanella via Libc-alpha Cc: "H . J . Lu" , Carlos O'Donell , Joseph Myers , Adhemerval Zanella Subject: Re: [PATCH] elf: Replace tst-p_alignmod1-editX with a python script References: <20220125170523.952874-1-adhemerval.zanella@linaro.org> Date: Wed, 26 Jan 2022 11:09:20 +0100 In-Reply-To: <20220125170523.952874-1-adhemerval.zanella@linaro.org> (Adhemerval Zanella via Libc-alpha's message of "Tue, 25 Jan 2022 14:05:23 -0300") Message-ID: <877damvmen.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jan 2022 10:09:43 -0000 * Adhemerval Zanella via Libc-alpha: > diff --git a/scripts/tst-elf-edit.py b/scripts/tst-elf-edit.py > new file mode 100644 > index 0000000000..1fb9b8e0fe > --- /dev/null > +++ b/scripts/tst-elf-edit.py > @@ -0,0 +1,206 @@ > +class Elf_Ehdr: > + def __init__(self, e_ident): > + endian, addr, off = elf_types_fmts(e_ident) > + self.fmt = '{0}HHI{1}{2}{2}IHHHHHH'.format(endian, addr, off) > + self.len = struct.calcsize(self.fmt) > + > + def read(self, f): > + buf = f.read(self.len) > + if not buf: > + error('{}: header too small'.format(f.name)) I think you need to check len(buf) < self.len. > +class Elf_Phdr: > + def __init__(self, e_ident): > + endian, addr, off = elf_types_fmts(e_ident) > + self.ei_class = e_ident[EI_CLASS] > + if self.ei_class == ELFCLASS32: > + self.fmt = '{0}I{2}{1}{1}IIII'.format(endian, addr, off) > + else: > + self.fmt = '{0}II{2}{1}{1}QQQ'.format(endian, addr, off) > + self.len = struct.calcsize(self.fmt) > + > + def read(self, f): > + buf = f.read(self.len) > + if not buf: > + error('{}: program header too small'.format(f.name)) Here as well. Rest looks okay. Thanks, Florian