Skip to content

Commit bd169c2

Browse files
poetteringkeszybz
authored andcommitted
fsck: copy out device argument from argv[] before forking
We nowadays rename our child processes, hence argv[] will be clobbered, let's hence copy the device path to dynamic memory before forking. This is fall-out from 60ffa37 since we now a lot more often end up overriding the argv[] buffer than before, simple because we know what to override. These kind of bugs kinda suck. THere are only two options here: stop overriding argv[] for all cases (or just these cases) or explicitly copying out everything we need in child processes before forking. With this patch I opt for the latter, though I am not 100% convinced this is a great solution. Just a better solution than everything else, i.e. allowing argv[] to remain out of sync with what others see. Fixes: systemd#12135
1 parent 7232c1f commit bd169c2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/fsck/fsck.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ static int fsck_progress_socket(void) {
265265
static int run(int argc, char *argv[]) {
266266
_cleanup_close_pair_ int progress_pipe[2] = { -1, -1 };
267267
_cleanup_(sd_device_unrefp) sd_device *dev = NULL;
268+
_cleanup_free_ char *dpath = NULL;
268269
const char *device, *type;
269270
bool root_directory;
270271
struct stat st;
@@ -290,7 +291,11 @@ static int run(int argc, char *argv[]) {
290291
return 0;
291292

292293
if (argc > 1) {
293-
device = argv[1];
294+
dpath = strdup(argv[1]);
295+
if (!dpath)
296+
return log_oom();
297+
298+
device = dpath;
294299

295300
if (stat(device, &st) < 0)
296301
return log_error_errno(errno, "Failed to stat %s: %m", device);

0 commit comments

Comments
 (0)