From owner-svn-src-head@freebsd.org Sat Jul 11 19:44:12 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C130B36EAD9; Sat, 11 Jul 2020 19:44:12 +0000 (UTC) (envelope-from allanjude@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4B40j84jWsz4V5f; Sat, 11 Jul 2020 19:44:12 +0000 (UTC) (envelope-from allanjude@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 852011855E; Sat, 11 Jul 2020 19:44:12 +0000 (UTC) (envelope-from allanjude@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 06BJiCJr004082; Sat, 11 Jul 2020 19:44:12 GMT (envelope-from allanjude@FreeBSD.org) Received: (from allanjude@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 06BJiCKK004081; Sat, 11 Jul 2020 19:44:12 GMT (envelope-from allanjude@FreeBSD.org) Message-Id: <202007111944.06BJiCKK004081@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: allanjude set sender to allanjude@FreeBSD.org using -f From: Allan Jude Date: Sat, 11 Jul 2020 19:44:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r363109 - head/usr.sbin/nscd X-SVN-Group: head X-SVN-Commit-Author: allanjude X-SVN-Commit-Paths: head/usr.sbin/nscd X-SVN-Commit-Revision: 363109 X-SVN-Commit-Repository: base 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.33 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: Sat, 11 Jul 2020 19:44:12 -0000 Author: allanjude Date: Sat Jul 11 19:44:12 2020 New Revision: 363109 URL: https://svnweb.freebsd.org/changeset/base/363109 Log: nscd: does not warn about invalid values what parsing config file PR: 202135 Submitted by: amutu@amutu.com Reported By: Trond.Endrestol@ximalas.info Reviewed by: markj, freqlabs MFC after: 4 weeks Sponsored by: Klara Inc. Event: July 2020 Bugathon Differential Revision: https://reviews.freebsd.org/D25627 Modified: head/usr.sbin/nscd/parser.c Modified: head/usr.sbin/nscd/parser.c ============================================================================== --- head/usr.sbin/nscd/parser.c Sat Jul 11 19:29:24 2020 (r363108) +++ head/usr.sbin/nscd/parser.c Sat Jul 11 19:44:12 2020 (r363109) @@ -375,6 +375,7 @@ parse_config_file(struct configuration *config, char *fields[128]; int field_count, line_num, value; int res; + int invalid_value; TRACE_IN(parse_config_file); assert(config != NULL); @@ -388,6 +389,7 @@ parse_config_file(struct configuration *config, res = 0; line_num = 0; + invalid_value = 0; memset(buffer, 0, sizeof(buffer)); while ((res == 0) && (fgets(buffer, sizeof(buffer) - 1, fin) != NULL)) { field_count = strbreak(buffer, fields, sizeof(fields)); @@ -421,12 +423,20 @@ parse_config_file(struct configuration *config, (strcmp(fields[0], "positive-time-to-live") == 0) && (check_cachename(fields[1]) == 0) && ((value = get_number(fields[2], 0, -1)) != -1)) { + if (value <= 0) { + invalid_value = 1; + break; + } set_positive_time_to_live(config, fields[1], value); continue; } else if ((field_count == 3) && (strcmp(fields[0], "positive-confidence-threshold") == 0) && ((value = get_number(fields[2], 1, -1)) != -1)) { + if (value <= 0) { + invalid_value = 1; + break; + } set_positive_confidence_threshold(config, fields[1], value); continue; @@ -450,12 +460,20 @@ parse_config_file(struct configuration *config, (strcmp(fields[0], "negative-time-to-live") == 0) && (check_cachename(fields[1]) == 0) && ((value = get_number(fields[2], 0, -1)) != -1)) { + if (value <= 0) { + invalid_value = 1; + break; + } set_negative_time_to_live(config, fields[1], value); continue; } else if ((field_count == 3) && (strcmp(fields[0], "negative-confidence-threshold") == 0) && ((value = get_number(fields[2], 1, -1)) != -1)) { + if (value <= 0) { + invalid_value = 1; + break; + } set_negative_confidence_threshold(config, fields[1], value); continue; @@ -473,6 +491,10 @@ parse_config_file(struct configuration *config, (strcmp(fields[0], "suggested-size") == 0) && (check_cachename(fields[1]) == 0) && ((value = get_number(fields[2], 1, -1)) != -1)) { + if (value <= 0) { + invalid_value = 1; + break; + } set_suggested_size(config, fields[1], value); continue; } @@ -490,6 +512,10 @@ parse_config_file(struct configuration *config, (strcmp(fields[0], "keep-hot-count") == 0) && (check_cachename(fields[1]) == 0) && ((value = get_number(fields[2], 0, -1)) != -1)) { + if (value < 0) { + invalid_value = 1; + break; + } set_keep_hot_count(config, fields[1], value); continue; @@ -509,9 +535,16 @@ parse_config_file(struct configuration *config, break; } - LOG_ERR_2("config file parser", "error in file " - "%s on line %d", fname, line_num); - *error_str = "syntax error"; + if (invalid_value != 0) { + LOG_ERR_2("Invalid value for parameter", + "error in file %s on line %d", + fname, line_num); + *error_str = "invalid value"; + } else { + LOG_ERR_2("config file parser", "error in file " + "%s on line %d", fname, line_num); + *error_str = "syntax error"; + } *error_line = line_num; res = -1; }