From owner-svn-src-head@freebsd.org Tue Dec 1 14:02:15 2015 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 CE95AA3E146; Tue, 1 Dec 2015 14:02:15 +0000 (UTC) (envelope-from trasz@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 810A61966; Tue, 1 Dec 2015 14:02:15 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tB1E2EpP063693; Tue, 1 Dec 2015 14:02:14 GMT (envelope-from trasz@FreeBSD.org) Received: (from trasz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tB1E2EVD063692; Tue, 1 Dec 2015 14:02:14 GMT (envelope-from trasz@FreeBSD.org) Message-Id: <201512011402.tB1E2EVD063692@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: trasz set sender to trasz@FreeBSD.org using -f From: Edward Tomasz Napierala Date: Tue, 1 Dec 2015 14:02:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r291583 - head/usr.bin/rctl 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.20 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: Tue, 01 Dec 2015 14:02:15 -0000 Author: trasz Date: Tue Dec 1 14:02:14 2015 New Revision: 291583 URL: https://svnweb.freebsd.org/changeset/base/291583 Log: Fix rctl rule filters - eg the 'rctl -r :' case. MFC after: 1 month Sponsored by: The FreeBSD Foundation Modified: head/usr.bin/rctl/rctl.c Modified: head/usr.bin/rctl/rctl.c ============================================================================== --- head/usr.bin/rctl/rctl.c Tue Dec 1 13:20:21 2015 (r291582) +++ head/usr.bin/rctl/rctl.c Tue Dec 1 14:02:14 2015 (r291583) @@ -111,22 +111,38 @@ parse_group(const char *s, id_t *gidp, c * Replace human-readable number with its expanded form. */ static char * -expand_amount(char *rule, const char *unexpanded_rule) +expand_amount(const char *rule, const char *unexpanded_rule) { uint64_t num; const char *subject, *subject_id, *resource, *action, *amount, *per; - char *expanded; + char *copy, *expanded, *tofree; int ret; - subject = strsep(&rule, ":"); - subject_id = strsep(&rule, ":"); - resource = strsep(&rule, ":"); - action = strsep(&rule, "=/"); - amount = strsep(&rule, "/"); - per = rule; + tofree = copy = strdup(rule); + if (copy == NULL) { + warn("strdup"); + return (NULL); + } - if (amount == NULL || strlen(amount) == 0) - return (rule); + subject = strsep(©, ":"); + subject_id = strsep(©, ":"); + resource = strsep(©, ":"); + action = strsep(©, "=/"); + amount = strsep(©, "/"); + per = copy; + + if (amount == NULL || strlen(amount) == 0) { + /* + * The "copy" has already been tinkered with by strsep(). + */ + free(tofree); + copy = strdup(rule); + if (copy == NULL) { + warn("strdup"); + return (NULL); + } + return (copy); + } assert(subject != NULL); assert(subject_id != NULL); @@ -136,6 +152,7 @@ expand_amount(char *rule, const char *un if (expand_number(amount, &num)) { warnx("malformed rule '%s': invalid numeric value '%s'", unexpanded_rule, amount); + free(tofree); return (NULL); } @@ -149,9 +166,12 @@ expand_amount(char *rule, const char *un if (ret <= 0) { warn("asprintf"); + free(tofree); return (NULL); } + free(tofree); + return (expanded); }