unix.c (PRS): Validate the completion information file descriptor so
that the completion bar won't get accidentally written onto the disk.
2001-05-01 Theodore Tso <tytso@valinux.com>
+ * unix.c (PRS): Validate the completion information file
+ descriptor so that the completion bar won't get
+ accidentally written onto the disk.
+
* e2fsck.8.in: Add explanation that you can use mke2fs -n -b
blocksize to printout alternate superblock locations.
static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
{
int flush = 0;
- int c;
+ int c, fd;
#ifdef MTRACE
extern void *mallwatch;
#endif
case 'C':
ctx->progress = e2fsck_update_progress;
ctx->progress_fd = atoi(optarg);
+ /* Validate the file descriptor to avoid disasters */
+ fd = dup(ctx->progress_fd);
+ if (fd < 0) {
+ fprintf(stderr,
+ _("Error validating file descriptor %d: %s\n"),
+ ctx->progress_fd,
+ error_message(errno));
+ fatal_error(ctx,
+ _("Invalid completion information file descriptor"));
+ } else
+ close(fd);
break;
case 'p':
case 'a':