From patchwork Thu Feb 9 13:10:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Sorenson X-Patchwork-Id: 9564519 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 19355601C3 for ; Thu, 9 Feb 2017 13:12:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00E5A284FB for ; Thu, 9 Feb 2017 13:12:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E919928518; Thu, 9 Feb 2017 13:12:48 +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=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 7C306284FB for ; Thu, 9 Feb 2017 13:12:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752166AbdBINM1 (ORCPT ); Thu, 9 Feb 2017 08:12:27 -0500 Received: from mail-qt0-f174.google.com ([209.85.216.174]:35130 "EHLO mail-qt0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751994AbdBINMN (ORCPT ); Thu, 9 Feb 2017 08:12:13 -0500 Received: by mail-qt0-f174.google.com with SMTP id x49so2991464qtc.2 for ; Thu, 09 Feb 2017 05:12:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=Bepo3S86qFlujjMkaljv/HGVKtwuASE3NXFvadYjKAA=; b=OxXAQE4uyza4bqnEVnnQ+XGty6KwJIp2vAn5bf94fvtZNz4UnLXgZzssiNB5e9UoaY 4Wz0YG3myh2QT7qraOqXz2WzXkDDoYJfAerS0sA/7BVwxQhaI2ghl8sF9kiSjt9Y5thI PM4QIQ1RhxeSSqdYvLPA3LvdeCXLqoBU/N6TdvQNdDxK1nF+5z4oDYEUMPo1B957EKFr WzQdwr9b67BHknBnHa5rcdX5GE4QpY80fYGJc19zln8YDjI2JhSpWPn9TtBri4Kyr8dl D/0f+qtNQRCUrvHqrGH/PyIcsxeGWM/hORvMzi1inmzk2PNt63IoitwEiwEhA04uRqIU e/VA== X-Gm-Message-State: AMke39k5TciutzVdBtg8C8tGze5JXZOTW8CR+jqExXPdBpDQTcDNyUvvWn5coFrI2FEZ4BGc X-Received: by 10.237.36.122 with SMTP id s55mr2640293qtc.0.1486645931670; Thu, 09 Feb 2017 05:12:11 -0800 (PST) Received: from hut.sorenson.redhat.com (198-0-247-150-static.hfc.comcastbusiness.net. [198.0.247.150]) by smtp.gmail.com with ESMTPSA id k8sm9083590qke.29.2017.02.09.05.12.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Feb 2017 05:12:11 -0800 (PST) To: linux-nfs@vger.kernel.org From: Frank Sorenson Subject: [nfs-utils PATCH] Replace non-thread-safe strtok function calls in gssd Message-ID: <6481e076-509a-1b60-bc46-7ac537ca24fe@redhat.com> Date: Thu, 9 Feb 2017 07:10:02 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP commit fae681fa84f328cf601f34452b5a97f5d54ca2e2 Author: Frank Sorenson Date: 2017-02-04 14:05:48 -0600 gssd: replace non-thread-safe strtok gssd uses the non-thread-safe strtok() function, which can lead to incorrect program behavior. In addition, strtok() modifies the input string, so error messages may be incomplete. Replace strtok() with the thread-safe strtok_r() and a per-thread state variable. Also duplicate the input string for use when outputting error messages. Signed-off-by: Frank Sorenson --- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/utils/gssd/gssd_proc.c b/utils/gssd/gssd_proc.c index d74d372..ba6ec29 100644 --- a/utils/gssd/gssd_proc.c +++ b/utils/gssd/gssd_proc.c @@ -729,10 +729,18 @@ handle_gssd_upcall(struct clnt_upcall_info *info) char *target = NULL; char *service = NULL; char *enctypes = NULL; + char *saveptr; + char *upcall_str; printerr(2, "\n%s: '%s' (%s)\n", __func__, info->lbuf, clp->relpath); - for (p = strtok(info->lbuf, " "); p; p = strtok(NULL, " ")) { + upcall_str = strdup(info->lbuf); + if (upcall_str == NULL) { + printerr(0, "ERROR: malloc failure\n"); + goto out_nomem; + } + + for (p = strtok_r(info->lbuf, " ", &saveptr); p; p = strtok_r(NULL, " ", &saveptr)) { if (!strncmp(p, "mech=", strlen("mech="))) mech = p + strlen("mech="); else if (!strncmp(p, "uid=", strlen("uid="))) @@ -748,7 +756,7 @@ handle_gssd_upcall(struct clnt_upcall_info *info) if (!mech || strlen(mech) < 1) { printerr(0, "WARNING: handle_gssd_upcall: " "failed to find gss mechanism name " - "in upcall string '%s'\n", info->lbuf); + "in upcall string '%s'\n", upcall_str); goto out; } @@ -761,7 +769,7 @@ handle_gssd_upcall(struct clnt_upcall_info *info) if (!uidstr) { printerr(0, "WARNING: handle_gssd_upcall: " "failed to find uid " - "in upcall string '%s'\n", info->lbuf); + "in upcall string '%s'\n", upcall_str); goto out; } @@ -774,7 +782,7 @@ handle_gssd_upcall(struct clnt_upcall_info *info) if (target && strlen(target) < 1) { printerr(0, "WARNING: handle_gssd_upcall: " "failed to parse target name " - "in upcall string '%s'\n", info->lbuf); + "in upcall string '%s'\n", upcall_str); goto out; } @@ -789,7 +797,7 @@ handle_gssd_upcall(struct clnt_upcall_info *info) if (service && strlen(service) < 1) { printerr(0, "WARNING: handle_gssd_upcall: " "failed to parse service type " - "in upcall string '%s'\n", info->lbuf); + "in upcall string '%s'\n", upcall_str); goto out; } @@ -802,6 +810,8 @@ handle_gssd_upcall(struct clnt_upcall_info *info) do_error_downcall(clp->gssd_fd, uid, -EACCES); } out: + free(upcall_str); +out_nomem: free(info); return; }