From patchwork Thu Jul 18 19:03:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rohit Ashiwal X-Patchwork-Id: 11049427 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 3293D746 for ; Thu, 18 Jul 2019 19:06:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 232D72862A for ; Thu, 18 Jul 2019 19:06:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 178E52872A; Thu, 18 Jul 2019 19:06:11 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 B3F042862A for ; Thu, 18 Jul 2019 19:06:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391116AbfGRTGJ (ORCPT ); Thu, 18 Jul 2019 15:06:09 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:35688 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387815AbfGRTGJ (ORCPT ); Thu, 18 Jul 2019 15:06:09 -0400 Received: by mail-pg1-f195.google.com with SMTP id s1so6999258pgr.2 for ; Thu, 18 Jul 2019 12:06:09 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=PbaKQr7Ljt5B74y63NGQ7Ds9EGU+IxbhlHcxkhYMMUk=; b=V+NhhWZf2yC2nnZwwDTqr76yaaYfEiB+1rp6qpmImSaeA0QZqeLC5AD8CVBgEnxO29 nDdgRRPFI9IzoGXb0T0yCFsVsM5httI+Rid0JtSHj+uFiXSsgNDJP3d+lFf0XBXPcYpV vh9jneILSBTUUsQqzwtifmA6JXNrgDcFBwM/aAVCTgx8/VVrmK1egu4HhXiOpnH8M560 F46oFwK+KO1Je0j0oFdzJW0cxJd4VO1zjo6yROgmRc3g5sz6HPS6vUBT2TKTN4pB/Lw3 NWVQRrAYSRXAPFJsTVmEcF24ZpVY33ID0jWbxBklhf+xvFL2S/7eoL3vtcdFh61GKh08 SHwQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=PbaKQr7Ljt5B74y63NGQ7Ds9EGU+IxbhlHcxkhYMMUk=; b=CNU4L6PV55HyI4d5IA3DfLznSzf1+lJLR5qhIKhQMhU45YP62L/Fb/FeSZf4ucRMsm ra1UXBOEe3RYa2HuoqkVMVTuBvYet6ZhGyi5vKNvS3Lezru/WRI3DJtJm/8/ejm/6rVh o3sCA47v94s1y7XfMPxKVJx7yvHHpKGwjjFpsh2OoH4ZpE+bcWFEnaDCCl9awOUNTZXO lJbfwyUm/0moai6/0A4oqyqW/Mjfzv60D+ym8BXX8YWB96Sldq+AkbttUIsAz7tQwWDl aNIoMUHQwFky9w6o6mUwIKkSZ5VmUlPWVM0FemZvb2ghH+bYJKDzlx0HBgKkZ97EvqN2 bpBA== X-Gm-Message-State: APjAAAUwy5c6mwytXfwBk839bKC8e1MHclB1zlCTg/gzkUHGfD7VvrEH 3+FJfXxh+KrAIQS5QPSTb+A= X-Google-Smtp-Source: APXvYqwmFDbsUXcXOpCsSKTYfNdsWHqFdT6TZNuGC/5M6vqFVVRhHYJ1brYnsKYQo+n4vobGGHfkDA== X-Received: by 2002:a17:90a:9301:: with SMTP id p1mr52665570pjo.22.1563476768644; Thu, 18 Jul 2019 12:06:08 -0700 (PDT) Received: from ar135.iitr.local ([27.63.78.254]) by smtp.gmail.com with ESMTPSA id f88sm28237555pjg.5.2019.07.18.12.06.04 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 18 Jul 2019 12:06:07 -0700 (PDT) From: Rohit Ashiwal To: Rohit Cc: Dscho , Git Mailing List , Junio , Martin , Phillip , Thomas , Elijah Subject: [GSoC][PATCH v2 1/2] sequencer: add NULL checks under read_author_script Date: Fri, 19 Jul 2019 00:33:13 +0530 Message-Id: <20190718190314.20549-2-rohit.ashiwal265@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190718190314.20549-1-rohit.ashiwal265@gmail.com> References: <20190712185357.21211-1-rohit.ashiwal265@gmail.com> <20190718190314.20549-1-rohit.ashiwal265@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP read_author_script reads name, email and author date from the author script. However, it does not check if the arguments are NULL. Adding NULL checks will allow us to selectively get the required value, for example: char *date; if (read_author_script(_path_, NULL, NULL, &date, _int_)) die(_("failed to read author date")); /* needs to be free()'d */ return date; Add NULL checks for better control over the information retrieved. Signed-off-by: Rohit Ashiwal --- sequencer.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/sequencer.c b/sequencer.c index f88a97fb10..a2d7b0925e 100644 --- a/sequencer.c +++ b/sequencer.c @@ -821,9 +821,19 @@ int read_author_script(const char *path, char **name, char **email, char **date, error(_("missing 'GIT_AUTHOR_DATE'")); if (date_i < 0 || email_i < 0 || date_i < 0 || err) goto finish; - *name = kv.items[name_i].util; - *email = kv.items[email_i].util; - *date = kv.items[date_i].util; + + if (name) + *name = kv.items[name_i].util; + else + free(kv.items[name_i].util); + if (email) + *email = kv.items[email_i].util; + else + free(kv.items[email_i].util); + if (date) + *date = kv.items[date_i].util; + else + free(kv.items[date_i].util); retval = 0; finish: string_list_clear(&kv, !!retval);