From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Campbell Subject: Re: [PATCH for-4.6 1/2] libxl: fix devd removal path Date: Wed, 23 Sep 2015 09:46:56 +0100 Message-ID: <1442998016.10338.211.camel@citrix.com> References: <1442938993-94328-1-git-send-email-roger.pau@citrix.com> <1442938993-94328-2-git-send-email-roger.pau@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Zefhd-0005IW-LU for xen-devel@lists.xenproject.org; Wed, 23 Sep 2015 08:47:02 +0000 In-Reply-To: <1442938993-94328-2-git-send-email-roger.pau@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Roger Pau Monne , xen-devel@lists.xenproject.org Cc: Alex Velazquez , Wei Liu , Ian Jackson List-Id: xen-devel@lists.xenproject.org On Tue, 2015-09-22 at 18:23 +0200, Roger Pau Monne wrote: > > - /* Check if event_path ends with "state" and truncate it */ > - if (strlen(event_path) < strlen("state")) > + /* Check if event_path ends with "state" or "online" and truncate it. */ > + if (strlen(event_path) < strlen("state") || > + strlen(event_path) < strlen("online")) This is the same as strlen(...) < strlen("state") (or more formaly < min(strlen("state"),strlen("online")). Which is a bit dangerous because one might be tricked into thinking that path - strlen("online") was safe to do after this check when it's not. (The new code seems to have avoided this particular pattern which the old code used though) I think I agree with Ian's suggestion to use strrchr. Alternatively you could register two watches on the two specific paths you care about and point them at wrappers which trivially strip the appropriate trailing text and pass the base onto the current code? BTW, what is watch_path passed to this function, is it not the watched path i.e. the exact truncated event_path that you are looking for? Ian.