Page MenuHomeFreeBSD

partedit: Check allocated strings for UFS auto partitioning
Needs ReviewPublic

Authored by asiciliano on May 1 2022, 3:15 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, May 8, 11:39 PM
Unknown Object (File)
Apr 11 2024, 8:03 AM
Unknown Object (File)
Dec 22 2023, 11:37 PM
Unknown Object (File)
Dec 17 2023, 4:31 AM
Unknown Object (File)
Aug 28 2023, 8:50 PM
Unknown Object (File)
Jun 30 2023, 5:05 PM
Unknown Object (File)
Jun 29 2023, 7:37 AM
Unknown Object (File)
Jun 5 2023, 4:01 PM
Subscribers
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

After this commit "bsdinstall/partedit: Fix UFS auto partitioning" https://cgit.freebsd.org/src/commit/?id=9b4c606b96ce8a8b011dc50295c71c38741a0f4f

+	} else { /* auto partitioning */
+		items[0].value = strdup(items[0].init);
+		items[1].value = strdup(items[1].init);
+		items[2].value = strdup(items[2].init);
+		if (nitems > 3)
+			items[3].value = strdup(items[3].init);
 	}

a report suggests to check the output of strdup() https://lists.freebsd.org/archives/dev-commits-src-main/2022-April/006059.html

Maybe it could be a bit superfluous in this context, I opened this review to discuss and to get tips.
Briefly, a possible error could be an extreme case: memory full with useful data in a critical memory environment, no some naughty or huge string.

Rationale:
Currently partedit does not check the output of strdup(), probably because the size of the strings is fixed and the TUI libraries guarantee strings with limited size, usually max 16 characters. The user is not allowed to input a string of arbitrary length.

In the reported commit, the allocated strings are not "indefinite", they are almost-constants: "freebsd-[ufs|swap]", "nnn GB", "/|none", "", so the allocated memory is less than 30 bytes. It is much less than the memory required by the dialog form in the interactive case (the flow goes into the if instead of } else { /* auto partitioning */).

Anyway, let' s say we add a check (pseudocode):

// really it is (forms.value = strdup("freebsd-ufs") == NULL)
if ((items[0].value = strdup(items[0].init))== NULL)
	return;
/* ... etc ... */

If we have not 30 bytes available the partitioner will fail an instant later the "return" probably building a new dialog, each dialog/widget requires much more allocated memory than 30 bytes. Surely it will be impossible to rebuild [*] the main menu for the partition table.

Even it would not be possible to build a simple dialog msgbox to warn the user:

if (form.value = strdup("freebsd-ufs") == NULL) {
	bsddialog_msgbox(&conf, Error: Impossible to allocate 30 bytes, 0, 0);
	return;
}

\[*] Probably in this critical memory environment partedit and bsdinstall are not able to start.

However, I have not a strong opinion, if others confirm the necessity I' ll add the check. Of course, everybody can open a review to propose a better solution/idea.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

asiciliano retitled this revision from partedit: Check allocated strings for autosizing to partedit: Check allocated strings for UFS auto partitioning.May 2 2022, 2:42 AM