Message ID | 20240131125623.45758-1-cgzones@googlemail.com (mailing list archive) |
---|---|
State | Accepted |
Commit | b52e27aeaa56 |
Delegated to: | Petr Lautrbach |
Headers | show |
Series | [1/3] libsepol: ensure transitivity in compare functions | expand |
On Wed, Jan 31, 2024 at 8:06 AM Christian Göttsche <cgzones@googlemail.com> wrote: > > Ensure comparison functions used by qsort(3) fulfill transitivity, since > otherwise the resulting array might not be sorted correctly or worse[1] > in case of integer overflows. > > [1]: https://www.qualys.com/2024/01/30/qsort.txt > > Signed-off-by: Christian Göttsche <cgzones@googlemail.com> For these three patches: Acked-by: James Carter <jwcart2@gmail.com> > --- > libsepol/src/kernel_to_common.c | 2 +- > libsepol/src/module_to_cil.c | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/libsepol/src/kernel_to_common.c b/libsepol/src/kernel_to_common.c > index 2422eed0..44f0be23 100644 > --- a/libsepol/src/kernel_to_common.c > +++ b/libsepol/src/kernel_to_common.c > @@ -503,7 +503,7 @@ static int ibendport_data_cmp(const void *a, const void *b) > if (rc) > return rc; > > - return (*aa)->u.ibendport.port - (*bb)->u.ibendport.port; > + return spaceship_cmp((*aa)->u.ibendport.port, (*bb)->u.ibendport.port); > } > > static int pirq_data_cmp(const void *a, const void *b) > diff --git a/libsepol/src/module_to_cil.c b/libsepol/src/module_to_cil.c > index ee22dbbd..c8dae562 100644 > --- a/libsepol/src/module_to_cil.c > +++ b/libsepol/src/module_to_cil.c > @@ -1680,7 +1680,7 @@ static int class_perm_cmp(const void *a, const void *b) > const struct class_perm_datum *aa = a; > const struct class_perm_datum *bb = b; > > - return aa->val - bb->val; > + return spaceship_cmp(aa->val, bb->val); > } > > static int common_to_cil(char *key, void *data, void *UNUSED(arg)) > -- > 2.43.0 > >
On Thu, Feb 22, 2024 at 10:14 AM James Carter <jwcart2@gmail.com> wrote: > > On Wed, Jan 31, 2024 at 8:06 AM Christian Göttsche > <cgzones@googlemail.com> wrote: > > > > Ensure comparison functions used by qsort(3) fulfill transitivity, since > > otherwise the resulting array might not be sorted correctly or worse[1] > > in case of integer overflows. > > > > [1]: https://www.qualys.com/2024/01/30/qsort.txt > > > > Signed-off-by: Christian Göttsche <cgzones@googlemail.com> > > For these three patches: > Acked-by: James Carter <jwcart2@gmail.com> > These three patches have been merged. Thanks, Jim > > --- > > libsepol/src/kernel_to_common.c | 2 +- > > libsepol/src/module_to_cil.c | 2 +- > > 2 files changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/libsepol/src/kernel_to_common.c b/libsepol/src/kernel_to_common.c > > index 2422eed0..44f0be23 100644 > > --- a/libsepol/src/kernel_to_common.c > > +++ b/libsepol/src/kernel_to_common.c > > @@ -503,7 +503,7 @@ static int ibendport_data_cmp(const void *a, const void *b) > > if (rc) > > return rc; > > > > - return (*aa)->u.ibendport.port - (*bb)->u.ibendport.port; > > + return spaceship_cmp((*aa)->u.ibendport.port, (*bb)->u.ibendport.port); > > } > > > > static int pirq_data_cmp(const void *a, const void *b) > > diff --git a/libsepol/src/module_to_cil.c b/libsepol/src/module_to_cil.c > > index ee22dbbd..c8dae562 100644 > > --- a/libsepol/src/module_to_cil.c > > +++ b/libsepol/src/module_to_cil.c > > @@ -1680,7 +1680,7 @@ static int class_perm_cmp(const void *a, const void *b) > > const struct class_perm_datum *aa = a; > > const struct class_perm_datum *bb = b; > > > > - return aa->val - bb->val; > > + return spaceship_cmp(aa->val, bb->val); > > } > > > > static int common_to_cil(char *key, void *data, void *UNUSED(arg)) > > -- > > 2.43.0 > > > >
diff --git a/libsepol/src/kernel_to_common.c b/libsepol/src/kernel_to_common.c index 2422eed0..44f0be23 100644 --- a/libsepol/src/kernel_to_common.c +++ b/libsepol/src/kernel_to_common.c @@ -503,7 +503,7 @@ static int ibendport_data_cmp(const void *a, const void *b) if (rc) return rc; - return (*aa)->u.ibendport.port - (*bb)->u.ibendport.port; + return spaceship_cmp((*aa)->u.ibendport.port, (*bb)->u.ibendport.port); } static int pirq_data_cmp(const void *a, const void *b) diff --git a/libsepol/src/module_to_cil.c b/libsepol/src/module_to_cil.c index ee22dbbd..c8dae562 100644 --- a/libsepol/src/module_to_cil.c +++ b/libsepol/src/module_to_cil.c @@ -1680,7 +1680,7 @@ static int class_perm_cmp(const void *a, const void *b) const struct class_perm_datum *aa = a; const struct class_perm_datum *bb = b; - return aa->val - bb->val; + return spaceship_cmp(aa->val, bb->val); } static int common_to_cil(char *key, void *data, void *UNUSED(arg))
Ensure comparison functions used by qsort(3) fulfill transitivity, since otherwise the resulting array might not be sorted correctly or worse[1] in case of integer overflows. [1]: https://www.qualys.com/2024/01/30/qsort.txt Signed-off-by: Christian Göttsche <cgzones@googlemail.com> --- libsepol/src/kernel_to_common.c | 2 +- libsepol/src/module_to_cil.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)