From owner-svn-src-head@freebsd.org Thu Jul 28 15:33:20 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E2E69BA6712; Thu, 28 Jul 2016 15:33:20 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B37CA1A87; Thu, 28 Jul 2016 15:33:20 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u6SFXJhb012673; Thu, 28 Jul 2016 15:33:19 GMT (envelope-from ed@FreeBSD.org) Received: (from ed@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u6SFXJLU012672; Thu, 28 Jul 2016 15:33:19 GMT (envelope-from ed@FreeBSD.org) Message-Id: <201607281533.u6SFXJLU012672@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ed set sender to ed@FreeBSD.org using -f From: Ed Schouten Date: Thu, 28 Jul 2016 15:33:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r303445 - head/usr.sbin/uathload X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Jul 2016 15:33:21 -0000 Author: ed Date: Thu Jul 28 15:33:19 2016 New Revision: 303445 URL: https://svnweb.freebsd.org/changeset/base/303445 Log: Call basename() and dirname() in the POSIXly correct way. Pull copies of the input string, as these functions are allowed to modify them. Free the copies after creating the new pathname string. Modified: head/usr.sbin/uathload/uathload.c Modified: head/usr.sbin/uathload/uathload.c ============================================================================== --- head/usr.sbin/uathload/uathload.c Thu Jul 28 15:19:47 2016 (r303444) +++ head/usr.sbin/uathload/uathload.c Thu Jul 28 15:33:19 2016 (r303445) @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -84,19 +85,30 @@ extern uint8_t _binary_ar5523_bin_end; static int getdevname(const char *devname, char *msgdev, char *datadev) { - char *bn, *dn; + char *bn, *bnbuf, *dn, *dnbuf; - dn = dirname(devname); - if (dn == NULL) + dnbuf = strdup(devname); + if (dnbuf == NULL) return (-1); - bn = basename(devname); - if (bn == NULL || strncmp(bn, "ugen", 4)) + dn = dirname(dnbuf); + bnbuf = strdup(devname); + if (bnbuf == NULL) { + free(dnbuf); return (-1); + } + bn = basename(bnbuf); + if (strncmp(bn, "ugen", 4) != 0) { + free(dnbuf); + free(bnbuf); + return (-1); + } bn += 4; /* NB: pipes are hardcoded */ snprintf(msgdev, 256, "%s/usb/%s.1", dn, bn); snprintf(datadev, 256, "%s/usb/%s.2", dn, bn); + free(dnbuf); + free(bnbuf); return (0); }