]>
Commit | Line | Data |
---|---|---|
68222393 JB |
1 | From e41adf01647c695b80b112b337e76021bb9f30c3 Mon Sep 17 00:00:00 2001 |
2 | From: Laurent Bigonville <bigon@bigon.be> | |
3 | Date: Tue, 26 Sep 2017 15:15:30 +0200 | |
4 | Subject: [PATCH] Fix build failure with GCC 7 due to possible truncation of | |
5 | snprintf output | |
6 | ||
7 | setools fails to build under GCC7 -Wformat -Werror with the following error: | |
8 | ||
9 | x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -O2 -fdebug-prefix-map=/<<PKGBUILDDIR>>=. -fstack-protector-strong -Wformat -Werror=format-security -Wno-sign-compare -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Ilibqpol -Ilibqpol/include -I/usr/include/python3.6m -c libqpol/policy_extend.c -o build/temp.linux-amd64-3.6/libqpol/policy_extend.o -Werror -Wextra -Waggregate-return -Wfloat-equal -Wformat -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-include-dirs -Wnested-externs -Wold-style-definition -Wpointer-arith -Wredundant-decls -Wstrict-prototypes -Wunknown-pragmas -Wwrite-strings -Wno-missing-field-initializers -Wno-unused-parameter -Wno-cast-qual -Wno-shadow -Wno-unreachable-code -fno-exceptions | |
10 | libqpol/policy_extend.c: In function 'policy_extend': | |
11 | libqpol/policy_extend.c:161:27: error: '%04zd' directive output may be truncated writing between 4 and 10 bytes into a region of size 5 [-Werror=format-truncation=] | |
12 | snprintf(buff, 9, "@ttr%04zd", i + 1); | |
13 | ^~~~~ | |
14 | libqpol/policy_extend.c:161:22: note: directive argument in the range [1, 4294967295] | |
15 | snprintf(buff, 9, "@ttr%04zd", i + 1); | |
16 | ^~~~~~~~~~~ | |
17 | ||
18 | Increase the size of the buffer to avoid collisions | |
19 | ||
20 | Closes: https://github.com/TresysTechnology/setools/issues/174 | |
21 | Signed-off-by: Laurent Bigonville <bigon@bigon.be> | |
22 | --- | |
23 | libqpol/policy_extend.c | 16 ++++++++-------- | |
24 | 1 file changed, 8 insertions(+), 8 deletions(-) | |
25 | ||
26 | diff --git a/libqpol/policy_extend.c b/libqpol/policy_extend.c | |
27 | index 742819b..739e184 100644 | |
28 | --- a/libqpol/policy_extend.c | |
29 | +++ b/libqpol/policy_extend.c | |
30 | @@ -110,7 +110,7 @@ static int qpol_policy_remove_bogus_aliases(qpol_policy_t * policy) | |
31 | * Builds data for the attributes and inserts them into the policydb. | |
32 | * This function modifies the policydb. Names created for attributes | |
33 | * are of the form @ttr<value> where value is the value of the attribute | |
34 | - * as a four digit number (prepended with 0's as needed). | |
35 | + * as a ten digit number (prepended with 0's as needed). | |
36 | * @param policy The policy from which to read the attribute map and | |
37 | * create the type data for the attributes. This policy will be altered | |
38 | * by this function. | |
39 | @@ -125,7 +125,7 @@ static int qpol_policy_build_attrs_from_map(qpol_policy_t * policy) | |
40 | uint32_t bit = 0, count = 0; | |
41 | ebitmap_node_t *node = NULL; | |
42 | type_datum_t *tmp_type = NULL, *orig_type; | |
43 | - char *tmp_name = NULL, buff[10]; | |
44 | + char *tmp_name = NULL, buff[16]; | |
45 | int error = 0, retv; | |
46 | ||
47 | INFO(policy, "%s", "Generating attributes for policy. (Step 4 of 5)"); | |
48 | @@ -137,7 +137,7 @@ static int qpol_policy_build_attrs_from_map(qpol_policy_t * policy) | |
49 | ||
50 | db = &policy->p->p; | |
51 | ||
52 | - memset(&buff, 0, 10 * sizeof(char)); | |
53 | + memset(&buff, 0, 16 * sizeof(char)); | |
54 | ||
55 | for (i = 0; i < db->p_types.nprim; i++) { | |
56 | /* skip types */ | |
57 | @@ -158,7 +158,7 @@ static int qpol_policy_build_attrs_from_map(qpol_policy_t * policy) | |
58 | * with this attribute */ | |
59 | /* Does not exist */ | |
60 | if (db->p_type_val_to_name[i] == NULL){ | |
61 | - snprintf(buff, 9, "@ttr%04zd", i + 1); | |
62 | + snprintf(buff, 15, "@ttr%010zd", i + 1); | |
63 | tmp_name = strdup(buff); | |
64 | if (!tmp_name) { | |
65 | error = errno; | |
66 | @@ -240,7 +240,7 @@ static int qpol_policy_build_attrs_from_map(qpol_policy_t * policy) | |
67 | * Builds data for empty attributes and inserts them into the policydb. | |
68 | * This function modifies the policydb. Names created for the attributes | |
69 | * are of the form @ttr<value> where value is the value of the attribute | |
70 | - * as a four digit number (prepended with 0's as needed). | |
71 | + * as a ten digit number (prepended with 0's as needed). | |
72 | * @param policy The policy to which to add type data for attributes. | |
73 | * This policy will be altered by this function. | |
74 | * @return Returns 0 on success and < 0 on failure; if the call fails, | |
75 | @@ -251,7 +251,7 @@ static int qpol_policy_build_attrs_from_map(qpol_policy_t * policy) | |
76 | static int qpol_policy_fill_attr_holes(qpol_policy_t * policy) | |
77 | { | |
78 | policydb_t *db = NULL; | |
79 | - char *tmp_name = NULL, buff[10]; | |
80 | + char *tmp_name = NULL, buff[16]; | |
81 | int error = 0, retv = 0; | |
82 | ebitmap_t tmp_bmap = { NULL, 0 }; | |
83 | type_datum_t *tmp_type = NULL; | |
84 | @@ -265,12 +265,12 @@ static int qpol_policy_fill_attr_holes(qpol_policy_t * policy) | |
85 | ||
86 | db = &policy->p->p; | |
87 | ||
88 | - memset(&buff, 0, 10 * sizeof(char)); | |
89 | + memset(&buff, 0, 16 * sizeof(char)); | |
90 | ||
91 | for (i = 0; i < db->p_types.nprim; i++) { | |
92 | if (db->type_val_to_struct[i]) | |
93 | continue; | |
94 | - snprintf(buff, 9, "@ttr%04zd", i + 1); | |
95 | + snprintf(buff, 15, "@ttr%010zd", i + 1); | |
96 | tmp_name = strdup(buff); | |
97 | if (!tmp_name) { | |
98 | error = errno; |