Commit 1d9ed2e
committed
file/config_file: reject non-numeric input in integer getters
config_get_int(), config_get_uint(), config_get_uint64() and
config_get_hex() all used this pattern:
errno = 0;
val = strtol(entry->value, NULL, 0);
if (errno == 0) {
*in = val;
return true;
}
strtol returns 0 (without setting errno) when handed a string that
has no leading digits at all -- so a config line like
width = abc
silently produced width = 0 and the getter reported success. The
user sees the setting "accepted" with a bogus value and no way to
tell anything went wrong. config_get_size_t() in the same file
already used the correct pattern; this patch applies it to the
other four.
Each fixed getter now:
- captures the end pointer from strtol/strtoul/strtoull
- rejects if errno was set (overflow)
- rejects if zero digits were consumed (end == entry->value)
- rejects if trailing garbage remains (*end != '\0')
- for config_get_int / config_get_uint / config_get_hex, also
rejects values outside the destination type's range (strtol
on 64-bit systems returns a 64-bit long that must fit in int)
Behavioural change: values that previously silently became zero
now return false and leave *in untouched. This matches the
documented "@return true if found, otherwise false" contract in
config_file.h -- the prior behaviour violated it by returning true
for not-a-number strings. Callers that relied on the bogus zero
were already silently broken; they now get explicit failure and
can fall back to a default.1 parent e044ef6 commit 1d9ed2e
4 files changed
Lines changed: 585 additions & 28 deletions
File tree
- libretro-common
- file
- samples/file
- archive_file
- config_file
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
963 | 964 | | |
964 | 965 | | |
965 | 966 | | |
966 | | - | |
967 | 967 | | |
968 | 968 | | |
969 | 969 | | |
970 | | - | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
971 | 974 | | |
972 | | - | |
973 | | - | |
974 | | - | |
975 | | - | |
976 | | - | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
977 | 983 | | |
978 | 984 | | |
979 | 985 | | |
| |||
1009 | 1015 | | |
1010 | 1016 | | |
1011 | 1017 | | |
1012 | | - | |
1013 | 1018 | | |
1014 | 1019 | | |
1015 | 1020 | | |
1016 | | - | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
1017 | 1025 | | |
1018 | | - | |
1019 | | - | |
1020 | | - | |
1021 | | - | |
1022 | | - | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
1023 | 1031 | | |
1024 | 1032 | | |
1025 | 1033 | | |
| |||
1028 | 1036 | | |
1029 | 1037 | | |
1030 | 1038 | | |
1031 | | - | |
1032 | 1039 | | |
1033 | 1040 | | |
1034 | 1041 | | |
1035 | | - | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
1036 | 1046 | | |
1037 | | - | |
1038 | | - | |
1039 | | - | |
1040 | | - | |
1041 | | - | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
1042 | 1055 | | |
1043 | 1056 | | |
1044 | 1057 | | |
| |||
1047 | 1060 | | |
1048 | 1061 | | |
1049 | 1062 | | |
1050 | | - | |
1051 | 1063 | | |
1052 | 1064 | | |
1053 | 1065 | | |
1054 | | - | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
1055 | 1070 | | |
1056 | | - | |
1057 | | - | |
1058 | | - | |
1059 | | - | |
1060 | | - | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
1061 | 1079 | | |
1062 | 1080 | | |
1063 | 1081 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
0 commit comments