Commit ec86019
committed
Fix likely misuse of ctype.h API #4397
The standard C <ctype.h> API takes type int as argument, but when
that argument value is neither (a) a value representable by type unsigned
char nor (b) the value of the macro EOF, the behaviour is undefined. See
C11, Sec. 7.4 Character handling <ctype.h> p.200, clause 1.
The <ctype.h> functions are designed to take as arguments the
values returned by getc or fgetc, no for processing elements of an
arbitrary string stored in a char array. Safely processing arbitrary
strings requires explicit cast to unsigned char to keep the argument
values within the domain {EOF, 0, 1 ..., 255}.
OTH, passing negative values {-128, -127, ..., -1} may trigger
undefined behaviour, and also the non-EOF 0xff can be conflated with -1,
which, although not forbidden, may give unintended results. Casting to
unsigned char avoids sign extension when implicitly converting to int.
This commit introduces an explicit cast to unsigned char when
passing argument to the standard <ctype.h> function family.
Reported-by: riastradh
Signed-off-by: Thales Antunes de Oliveira Barretto <[email protected]>
# api/src/glfs.c | 2 +-
# cli/src/cli-cmd-parser.c | 12 ++++-----
# cli/src/cli-xml-output.c | 4 +--
# extras/benchmarking/rdd.c | 2 +-
# extras/geo-rep/gsync-sync-gfid.c | 2 +-
# geo-replication/src/procdiggy.c | 4 +--
# libglusterfs/src/common-utils.c | 31 +++++++++++++-----------
# tests/basic/open-behind/tester.c | 5 ++--
# xlators/cluster/ec/src/ec-code.c | 4 +--
# xlators/debug/io-stats/src/io-stats.c | 4 +--
# xlators/mgmt/glusterd/src/glusterd-ganesha.c | 5 ++--
# xlators/mgmt/glusterd/src/glusterd-geo-rep.c | 10 ++++----
# xlators/mgmt/glusterd/src/glusterd-mountbroker.c | 4 +--
# xlators/mgmt/glusterd/src/glusterd-pmap.c | 4 +--
# xlators/mgmt/glusterd/src/glusterd-utils.c | 2 +-
# xlators/mgmt/glusterd/src/glusterd-volume-set.c | 3 ++-
# xlators/performance/md-cache/src/md-cache.c | 2 +-
# 17 files changed, 53 insertions(+), 47 deletions(-)
# api/src/glfs.c | 2 +-
# cli/src/cli-cmd-parser.c | 12 ++++-----
# cli/src/cli-xml-output.c | 4 +--
# extras/benchmarking/rdd.c | 2 +-
# extras/geo-rep/gsync-sync-gfid.c | 2 +-
# geo-replication/src/procdiggy.c | 4 +--
# libglusterfs/src/common-utils.c | 31 +++++++++++++-----------
# tests/basic/open-behind/tester.c | 5 ++--
# xlators/cluster/ec/src/ec-code.c | 4 +--
# xlators/debug/io-stats/src/io-stats.c | 4 +--
# xlators/mgmt/glusterd/src/glusterd-ganesha.c | 5 ++--
# xlators/mgmt/glusterd/src/glusterd-geo-rep.c | 10 ++++----
# xlators/mgmt/glusterd/src/glusterd-mountbroker.c | 4 +--
# xlators/mgmt/glusterd/src/glusterd-pmap.c | 4 +--
# xlators/mgmt/glusterd/src/glusterd-utils.c | 2 +-
# xlators/mgmt/glusterd/src/glusterd-volume-set.c | 3 ++-
# xlators/performance/md-cache/src/md-cache.c | 2 +-
# 17 files changed, 53 insertions(+), 47 deletions(-)
# api/src/glfs.c | 2 +-
# cli/src/cli-cmd-parser.c | 12 ++++-----
# cli/src/cli-xml-output.c | 4 +--
# extras/benchmarking/rdd.c | 2 +-
# extras/geo-rep/gsync-sync-gfid.c | 2 +-
# geo-replication/src/procdiggy.c | 4 +--
# libglusterfs/src/common-utils.c | 31 +++++++++++++-----------
# tests/basic/open-behind/tester.c | 5 ++--
# xlators/cluster/ec/src/ec-code.c | 4 +--
# xlators/debug/io-stats/src/io-stats.c | 4 +--
# xlators/mgmt/glusterd/src/glusterd-ganesha.c | 5 ++--
# xlators/mgmt/glusterd/src/glusterd-geo-rep.c | 10 ++++----
# xlators/mgmt/glusterd/src/glusterd-mountbroker.c | 4 +--
# xlators/mgmt/glusterd/src/glusterd-pmap.c | 4 +--
# xlators/mgmt/glusterd/src/glusterd-utils.c | 2 +-
# xlators/mgmt/glusterd/src/glusterd-volume-set.c | 3 ++-
# xlators/performance/md-cache/src/md-cache.c | 2 +-
# 17 files changed, 53 insertions(+), 47 deletions(-)1 parent c440132 commit ec86019
File tree
17 files changed
+53
-47
lines changed- api/src
- cli/src
- extras
- benchmarking
- geo-rep
- geo-replication/src
- libglusterfs/src
- tests/basic/open-behind
- xlators
- cluster/ec/src
- debug/io-stats/src
- mgmt/glusterd/src
- performance/md-cache/src
17 files changed
+53
-47
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
850 | 850 | | |
851 | 851 | | |
852 | 852 | | |
853 | | - | |
| 853 | + | |
854 | 854 | | |
855 | 855 | | |
856 | 856 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
562 | 562 | | |
563 | 563 | | |
564 | 564 | | |
565 | | - | |
| 565 | + | |
566 | 566 | | |
567 | 567 | | |
568 | 568 | | |
| |||
1702 | 1702 | | |
1703 | 1703 | | |
1704 | 1704 | | |
1705 | | - | |
| 1705 | + | |
1706 | 1706 | | |
1707 | 1707 | | |
1708 | 1708 | | |
| |||
3087 | 3087 | | |
3088 | 3088 | | |
3089 | 3089 | | |
3090 | | - | |
| 3090 | + | |
3091 | 3091 | | |
3092 | 3092 | | |
3093 | 3093 | | |
| |||
4173 | 4173 | | |
4174 | 4174 | | |
4175 | 4175 | | |
4176 | | - | |
| 4176 | + | |
4177 | 4177 | | |
4178 | 4178 | | |
4179 | 4179 | | |
| |||
4255 | 4255 | | |
4256 | 4256 | | |
4257 | 4257 | | |
4258 | | - | |
| 4258 | + | |
4259 | 4259 | | |
4260 | 4260 | | |
4261 | 4261 | | |
| |||
5468 | 5468 | | |
5469 | 5469 | | |
5470 | 5470 | | |
5471 | | - | |
| 5471 | + | |
5472 | 5472 | | |
5473 | 5473 | | |
5474 | 5474 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3412 | 3412 | | |
3413 | 3413 | | |
3414 | 3414 | | |
3415 | | - | |
| 3415 | + | |
3416 | 3416 | | |
3417 | 3417 | | |
3418 | 3418 | | |
| |||
3434 | 3434 | | |
3435 | 3435 | | |
3436 | 3436 | | |
3437 | | - | |
| 3437 | + | |
3438 | 3438 | | |
3439 | 3439 | | |
3440 | 3440 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
212 | | - | |
| 212 | + | |
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
713 | 713 | | |
714 | 714 | | |
715 | 715 | | |
716 | | - | |
| 716 | + | |
717 | 717 | | |
718 | 718 | | |
719 | 719 | | |
720 | 720 | | |
721 | 721 | | |
722 | 722 | | |
723 | | - | |
| 723 | + | |
724 | 724 | | |
725 | 725 | | |
726 | 726 | | |
| |||
778 | 778 | | |
779 | 779 | | |
780 | 780 | | |
781 | | - | |
| 781 | + | |
782 | 782 | | |
783 | 783 | | |
784 | 784 | | |
| |||
852 | 852 | | |
853 | 853 | | |
854 | 854 | | |
855 | | - | |
| 855 | + | |
856 | 856 | | |
857 | 857 | | |
858 | 858 | | |
| |||
928 | 928 | | |
929 | 929 | | |
930 | 930 | | |
931 | | - | |
| 931 | + | |
932 | 932 | | |
933 | 933 | | |
934 | 934 | | |
| |||
971 | 971 | | |
972 | 972 | | |
973 | 973 | | |
974 | | - | |
| 974 | + | |
975 | 975 | | |
976 | 976 | | |
977 | 977 | | |
| |||
1082 | 1082 | | |
1083 | 1083 | | |
1084 | 1084 | | |
1085 | | - | |
| 1085 | + | |
1086 | 1086 | | |
1087 | 1087 | | |
1088 | 1088 | | |
| |||
1450 | 1450 | | |
1451 | 1451 | | |
1452 | 1452 | | |
1453 | | - | |
| 1453 | + | |
1454 | 1454 | | |
1455 | 1455 | | |
1456 | 1456 | | |
| |||
1549 | 1549 | | |
1550 | 1550 | | |
1551 | 1551 | | |
1552 | | - | |
| 1552 | + | |
1553 | 1553 | | |
1554 | 1554 | | |
1555 | 1555 | | |
| |||
1806 | 1806 | | |
1807 | 1807 | | |
1808 | 1808 | | |
1809 | | - | |
| 1809 | + | |
1810 | 1810 | | |
1811 | 1811 | | |
1812 | 1812 | | |
| |||
1995 | 1995 | | |
1996 | 1996 | | |
1997 | 1997 | | |
1998 | | - | |
| 1998 | + | |
| 1999 | + | |
1999 | 2000 | | |
2000 | 2001 | | |
2001 | 2002 | | |
| |||
2013 | 2014 | | |
2014 | 2015 | | |
2015 | 2016 | | |
2016 | | - | |
| 2017 | + | |
| 2018 | + | |
2017 | 2019 | | |
2018 | 2020 | | |
2019 | 2021 | | |
2020 | 2022 | | |
2021 | | - | |
| 2023 | + | |
2022 | 2024 | | |
2023 | 2025 | | |
2024 | 2026 | | |
| |||
2049 | 2051 | | |
2050 | 2052 | | |
2051 | 2053 | | |
2052 | | - | |
| 2054 | + | |
| 2055 | + | |
2053 | 2056 | | |
2054 | 2057 | | |
2055 | 2058 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
| 85 | + | |
| 86 | + | |
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
| |||
98 | 99 | | |
99 | 100 | | |
100 | 101 | | |
101 | | - | |
| 102 | + | |
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
838 | 838 | | |
839 | 839 | | |
840 | 840 | | |
841 | | - | |
| 841 | + | |
842 | 842 | | |
843 | 843 | | |
844 | 844 | | |
| |||
856 | 856 | | |
857 | 857 | | |
858 | 858 | | |
859 | | - | |
| 859 | + | |
860 | 860 | | |
861 | 861 | | |
862 | 862 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
822 | 822 | | |
823 | 823 | | |
824 | 824 | | |
825 | | - | |
| 825 | + | |
826 | 826 | | |
827 | 827 | | |
828 | 828 | | |
| |||
879 | 879 | | |
880 | 880 | | |
881 | 881 | | |
882 | | - | |
| 882 | + | |
883 | 883 | | |
884 | 884 | | |
885 | 885 | | |
| |||
0 commit comments