From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id A18DA13835A for ; Tue, 9 Feb 2021 19:08:09 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id B0B58E08D3; Tue, 9 Feb 2021 19:08:08 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 880D6E08D3 for ; Tue, 9 Feb 2021 19:08:08 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 4FB34340B65 for ; Tue, 9 Feb 2021 19:08:07 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id B8B7648B for ; Tue, 9 Feb 2021 19:08:05 +0000 (UTC) From: "Anthony G. Basile" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Anthony G. Basile" Message-ID: <1612897654.14748acf5e6e11db07e61ac188d6d1e799f29c6a.blueness@gentoo> Subject: [gentoo-commits] proj/eudev:master commit in: src/udev/ X-VCS-Repository: proj/eudev X-VCS-Files: src/udev/udevadm-hwdb.c X-VCS-Directories: src/udev/ X-VCS-Committer: blueness X-VCS-Committer-Name: Anthony G. Basile X-VCS-Revision: 14748acf5e6e11db07e61ac188d6d1e799f29c6a X-VCS-Branch: master Date: Tue, 9 Feb 2021 19:08:05 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 00187219-cfe9-4be2-a932-4c704445806b X-Archives-Hash: 6e37757365690b13a8ac174b33f2b93f commit: 14748acf5e6e11db07e61ac188d6d1e799f29c6a Author: Thomas Deutschmann gentoo org> AuthorDate: Tue Feb 9 12:17:06 2021 +0000 Commit: Anthony G. Basile gentoo org> CommitDate: Tue Feb 9 19:07:34 2021 +0000 URL: https://gitweb.gentoo.org/proj/eudev.git/commit/?id=14748acf udevadm: hwdb: sync with systemd Backports some changes from https://github.com/systemd/systemd/commit/6a34639e76b8b59233a97533b13836d5a44e8d4a. Signed-off-by: Thomas Deutschmann gentoo.org> Signed-off-by: Anthony G. Basile gentoo.org> src/udev/udevadm-hwdb.c | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c index 9df043835..6bc108783 100644 --- a/src/udev/udevadm-hwdb.c +++ b/src/udev/udevadm-hwdb.c @@ -426,21 +426,25 @@ static int insert_data(struct trie *trie, struct udev_list *match_list, char *value; struct udev_list_entry *entry; + assert(line[0] == ' '); + value = strchr(line, '='); if (!value) { - log_error("Error, key/value pair expected but got '%s' in '%s':", line, filename); + log_error("Warning, key-value pair expected but got \"%s\", ignoring", line); return -EINVAL; } value[0] = '\0'; value++; - /* libudev requires properties to start with a space */ + /* Replace multiple leading spaces by a single space */ while (isblank(line[0]) && isblank(line[1])) line++; - if (line[0] == '\0' || value[0] == '\0') { - log_error("Error, empty key or value '%s' in '%s':", line, filename); + if (isempty(line + 1) || isempty(value)) { + log_error("Warning, empty %s in \"%s=%s\", ignoring", + isempty(line + 1) ? "key" : "value", + line, value); return -EINVAL; } @@ -459,17 +463,21 @@ static int import_file(struct udev *udev, struct trie *trie, const char *filenam FILE *f; char line[LINE_MAX]; struct udev_list match_list; + uint32_t line_number = 0; + int r = 0, err; udev_list_init(udev, &match_list, false); f = fopen(filename, "re"); - if (f == NULL) + if (!f) return -errno; while (fgets(line, sizeof(line), f)) { size_t len; char *pos; + ++line_number; + /* comment line */ if (line[0] == '#') continue; @@ -491,7 +499,8 @@ static int import_file(struct udev *udev, struct trie *trie, const char *filenam break; if (line[0] == ' ') { - log_error("Error, MATCH expected but got '%s' in '%s':", line, filename); + log_error("Warning, match expected but got indented property \"%s\", ignoring line", line); + r = -EINVAL; break; } @@ -502,46 +511,55 @@ static int import_file(struct udev *udev, struct trie *trie, const char *filenam case HW_MATCH: if (len == 0) { - log_error("Error, DATA expected but got empty line in '%s':", filename); + log_error("Warning, property expected, ignoring record with no properties"); + r = -EINVAL; state = HW_NONE; udev_list_cleanup(&match_list); break; } - /* another match */ if (line[0] != ' ') { + /* another match */ udev_list_entry_add(&match_list, line, NULL); break; } /* first data */ state = HW_DATA; - insert_data(trie, &match_list, line, filename); + err = insert_data(trie, &match_list, line, filename); + if (err < 0) + r = err; break; case HW_DATA: - /* end of record */ if (len == 0) { + /* end of record */ state = HW_NONE; udev_list_cleanup(&match_list); break; } if (line[0] != ' ') { - log_error("Error, DATA expected but got '%s' in '%s':", line, filename); + log_error("Warning, property or empty line expected, got \"%s\", ignoring record", line); + r = -EINVAL; state = HW_NONE; udev_list_cleanup(&match_list); break; } - insert_data(trie, &match_list, line, filename); + err = insert_data(trie, &match_list, line, filename); + if (err < 0) + r = err; break; }; } + if (state == HW_MATCH) + log_error("Warning, property expected, ignoring record with no properties"); + fclose(f); udev_list_cleanup(&match_list); - return 0; + return r; } static void help(void) {