From patchwork Wed Aug 15 19:30:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Randy Dunlap X-Patchwork-Id: 10566779 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 99511139A for ; Wed, 15 Aug 2018 19:30:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6575D2AFE4 for ; Wed, 15 Aug 2018 19:30:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 586DB2AFE6; Wed, 15 Aug 2018 19:30:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EFDA22AFE4 for ; Wed, 15 Aug 2018 19:30:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727487AbeHOWYM (ORCPT ); Wed, 15 Aug 2018 18:24:12 -0400 Received: from merlin.infradead.org ([205.233.59.134]:59502 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725941AbeHOWYM (ORCPT ); Wed, 15 Aug 2018 18:24:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Transfer-Encoding:Content-Type: MIME-Version:Date:Message-ID:Subject:From:Cc:To:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=REit2rzsb5WkTUr7mOiBEVmwkKhMmXIllsCt9e/cppo=; b=XPaXwiTtS13Etn8mIUixrJF7jf BOGGAbOlFs1NC15zZdmTY4idLB9Sa4pftrMHTMDhNIRcJlK2hhvGbidAF9O+YvMEUBa72ddJXUcNp SGzatRxTXOyYVVEUW9h+QzuoxtVXuQQ7p6+Qya2br2G4xrR3W53Vsf+/Ddi1H/o2vq/z8lGKt5wVb GZNQLldNeoYmctGQei9Xxt08Zf0cN76VXj2M/UgD0vb1EVrJ5y4QxCU3XGdqT9qL2GimkfIwIisMZ KeTMo+03pQJBREa9lrcvwrsP+15k8iJZ0TujE+drQMbOMQXKdtTXaK0XJPgtT3SxipJhQyUUfdmCp fK//CnUQ==; Received: from static-50-53-52-16.bvtn.or.frontiernet.net ([50.53.52.16] helo=midway.dunlab) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fq1VB-0004aU-Af; Wed, 15 Aug 2018 19:30:41 +0000 To: linux-kbuild , LKML , Masahiro Yamada Cc: Yuexing Wang From: Randy Dunlap Subject: [PATCH v2] scripts: modpost: check memory allocation results Message-ID: Date: Wed, 15 Aug 2018 12:30:38 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 Content-Language: en-US Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Randy Dunlap Fix missing error check for memory allocation functions in scripts/mod/modpost.c. Fixes kernel bugzilla #200319: https://bugzilla.kernel.org/show_bug.cgi?id=200319 Signed-off-by: Randy Dunlap Cc: Yuexing Wang Cc: Masahiro Yamada --- v2: add checks in more places scripts/mod/modpost.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- linux-next-20180814.orig/scripts/mod/modpost.c +++ linux-next-20180814/scripts/mod/modpost.c @@ -672,7 +672,7 @@ static void handle_modversions(struct mo if (ELF_ST_TYPE(sym->st_info) == STT_SPARC_REGISTER) break; if (symname[0] == '.') { - char *munged = strdup(symname); + char *munged = NOFAIL(strdup(symname)); munged[0] = '_'; munged[1] = toupper(munged[1]); symname = munged; @@ -1318,7 +1318,7 @@ static Elf_Sym *find_elf_symbol2(struct static char *sec2annotation(const char *s) { if (match(s, init_exit_sections)) { - char *p = malloc(20); + char *p = NOFAIL(malloc(20)); char *r = p; *p++ = '_'; @@ -1338,7 +1338,7 @@ static char *sec2annotation(const char * strcat(p, " "); return r; } else { - return strdup(""); + return NOFAIL(strdup("")); } } @@ -2036,7 +2036,7 @@ void buf_write(struct buffer *buf, const { if (buf->size - buf->pos < len) { buf->size += len + SZ; - buf->p = realloc(buf->p, buf->size); + buf->p = NOFAIL(realloc(buf->p, buf->size)); } strncpy(buf->p + buf->pos, s, len); buf->pos += len;