From patchwork Fri Oct 18 15:12:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 13841945 Received: from server02.seltendoof.de (server02.seltendoof.de [168.119.48.163]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CEEE20010F for ; Fri, 18 Oct 2024 15:13:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.48.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729264394; cv=none; b=Zivkf2bDFopqvflRIQc8rBI7fi+ji6OvHe4E1OHzJO4Au44kLGDjim19YxyYZ6QyXQY9nu/nZNHaLRZDeKpUGjlPPt30jTttyqRd8B7BEU5PKMOnCKpyPkVA0ISo67o/tviAA0MPtRD25Qdq90tQXY+I9VjI4XruED7aXj7VMI4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729264394; c=relaxed/simple; bh=cooWyQYxODLa73FWqnDldTm3rdd0GA53DwdE5dqLufk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=T3MzgXvNqIZfHdMh8+uJeyopJmYr5laEGMi47KNRmm5bPo+Fz6ZBpXhzJN+I4dAOO27oSPzr8XdmnFTn1nBngfNoNbgGALEfT37+TtlmDuFNYgq+C57rzfhKFkSR4YWcsdX04SB0fZEDdTqx3HisY1HeUpCtrwcb1XYFKLS6J48= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=seltendoof.de; spf=pass smtp.mailfrom=seltendoof.de; dkim=pass (2048-bit key) header.d=seltendoof.de header.i=@seltendoof.de header.b=TO+Rh6Sd; arc=none smtp.client-ip=168.119.48.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=seltendoof.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=seltendoof.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=seltendoof.de header.i=@seltendoof.de header.b="TO+Rh6Sd" From: =?utf-8?q?Christian_G=C3=B6ttsche?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seltendoof.de; s=2023072701; t=1729264387; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8jdytSgGIOtxdBMe+2TJUh7H89Qrv3ZqAWTDHRhfK3c=; b=TO+Rh6SdKHWZWZb8008EeEzBok0opV+cZQnAdD9ZP2qSxXKmjmxpoUefKwqz73qPmGboqf BGaW4v5IUPYi/NDNjCxC9oh6XTmiw+g77Z9oKa4n9IMXjlzxXVKyNBFjBkL5LkOBxArrtg 3exn3y59tghXPjqp8LufxzR78KVYY5NIt6Sbntfq6Rrv0t47cTCtavu70aoKTfyHX6RtLu z4P3Z79tsQ4EGXAWGGaikdCGtpOcpAk6bQgTVdMwTcN0ODmz7e7GAEKjsvrsRApXs/CDW6 XtQs3AryUIGkU6H33zWCJdbnglfYSeY8yVZATf6o1oCwygsPfAUWX5+frPGrHg== To: selinux@vger.kernel.org Cc: =?utf-8?q?Christian_G=C3=B6ttsche?= Subject: [PATCH 1/4] libselinux: avoid errno modification by fclose(3) Date: Fri, 18 Oct 2024 17:12:57 +0200 Message-ID: <20241018151300.445618-1-cgoettsche@seltendoof.de> Reply-To: cgzones@googlemail.com Precedence: bulk X-Mailing-List: selinux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christian Göttsche In case fclose(3) might modify the global variable errno, use a wrapper retaining the errno value. In the affected cases the success of fclose(3) itself is not important, since the underlying descriptor is only read from. Reported-by: clang-analyzer Signed-off-by: Christian Göttsche Acked-by: James Carter --- libselinux/src/get_context_list.c | 4 ++-- libselinux/src/label_file.c | 4 ++-- libselinux/src/selinux_internal.h | 11 +++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/libselinux/src/get_context_list.c b/libselinux/src/get_context_list.c index 0ad24654..222b54c1 100644 --- a/libselinux/src/get_context_list.c +++ b/libselinux/src/get_context_list.c @@ -438,7 +438,7 @@ int get_ordered_context_list(const char *user, __fsetlocking(fp, FSETLOCKING_BYCALLER); rc = get_context_user(fp, con, user, &reachable, &nreachable); - fclose(fp); + fclose_errno_safe(fp); if (rc < 0 && errno != ENOENT) { selinux_log(SELINUX_ERROR, "%s: error in processing configuration file %s\n", @@ -451,7 +451,7 @@ int get_ordered_context_list(const char *user, if (fp) { __fsetlocking(fp, FSETLOCKING_BYCALLER); rc = get_context_user(fp, con, user, &reachable, &nreachable); - fclose(fp); + fclose_errno_safe(fp); if (rc < 0 && errno != ENOENT) { selinux_log(SELINUX_ERROR, "%s: error in processing configuration file %s\n", diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c index 2fad0c93..40628e2c 100644 --- a/libselinux/src/label_file.c +++ b/libselinux/src/label_file.c @@ -628,7 +628,7 @@ static int process_file(const char *path, const char *suffix, rc = fcontext_is_binary(fp); if (rc < 0) { - (void) fclose(fp); + fclose_errno_safe(fp); return -1; } @@ -639,7 +639,7 @@ static int process_file(const char *path, const char *suffix, rc = digest_add_specfile(digest, fp, NULL, sb.st_size, found_path); - fclose(fp); + fclose_errno_safe(fp); if (!rc) return 0; diff --git a/libselinux/src/selinux_internal.h b/libselinux/src/selinux_internal.h index 450a42c2..372837dd 100644 --- a/libselinux/src/selinux_internal.h +++ b/libselinux/src/selinux_internal.h @@ -2,7 +2,9 @@ #define SELINUX_INTERNAL_H_ #include +#include #include +#include extern int require_seusers ; @@ -131,4 +133,13 @@ void *reallocarray(void *ptr, size_t nmemb, size_t size); #define IGNORE_DEPRECATED_DECLARATION_END #endif +static inline void fclose_errno_safe(FILE *stream) +{ + int saved_errno; + + saved_errno = errno; + (void) fclose(stream); + errno = saved_errno; +} + #endif /* SELINUX_INTERNAL_H_ */ From patchwork Fri Oct 18 15:12:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 13841944 Received: from server02.seltendoof.de (server02.seltendoof.de [168.119.48.163]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CF462022C1 for ; Fri, 18 Oct 2024 15:13:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.48.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729264394; cv=none; b=Xy91+4LJoQ2zGro/tj7tgL2ftuOZpLAab7P59K1P2f+JC4IxyFxSgrxnRCa/xsU0VZcDw0p9xBymiegpGf6/JB9HQLGtwmLwhtS9IHEVuBSS6fsqgvZg9+DZpcBqif6WS5RZW3wLqW2aQE5fAIDbysQad+fZPxVJDmiIk9i5LpE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729264394; c=relaxed/simple; bh=MHg9Sy6d/d/67nxZ+Kku8SAaQBKWHkE9gaN9DN1LiR4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HPNts6yESVBwLU+VNTrXO1+Eh38TNG0oVtI955Ikbon3Vq/9bcUASmkrQguwZsVqFFZfu9eCTsIuutQtOfrUyV1zW3LrU+ZCTjyoMgiKqeqq8KICsSS2wCwKrvI3yRNVYsD+QArL9NBpN+gGRlQwTT7Nk/+j9tYZ40Kg34yu0Vo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=seltendoof.de; spf=pass smtp.mailfrom=seltendoof.de; dkim=pass (2048-bit key) header.d=seltendoof.de header.i=@seltendoof.de header.b=XCX3s/+e; arc=none smtp.client-ip=168.119.48.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=seltendoof.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=seltendoof.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=seltendoof.de header.i=@seltendoof.de header.b="XCX3s/+e" From: =?utf-8?q?Christian_G=C3=B6ttsche?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seltendoof.de; s=2023072701; t=1729264388; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2kgyjG0I2pptuyQUEyBJ6ZbXaVitwir7sqnBvzvnqlQ=; b=XCX3s/+e0qED/svO5N+goQcLvXsiGU6y1HkpkKDrdGFl0BQoRS53GqC/7CZJII+h60UkEM eLKmcBNY7isHXnQoFOCNMuQVwRIhsOCNCRqGmIFcr2ejuRmvZHIvh1x7HpDmpH6Nqhd6d6 ECjLB2F7dViHXOyWR6K0CvWdrJ2/6OUOqdh7jOks/7eddYuxWiD1nHwOgbgf04Q9jvXI7I 1p+KPwUU1cUVTOGCD0BNU6KEMxM7BlMvNNoI9S73l4IKlLPkTcqfvyLY20Fui5X/NtG+v8 CtubciDsf734hG5uq7m0Y/XWilTyEQlfEmbZI25Y9FrvEWcYwN5YPGUmscWcVQ== To: selinux@vger.kernel.org Cc: =?utf-8?q?Christian_G=C3=B6ttsche?= Subject: [PATCH 2/4] selinux: free memory in error branch Date: Fri, 18 Oct 2024 17:12:58 +0200 Message-ID: <20241018151300.445618-2-cgoettsche@seltendoof.de> In-Reply-To: <20241018151300.445618-1-cgoettsche@seltendoof.de> References: <20241018151300.445618-1-cgoettsche@seltendoof.de> Reply-To: cgzones@googlemail.com Precedence: bulk X-Mailing-List: selinux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christian Göttsche Free the allocated line if it fails to parse via process_line() for the X or media database. Also declare the line_buf parameter of process_line() const, so it is more obvious it is not modified or free'd. Reported-by: clang-analyzer Signed-off-by: Christian Göttsche --- libselinux/src/label_media.c | 6 +++--- libselinux/src/label_x.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libselinux/src/label_media.c b/libselinux/src/label_media.c index bae065c1..d535ef86 100644 --- a/libselinux/src/label_media.c +++ b/libselinux/src/label_media.c @@ -30,12 +30,12 @@ struct saved_data { spec_t *spec_arr; }; -static int process_line(const char *path, char *line_buf, int pass, +static int process_line(const char *path, const char *line_buf, int pass, unsigned lineno, struct selabel_handle *rec) { struct saved_data *data = (struct saved_data *)rec->data; int items; - char *buf_p; + const char *buf_p; char *key, *context; buf_p = line_buf; @@ -145,7 +145,6 @@ static int init(struct selabel_handle *rec, const struct selinux_opt *opts, goto finish; } } - free(line_buf); status = digest_add_specfile(rec->digest, fp, NULL, sb.st_size, path); if (status) @@ -154,6 +153,7 @@ static int init(struct selabel_handle *rec, const struct selinux_opt *opts, digest_gen_hash(rec->digest); finish: + free(line_buf); fclose(fp); return status; } diff --git a/libselinux/src/label_x.c b/libselinux/src/label_x.c index ddae4f6c..c0d1d475 100644 --- a/libselinux/src/label_x.c +++ b/libselinux/src/label_x.c @@ -32,12 +32,12 @@ struct saved_data { spec_t *spec_arr; }; -static int process_line(const char *path, char *line_buf, int pass, +static int process_line(const char *path, const char *line_buf, int pass, unsigned lineno, struct selabel_handle *rec) { struct saved_data *data = (struct saved_data *)rec->data; int items; - char *buf_p; + const char *buf_p; char *type, *key, *context; buf_p = line_buf; @@ -172,7 +172,6 @@ static int init(struct selabel_handle *rec, const struct selinux_opt *opts, goto finish; } } - free(line_buf); status = digest_add_specfile(rec->digest, fp, NULL, sb.st_size, path); if (status) @@ -181,6 +180,7 @@ static int init(struct selabel_handle *rec, const struct selinux_opt *opts, digest_gen_hash(rec->digest); finish: + free(line_buf); fclose(fp); return status; } From patchwork Fri Oct 18 15:12:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 13841943 Received: from server02.seltendoof.de (server02.seltendoof.de [168.119.48.163]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CE9318C03B for ; Fri, 18 Oct 2024 15:13:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.48.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729264394; cv=none; b=MF9iGVR4Kx6vwEqFZ2l1i39g+VOh4aVgltcMt6VV01KMhG/lLEsahpRj5LJcskhNLhEhlwfBf5oEFDcOODy7NywUPhzOIS09Et3dsDJqB5VmWGLhiF7IUPHR8l1fXNDGGG19a26vAP2erkaDy5cpqUvyYaglgnz8Ww7LfebvnxM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729264394; c=relaxed/simple; bh=cYUEX58QNg+yNRZRqE9VCAGgCgvTY+luUYsIGYeduGQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=d0VFmHaHtVvtsKt845yL7yjJ5MCzSIMAJemDeZxMHFcbo1Aeu1gLos5Cs++OgRrJ4gtkMYKtesQRgXnmcDufKzuZ/OpLuYIaU6p5npX3o9e+KFmj+LQbWEaE/ThDAxYMC6MayR8sRZ7G3xGVhShsgq0f+SxgH2XZw/nPSLSG52g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=seltendoof.de; spf=pass smtp.mailfrom=seltendoof.de; dkim=pass (2048-bit key) header.d=seltendoof.de header.i=@seltendoof.de header.b=WzvfowrB; arc=none smtp.client-ip=168.119.48.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=seltendoof.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=seltendoof.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=seltendoof.de header.i=@seltendoof.de header.b="WzvfowrB" From: =?utf-8?q?Christian_G=C3=B6ttsche?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seltendoof.de; s=2023072701; t=1729264388; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zUm5PDnbIiRiQGyTNL24G1DTQaLNdHtiJAaqtfau2pc=; b=WzvfowrBWSDA/PUYcblaaNR4xa+tNCjY+MqkyGUraWmSMLVb3713UrORB67evkRL+vFHbV l/Zc8sXgqdvRYXM4ae+6PTIUqMWs7T2h71AzvVH3qQe7YrdaazIaw27205PVRGd6MoqKh3 EZebj9CTWUhj1ZOGE6/gJ0sxLzkrMBMT5DvzYlsRDDbcH7lstu729xcdLtDCEH3QK6Zoyx l2TfqRr0hNgfvRY/taKizBqpb+tqaERTS9QhPYN7jAaPFk8U+tHiSNGj+B+fvPHZXudEXc gOIqWE5JkyaJr8xobQ/GAXl6H7YavgzyQ5Xj0z73Xi3A5sAZa6wLDGsumhE1fg== To: selinux@vger.kernel.org Cc: =?utf-8?q?Christian_G=C3=B6ttsche?= Subject: [PATCH 3/4] libsemanage: check for rewind(3) failure Date: Fri, 18 Oct 2024 17:12:59 +0200 Message-ID: <20241018151300.445618-3-cgoettsche@seltendoof.de> In-Reply-To: <20241018151300.445618-1-cgoettsche@seltendoof.de> References: <20241018151300.445618-1-cgoettsche@seltendoof.de> Reply-To: cgzones@googlemail.com Precedence: bulk X-Mailing-List: selinux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christian Göttsche Use fseek(3) instead of rewind(3) to detect failures. Reported-by: clang-analyzer Signed-off-by: Christian Göttsche --- libsemanage/src/compressed_file.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libsemanage/src/compressed_file.c b/libsemanage/src/compressed_file.c index 5546b830..e230a70b 100644 --- a/libsemanage/src/compressed_file.c +++ b/libsemanage/src/compressed_file.c @@ -114,7 +114,12 @@ static ssize_t bunzip(semanage_handle_t *sh, FILE *f, void **data) /* Check if the file is bzipped */ bzerror = fread(buf, 1, BZ2_MAGICLEN, f); - rewind(f); + + if (fseek(f, 0L, SEEK_SET) == -1) { + ERR(sh, "Failure rewinding file."); + goto exit; + } + if ((bzerror != BZ2_MAGICLEN) || memcmp(buf, BZ2_MAGICSTR, BZ2_MAGICLEN)) { goto exit; } From patchwork Fri Oct 18 15:13:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 13841942 Received: from server02.seltendoof.de (server02.seltendoof.de [168.119.48.163]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0CF82022C4 for ; Fri, 18 Oct 2024 15:13:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.48.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729264394; cv=none; b=PrDip5LuCLTQv1qB1QO5z61ZfLcIo52p65jBMMetC1sLBjD5VarDcdbNU047I91u2k+bzLitnFOKh40h4BS8BJHQhCnxGSZ8kArc/K/LcmXhvpTMy6JS5pcn1PAIHMUvx3etMObipC3LisfATl5HCf/vb4xDhUvdQchUnDfOlqs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729264394; c=relaxed/simple; bh=pn2pscKBMz2WcVT4ShuUDPCgf5L6xXfCHoPRCsBNK1c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mlhBpY5U2yeTb2BAV6zQ/58S3NO7wP5DLpVZRCr1Y0M2AYqPo77mlJeri8FTGf2I1rXg0ncTpa72Z64dZ7D9eu0sbwLiCMbHa6vXc332KioS7pF/2cnEIDbf/zF5cGkZ23DSQpMVzMTSgL3+wxM6f+A6RfXOyQvNIsWeBTil6Aw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=seltendoof.de; spf=pass smtp.mailfrom=seltendoof.de; dkim=pass (2048-bit key) header.d=seltendoof.de header.i=@seltendoof.de header.b=ZPyWzd1V; arc=none smtp.client-ip=168.119.48.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=seltendoof.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=seltendoof.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=seltendoof.de header.i=@seltendoof.de header.b="ZPyWzd1V" From: =?utf-8?q?Christian_G=C3=B6ttsche?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seltendoof.de; s=2023072701; t=1729264388; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oaASQNZLTvaOORUJxLX1TZhEyA82G6w465uGhQVszZ8=; b=ZPyWzd1VaT0xI5NmfqR0a6/TAYMQH1ie6Op7KszzlAzNEIkMkaRATobeI8q7K0wcAmtf+C 9gEcShWyRSPWJJOA51crjRtetAidICzwXMdAjCoGv6M8fkrBVazwu1l5P9poZGX5Ejfe0W AwLb1eYeWzE1r2u3k0JntY6L8SY2MGDTI/H/qGj9xWajnqYc1hbfcdZEDR1h37ATvw74E2 GOXq0Sisk0fA5Guwa8w8X4QDSP8DrLHQ1xjB2FppwuuMGbnqdoZTwIcqeN8AeHxIQcdmyb PCw3y9eVrFo0t+14HUN+5RxI94xF16NgTarBlh7Y9l2qGFGH8TuNk2kzrMdDHw== To: selinux@vger.kernel.org Cc: =?utf-8?q?Christian_G=C3=B6ttsche?= Subject: [PATCH 4/4] selinux: set missing errno in failure branch Date: Fri, 18 Oct 2024 17:13:00 +0200 Message-ID: <20241018151300.445618-4-cgoettsche@seltendoof.de> In-Reply-To: <20241018151300.445618-1-cgoettsche@seltendoof.de> References: <20241018151300.445618-1-cgoettsche@seltendoof.de> Reply-To: cgzones@googlemail.com Precedence: bulk X-Mailing-List: selinux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christian Göttsche Set errno in open_file() if rolling_append(), which does not set errno, failed, since transitive callers might rely on it. Reported-by: clang-analyzer Signed-off-by: Christian Göttsche --- libselinux/src/label_file.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c index 40628e2c..b9c3be2a 100644 --- a/libselinux/src/label_file.c +++ b/libselinux/src/label_file.c @@ -563,8 +563,10 @@ static FILE *open_file(const char *path, const char *suffix, /* This handles the case if suffix is null */ path = rolling_append(stack_path, fdetails[i].suffix, sizeof(stack_path)); - if (!path) + if (!path) { + errno = ENOMEM; return NULL; + } rc = stat(path, &fdetails[i].sb); if (rc)