From nobody Sat Sep 21 11:26:23 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4X9n5C5nJ5z5Vq6C; Sat, 21 Sep 2024 11:26:23 +0000 (UTC) (envelope-from git@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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4X9n5C3l9Yz4nhN; Sat, 21 Sep 2024 11:26:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726917983; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5s4SbOMjs/wb20l9sGlS+lwzih8UiJ4eP4p9wQBR/ro=; b=HJ6CXvzbQTAckMExnx2wzp4992taKUEZgz0hwDtop8KIsGz+Eq8jwp4MLmh6bW2vswAH96 TaC7XF8BQO7jS+/sDltgMUkMgbnKXeyG9t2V7iIYnjtbg/bEfJFI6bl2avkfQ4RUqIwlM5 5KY7QSMe4bkMhEGxhKeVxxzm2iNDOmwq0SnZrNHNnknD7cotnVFPaQZgTQCLlkXTxNF5CX OMuWgxTpmcdz58EpoPlhXz1MYEqQLhAM9ri36XguRxgVXzbs31xvFd5rhbkJp2vwJFY/4Z QwNehEZac3TvYyIdemkHPLT3mOMTztlKEEsKn6rL8ySNLEmtuGycEd6yDbQk6A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1726917983; a=rsa-sha256; cv=none; b=JNW/kGKDivYcFQJLXfk9IZWWNsbTwFbcKCEjwqMc6kamx3NJ8UtD4P2AXnlhxQOLo/NMQq 9BhKbMbf5hJLD87lpSdQ4xqSNkXmBCqmJRo2FZr7qLaSbuM3T7VEmjkWFpDz65K83sF336 Bla9XJBBEvIRS4bFhhFCKfEGhA36efrZz/NgHRIFAWdziT0QTmvnrKR/MI1yZIDW9gd2em UwKZnMraLS+Vgc7OnO+fu9FkXHqjz6mrfi2ynxjfDdKAr0khkORGsYn3EKgPK1cHXQnDwn UyZENv2IS6OQ7l+gBH+gSxrmsxkjgbaT1CGRSmo453M9zJBS0SUjkPdiHF8PHA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726917983; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5s4SbOMjs/wb20l9sGlS+lwzih8UiJ4eP4p9wQBR/ro=; b=sFq4HPWeIKoXWSKUqkRyBFCC2voQQdmjG39crEBB94XLRDtUre0n+GaBh956m9s0ZTTMMW bjWwQcUBDuU97diSvVqHHe+6h3+etdwGXy3wAF/QaxUy4zGY561TidRGeJTDlD4/bSRMHE 280k9PrXXhEWb6rL63tz5R8f+KGPWsPEfFSuVOIxMj08Dd9A9RvFY674kv7Doz6Jq8818X 0ToZ0J8CpKVJY+PwdGJmCby8Lwt9C9FPHig2byzcfgR4m2Z+ArY0e4IlpTfgY+qW4UAfBD 0dRlqYbsvEnPJgcT95f3Vf+Z3A9YhGTXPFe17TDv1BzveZrWZBwjnKf9WI8E0w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4X9n5C2pJ8zX7B; Sat, 21 Sep 2024 11:26:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 48LBQNQ0040283; Sat, 21 Sep 2024 11:26:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48LBQNmk040280; Sat, 21 Sep 2024 11:26:23 GMT (envelope-from git) Date: Sat, 21 Sep 2024 11:26:23 GMT Message-Id: <202409211126.48LBQNmk040280@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: f144058b4066 - main - Refactor error handling in lseek operations List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f144058b406656fa4678f8ff2f04c2da46176c79 Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=f144058b406656fa4678f8ff2f04c2da46176c79 commit f144058b406656fa4678f8ff2f04c2da46176c79 Author: Faraz Vahedi AuthorDate: 2024-08-21 13:19:38 +0000 Commit: Warner Losh CommitDate: 2024-09-21 11:25:15 +0000 Refactor error handling in lseek operations 1. Subtraction was performed on the current position regardless of the success of the lseek operation. In the event of an error, this resulted in the current position being erroneously set to -2, which bypassed the intended error handling mechanism. The proposed change performs error checking immediately following the lseek operation, prior to any modification of the current position. This ensures that a failed lseek operation will correctly trigger the appropriate error handling. 2. The error checking logic was based on the assumption that lseek would return `offset - 1` upon failure. However, this is not consistent with the behaviour of lseek as specified in the POSIX standard, which stipulates that lseek shall return -1 in case of an error. The code has been updated to reflect this standard, improving reliability and compliance. Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1392 --- lib/libfigpar/figpar.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/lib/libfigpar/figpar.c b/lib/libfigpar/figpar.c index 19fb91f08900..fbc6aaaba606 100644 --- a/lib/libfigpar/figpar.c +++ b/lib/libfigpar/figpar.c @@ -160,11 +160,11 @@ parse_config(struct figpar_config options[], const char *path, } /* Get the current offset */ - curpos = lseek(fd, 0, SEEK_CUR) - 1; - if (curpos == -1) { + if ((curpos = lseek(fd, 0, SEEK_CUR)) == -1) { close(fd); return (-1); } + curpos--; /* Find the length of the directive */ for (n = 0; r != 0; n++) { @@ -186,8 +186,7 @@ parse_config(struct figpar_config options[], const char *path, } /* Go back to the beginning of the directive */ - error = (int)lseek(fd, curpos, SEEK_SET); - if (error == (curpos - 1)) { + if (lseek(fd, curpos, SEEK_SET) == -1) { close(fd); return (-1); } @@ -245,11 +244,11 @@ parse_config(struct figpar_config options[], const char *path, } /* Get the current offset */ - curpos = lseek(fd, 0, SEEK_CUR) - 1; - if (curpos == -1) { + if ((curpos = lseek(fd, 0, SEEK_CUR)) == -1) { close(fd); return (-1); } + curpos--; /* Find the end of the value */ quote = 0; @@ -267,19 +266,18 @@ parse_config(struct figpar_config options[], const char *path, */ /* Get the current offset */ - charpos = lseek(fd, 0, SEEK_CUR) - 1; - if (charpos == -1) { + if ((charpos = lseek(fd, 0, SEEK_CUR)) == -1) { close(fd); return (-1); } + charpos--; /* * Go back so we can read the character before the key * to check if the character is escaped (which means we * should continue). */ - error = (int)lseek(fd, -2, SEEK_CUR); - if (error == -3) { + if (lseek(fd, -2, SEEK_CUR) == -1) { close(fd); return (-1); } @@ -291,8 +289,7 @@ parse_config(struct figpar_config options[], const char *path, */ for (n = 1; *p == '\\'; n++) { /* Move back another offset to read */ - error = (int)lseek(fd, -2, SEEK_CUR); - if (error == -3) { + if (lseek(fd, -2, SEEK_CUR) == -1) { close(fd); return (-1); } @@ -300,8 +297,7 @@ parse_config(struct figpar_config options[], const char *path, } /* Move offset back to the key and read it */ - error = (int)lseek(fd, charpos, SEEK_SET); - if (error == (charpos - 1)) { + if (lseek(fd, charpos, SEEK_SET) == -1) { close(fd); return (-1); } @@ -352,8 +348,7 @@ parse_config(struct figpar_config options[], const char *path, } /* Get the current offset */ - charpos = lseek(fd, 0, SEEK_CUR) - 1; - if (charpos == -1) { + if ((charpos = lseek(fd, 0, SEEK_CUR)) == -1) { close(fd); return (-1); } @@ -364,8 +359,7 @@ parse_config(struct figpar_config options[], const char *path, n--; /* Move offset back to the beginning of the value */ - error = (int)lseek(fd, curpos, SEEK_SET); - if (error == (curpos - 1)) { + if (lseek(fd, curpos, SEEK_SET) == -1) { close(fd); return (-1); }