• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得cocoawindowspythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdombtronvb.netdirectxarduinopreviewerゲームエンジン

external/efibootmgr


Commit MetaInfo

Revisione42b460e88feb8e0cb6a9c57bce07777b7ff2c7f (tree)
Zeit2017-03-08 01:07:06
AutorRaymund Will <rw@suse...>
CommiterPeter Jones

Log Message

efibootmgr: sanitize set/get_mirror()

get_mirror()
- don't short-circuit the assignment of values in case of version mismatch

as show_mirror() happily tries to use them nevertheless

- 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

it with opts.set_mirror_hi/_lo respectively, thus simplifying the code
down the line

Note: this will prevent unnecessary write-operations!

Signed-off-by: Raymund Will <rw@suse.com>

Ändern Zusammenfassung

Diff

--- a/src/efibootmgr.c
+++ b/src/efibootmgr.c
@@ -1106,12 +1106,12 @@ get_mirror(int which, int *below4g, int *above4g, int *mirrorstatus)
11061106 if (rc == 0) {
11071107 abm = (ADDRESS_RANGE_MIRROR_VARIABLE_DATA *)data;
11081108 if (!which && abm->mirror_version != MIRROR_VERSION) {
1109- warningx("** Warning ** : unrecognised version for memory mirror i/f");
1110- return 2;
1109+ rc = 2;
11111110 }
11121111 *below4g = abm->mirror_memory_below_4gb;
11131112 *above4g = abm->mirror_amount_above_4gb;
11141113 *mirrorstatus = abm->mirror_status;
1114+ free(data);
11151115 } else {
11161116 cond_warning(opts.verbose >= 2,
11171117 "Could not read variable '%s'", name);
@@ -1130,14 +1130,19 @@ set_mirror(int below4g, int above4g)
11301130 uint32_t attributes;
11311131 int oldbelow4g, oldabove4g;
11321132
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");
11381138 return s;
11391139 }
11401140
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+
11411146 data = (uint8_t *)&abm;
11421147 data_size = sizeof (abm);
11431148 attributes = EFI_VARIABLE_NON_VOLATILE
@@ -1145,10 +1150,9 @@ set_mirror(int below4g, int above4g)
11451150 | EFI_VARIABLE_RUNTIME_ACCESS;
11461151
11471152 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;
11501155 abm.mirror_status = 0;
1151- data = (uint8_t *)&abm;
11521156 rc = efi_set_variable(ADDRESS_RANGE_MIRROR_VARIABLE_GUID,
11531157 ADDRESS_RANGE_MIRROR_VARIABLE_REQUEST, data,
11541158 data_size, attributes, 0644);