external/efibootmgr
Revisão | e42b460e88feb8e0cb6a9c57bce07777b7ff2c7f (tree) |
---|---|
Hora | 2017-03-08 01:07:06 |
Autor | Raymund Will <rw@suse...> |
Commiter | Peter Jones |
efibootmgr: sanitize set/get_mirror()
get_mirror()
- don't short-circuit the assignment of values in case of version mismatch
- move redundant warning (from show_mirror()s PoV) to set_mirror()
- add missing free(data)
set_mirror()
- skip obsolete second assignment of data
- avoid potentially "uninitialized" access to above/below4g by protecting
Note: this will prevent unnecessary write-operations!
Signed-off-by: Raymund Will <rw@suse.com>
@@ -1106,12 +1106,12 @@ get_mirror(int which, int *below4g, int *above4g, int *mirrorstatus) | ||
1106 | 1106 | if (rc == 0) { |
1107 | 1107 | abm = (ADDRESS_RANGE_MIRROR_VARIABLE_DATA *)data; |
1108 | 1108 | if (!which && abm->mirror_version != MIRROR_VERSION) { |
1109 | - warningx("** Warning ** : unrecognised version for memory mirror i/f"); | |
1110 | - return 2; | |
1109 | + rc = 2; | |
1111 | 1110 | } |
1112 | 1111 | *below4g = abm->mirror_memory_below_4gb; |
1113 | 1112 | *above4g = abm->mirror_amount_above_4gb; |
1114 | 1113 | *mirrorstatus = abm->mirror_status; |
1114 | + free(data); | |
1115 | 1115 | } else { |
1116 | 1116 | cond_warning(opts.verbose >= 2, |
1117 | 1117 | "Could not read variable '%s'", name); |
@@ -1130,14 +1130,19 @@ set_mirror(int below4g, int above4g) | ||
1130 | 1130 | uint32_t attributes; |
1131 | 1131 | int oldbelow4g, oldabove4g; |
1132 | 1132 | |
1133 | - if ((s = get_mirror(0, &oldbelow4g, &oldabove4g, &status)) == 0) { | |
1134 | - if (oldbelow4g == below4g && oldabove4g == above4g) | |
1135 | - return 0; | |
1136 | - } else { | |
1137 | - warningx("** Warning ** : platform does not support memory mirror"); | |
1133 | + if ((s = get_mirror(0, &oldbelow4g, &oldabove4g, &status)) != 0) { | |
1134 | + if (s == 2) | |
1135 | + warningx("** Warning ** : unrecognised version for memory mirror i/f"); | |
1136 | + else | |
1137 | + warningx("** Warning ** : platform does not support memory mirror"); | |
1138 | 1138 | return s; |
1139 | 1139 | } |
1140 | 1140 | |
1141 | + below4g = opts.set_mirror_lo ? below4g : oldbelow4g; | |
1142 | + above4g = opts.set_mirror_hi ? above4g : oldabove4g; | |
1143 | + if (oldbelow4g == below4g && oldabove4g == above4g) | |
1144 | + return 0; | |
1145 | + | |
1141 | 1146 | data = (uint8_t *)&abm; |
1142 | 1147 | data_size = sizeof (abm); |
1143 | 1148 | attributes = EFI_VARIABLE_NON_VOLATILE |
@@ -1145,10 +1150,9 @@ set_mirror(int below4g, int above4g) | ||
1145 | 1150 | | EFI_VARIABLE_RUNTIME_ACCESS; |
1146 | 1151 | |
1147 | 1152 | abm.mirror_version = MIRROR_VERSION; |
1148 | - abm.mirror_amount_above_4gb = opts.set_mirror_hi ? above4g : oldabove4g; | |
1149 | - abm.mirror_memory_below_4gb = opts.set_mirror_lo ? below4g : oldbelow4g; | |
1153 | + abm.mirror_amount_above_4gb = above4g; | |
1154 | + abm.mirror_memory_below_4gb = below4g; | |
1150 | 1155 | abm.mirror_status = 0; |
1151 | - data = (uint8_t *)&abm; | |
1152 | 1156 | rc = efi_set_variable(ADDRESS_RANGE_MIRROR_VARIABLE_GUID, |
1153 | 1157 | ADDRESS_RANGE_MIRROR_VARIABLE_REQUEST, data, |
1154 | 1158 | data_size, attributes, 0644); |