From owner-freebsd-bugs@FreeBSD.ORG Thu Jun 26 22:46:10 2014 Return-Path: Delivered-To: freebsd-bugs@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9C3DE4E8 for ; Thu, 26 Jun 2014 22:46:10 +0000 (UTC) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7D91E211C for ; Thu, 26 Jun 2014 22:46:10 +0000 (UTC) Received: from bugs.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.14.8/8.14.8) with ESMTP id s5QMkAHo021145 for ; Thu, 26 Jun 2014 23:46:10 +0100 (BST) (envelope-from bugzilla-noreply@freebsd.org) From: bugzilla-noreply@freebsd.org To: freebsd-bugs@FreeBSD.org Subject: [Bug 191427] New: "pw userdel" can go into an infinite loop Date: Thu, 26 Jun 2014 22:46:10 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bin X-Bugzilla-Version: 10.0-RELEASE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Many People X-Bugzilla-Who: yenbut@cs.washington.edu X-Bugzilla-Status: Needs Triage X-Bugzilla-Priority: Normal X-Bugzilla-Assigned-To: freebsd-bugs@FreeBSD.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Jun 2014 22:46:10 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=191427 Bug ID: 191427 Summary: "pw userdel" can go into an infinite loop Product: Base System Version: 10.0-RELEASE Hardware: Any OS: Any Status: Needs Triage Severity: Affects Many People Priority: Normal Component: bin Assignee: freebsd-bugs@FreeBSD.org Reporter: yenbut@cs.washington.edu There is an infinite loop in /usr/src/usr.sbin/pw/pw_user.c. Below is a code segment from pw_user.c: if (!strcmp(grp->gr_mem[i], a_name->val)) { while (grp->gr_mem[i] != NULL) { grp->gr_mem[i] = grp->gr_mem[i+1]; } strlcpy(group, grp->gr_name, MAXLOGNAME); chggrent(group, grp); } Note that the index variable i in the while loop is static. If the content of gr_mem[i+1] being copied is not NULL, the while loop would run forever. Environment: System: FreeBSD bld017c1e.cs.washington.edu 10.0-RELEASE-p6 FreeBSD 10.0-RELEASE-p6 #0: Tue Jun 24 07:47:37 UTC 2014 root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC amd64 How-To-Repeat: It is obvious from the code. However, to be certain, become root and run the following commands: pw useradd test pw groupmod test -M 'test,root' pw userdel test The last command would run forever. For cleaning up the 'test' group, hit Ctrl-C and then run the following command. pw groupdel test Fix: Here is one way to fix it: --- pw_user.c 2014/06/26 21:39:49 1.1 +++ pw_user.c 2014/06/26 21:41:18 @@ -429,12 +429,14 @@ delgrent(GETGRNAM(a_name->val)); SETGRENT(); while ((grp = GETGRENT()) != NULL) { - int i; + int i,j; char group[MAXLOGNAME]; for (i = 0; grp->gr_mem[i] != NULL; i++) { if (!strcmp(grp->gr_mem[i], a_name->val)) { - while (grp->gr_mem[i] != NULL) { - grp->gr_mem[i] = grp->gr_mem[i+1]; + j = i; + while (grp->gr_mem[j] != NULL) { + grp->gr_mem[j] = grp->gr_mem[j+1]; + j += 1; } strlcpy(group, grp->gr_name, MAXLOGNAME); chggrent(group, grp); -- You are receiving this mail because: You are the assignee for the bug.