From patchwork Mon Dec 18 17:52:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 850238 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=networkplumber-org.20150623.gappssmtp.com header.i=@networkplumber-org.20150623.gappssmtp.com header.b="L7HTLu6U"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z0pXj3XLnz9t2W for ; Tue, 19 Dec 2017 04:52:53 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936222AbdLRRwg (ORCPT ); Mon, 18 Dec 2017 12:52:36 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:39334 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934505AbdLRRw1 (ORCPT ); Mon, 18 Dec 2017 12:52:27 -0500 Received: by mail-pl0-f68.google.com with SMTP id bi12so5258722plb.6 for ; Mon, 18 Dec 2017 09:52:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=I/rED9HCOlyzz0xmxlxt6F7w3XQ/HKY0If4naABnusM=; b=L7HTLu6UEV17AsdRY+qiBlTvnyCRy21O2xIgMUnPfgFj+uYb7x0pfeiIVktgr5Wwhi Y62V+8ogHaOVsu/i8Y7hrrMlrc2nPWUIjKc9qQA6serdtsoxLiV0AbPBiWlqBOCNrbdR ZydV/0Vx6GSr3+2Rs9XAQxH81mHYjGy1rLzuTGcXxFdh7LHYYMB49B8feqs2ecJgKmGK VYg0+xE+lfBuhZ20u4vLxMVBRAaEmokVwBhAOcWRYNEt+6KhzlimLJNPY70unorZHbsH UMqRXTTt3X6Ijc2y3M9YOPc3IrAkx4CCBQU9lWLn3RxP+F7tQ2TOLEZeY045drkJes3B bsIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=I/rED9HCOlyzz0xmxlxt6F7w3XQ/HKY0If4naABnusM=; b=O3iuOXneKiOcOYhpuckIkoEDtd9f3i5T0BjkehWDrpU68z1/dx8KsgaKxjK3/7uNlH x1pJdsWURkzcRkIvsPICOz+SdJUJwcq4JW2W8oJt7Dkm10jfN9I3FxJQIpC9q2xSZZTt yxluMTTCMD6QlCrJ8RlAK4mZnap+XA5sbbBVi9iyFFy6GDNYJ/MES5ziSs46kpIgIIjV VvFvb+L1nyHyfM/EOqhGdND9R9DktY9wFN5xuA2pSLonqV0TyPEt60y/5x+kRgIS7yoH Mmzf/5qiTAIY/HMkrh4Q0lPmjGSBkUVUsVEd4NwMgQm4zFAosEAApcaL98SzAV6hhv6i HDjg== X-Gm-Message-State: AKGB3mJ60WL0PLqEX8vfMnL+40JBH/+DLsycLLsFzpkHQKeiXmLt+T08 9xgbOuf6w/8mrmFpNJH5N/hDIU20dtU= X-Google-Smtp-Source: ACJfBouyy6SrYGmyxy0Y4eGRRLVrBDuyq+ZG9qXHNTB3eDbVeBOOjF6FVe6U6r177YQz69n28+wSGg== X-Received: by 10.84.176.195 with SMTP id v61mr492612plb.8.1513619546504; Mon, 18 Dec 2017 09:52:26 -0800 (PST) Received: from xeon-e3.lan (204-195-18-133.wavecable.com. [204.195.18.133]) by smtp.gmail.com with ESMTPSA id x4sm25494483pfb.13.2017.12.18.09.52.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Dec 2017 09:52:25 -0800 (PST) From: Stephen Hemminger To: netdev@vger.kernel.org Cc: Stephen Hemminger , Stephen Hemminger Subject: [PATCH] ss: fix crash with invalid command input file Date: Mon, 18 Dec 2017 09:52:21 -0800 Message-Id: <20171218175221.26449-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.11.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org If given an invalid input file with -F flag, ss would crash. Examples of invalid input are line to long, or null file. Signed-off-by: Stephen Hemminger --- misc/ssfilter.y | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/misc/ssfilter.y b/misc/ssfilter.y index ba82b65f712b..4db3c95faa3c 100644 --- a/misc/ssfilter.y +++ b/misc/ssfilter.y @@ -202,15 +202,23 @@ int yylex(void) argc++; } else if (yy_fp) { while (tokptr == NULL) { - if (fgets(argbuf, sizeof(argbuf)-1, yy_fp) == NULL) + size_t len; + + if (fgets(argbuf, sizeof(argbuf), yy_fp) == NULL) return 0; - argbuf[sizeof(argbuf)-1] = 0; - if (strlen(argbuf) == sizeof(argbuf) - 1) { - fprintf(stderr, "Too long line in filter"); + + len = strnlen(argbuf, sizeof(argbuf)); + if (len == 0) { + fprintf(stderr, "Invalid line\n"); + exit(-1); + } + + if (len >= sizeof(argbuf) - 1) { + fprintf(stderr, "Too long line in filter\n"); exit(-1); } - if (argbuf[strlen(argbuf)-1] == '\n') - argbuf[strlen(argbuf)-1] = 0; + if (argbuf[len - 1] == '\n') + argbuf[len-1] = 0; if (argbuf[0] == '#' || argbuf[0] == '0') continue; tokptr = argbuf;