unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob 13cffca2537b5d9da25a8342842e6e1a5aaa4a66 3745 bytes (raw)
name: gnu/packages/patches/libsepol-fix-stringop-truncation-warning.patch 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
 
Taken from upstream:
<https://github.com/SELinuxProject/selinux/commit/07d6f1cea5a8ec0251606636189bc519d80b0729>.

From 07d6f1cea5a8ec0251606636189bc519d80b0729 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
Date: Thu, 1 Jul 2021 20:07:07 +0200
Subject: [PATCH] libsepol: assure string NUL-termination of ibdev_name
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Clang complains:

 ibendport_record.c: In function ‘sepol_ibendport_get_ibdev_name’:
 ibendport_record.c:169:2: error: ‘strncpy’ specified bound 64 equals destination size [-Werror=stringop-truncation]
 169 | strncpy(tmp_ibdev_name, ibendport->ibdev_name, IB_DEVICE_NAME_MAX);
 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ibendport_record.c: In function ‘sepol_ibendport_set_ibdev_name’:
 ibendport_record.c:189:2: error: ‘strncpy’ specified bound 64 equals destination size [-Werror=stringop-truncation]
 189 | strncpy(tmp, ibdev_name, IB_DEVICE_NAME_MAX);
 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

strncpy(3) does not NUL-terminate the destination if the source is of
the same length or longer then the specified size.
The source of these copies are retrieved from
sepol_ibendport_alloc_ibdev_name(), which allocates a fixed amount of
IB_DEVICE_NAME_MAX bytes.
Reduce the size to copy by 1 of all memory regions allocated by
sepol_ibendport_alloc_ibdev_name().

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 libsepol/src/ibendport_record.c | 8 ++++----
 libsepol/src/ibendports.c | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/libsepol/src/ibendport_record.c b/libsepol/src/ibendport_record.c
index adf671615..1eb50914b 100644
--- a/libsepol/src/ibendport_record.c
+++ b/libsepol/src/ibendport_record.c
@@ -62,7 +62,7 @@ int sepol_ibendport_key_create(sepol_handle_t *handle,
 if (sepol_ibendport_alloc_ibdev_name(handle, &tmp_key->ibdev_name) < 0)
 goto err;

- strncpy(tmp_key->ibdev_name, ibdev_name, IB_DEVICE_NAME_MAX);
+ strncpy(tmp_key->ibdev_name, ibdev_name, IB_DEVICE_NAME_MAX - 1);
 tmp_key->port = port;

 *key_ptr = tmp_key;
@@ -166,7 +166,7 @@ int sepol_ibendport_get_ibdev_name(sepol_handle_t *handle,
 if (sepol_ibendport_alloc_ibdev_name(handle, &tmp_ibdev_name) < 0)
 goto err;

- strncpy(tmp_ibdev_name, ibendport->ibdev_name, IB_DEVICE_NAME_MAX);
+ strncpy(tmp_ibdev_name, ibendport->ibdev_name, IB_DEVICE_NAME_MAX - 1);
 *ibdev_name = tmp_ibdev_name;
 return STATUS_SUCCESS;

@@ -186,7 +186,7 @@ int sepol_ibendport_set_ibdev_name(sepol_handle_t *handle,
 if (sepol_ibendport_alloc_ibdev_name(handle, &tmp) < 0)
 goto err;

- strncpy(tmp, ibdev_name, IB_DEVICE_NAME_MAX);
+ strncpy(tmp, ibdev_name, IB_DEVICE_NAME_MAX - 1);
 free(ibendport->ibdev_name);
 ibendport->ibdev_name = tmp;
 return STATUS_SUCCESS;
@@ -230,7 +230,7 @@ int sepol_ibendport_clone(sepol_handle_t *handle,
 if (sepol_ibendport_alloc_ibdev_name(handle, &new_ibendport->ibdev_name) < 0)
 goto omem;

- strncpy(new_ibendport->ibdev_name, ibendport->ibdev_name, IB_DEVICE_NAME_MAX);
+ strncpy(new_ibendport->ibdev_name, ibendport->ibdev_name, IB_DEVICE_NAME_MAX - 1);
 new_ibendport->port = ibendport->port;

 if (ibendport->con &&
diff --git a/libsepol/src/ibendports.c b/libsepol/src/ibendports.c
index 6d56c9a17..ee5cb1930 100644
--- a/libsepol/src/ibendports.c
+++ b/libsepol/src/ibendports.c
@@ -34,7 +34,7 @@ static int ibendport_from_record(sepol_handle_t *handle,
 &ibdev_name) < 0)
 goto err;

- strncpy(tmp_ibendport->u.ibendport.dev_name, ibdev_name, IB_DEVICE_NAME_MAX);
+ strncpy(tmp_ibendport->u.ibendport.dev_name, ibdev_name, IB_DEVICE_NAME_MAX - 1);

 free(ibdev_name);
 ibdev_name = NULL;


debug log:

solving 59f9513d7a ...
found 59f9513d7a in https://yhetil.org/guix-patches/9NQooI4o8z-uFEla2gQE_BW33e1nehl_d8k15dMF5MdmVN7L_kFaZj__pPbd8tCgTnMcOR-fD46XJzCjdAiOgkVcYnwNnGwX2KChPUZWc5A=@nevans.me/

applying [1/1] https://yhetil.org/guix-patches/9NQooI4o8z-uFEla2gQE_BW33e1nehl_d8k15dMF5MdmVN7L_kFaZj__pPbd8tCgTnMcOR-fD46XJzCjdAiOgkVcYnwNnGwX2KChPUZWc5A=@nevans.me/
diff --git a/gnu/packages/patches/libsepol-fix-stringop-truncation-warning.patch b/gnu/packages/patches/libsepol-fix-stringop-truncation-warning.patch
new file mode 100644
index 0000000000..59f9513d7a

Checking patch gnu/packages/patches/libsepol-fix-stringop-truncation-warning.patch...
1:96: new blank line at EOF.
+
Applied patch gnu/packages/patches/libsepol-fix-stringop-truncation-warning.patch cleanly.
warning: 1 line adds whitespace errors.

index at:
100644 13cffca2537b5d9da25a8342842e6e1a5aaa4a66	gnu/packages/patches/libsepol-fix-stringop-truncation-warning.patch

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).