Whamcloud - gitweb
ChangeLog, unix.c:
authorTheodore Ts'o <tytso@mit.edu>
Tue, 1 May 2001 21:13:37 +0000 (21:13 +0000)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 1 May 2001 21:13:37 +0000 (21:13 +0000)
  unix.c (PRS): Validate the completion information file descriptor so
   that the completion bar won't get accidentally written onto the disk.

e2fsck/ChangeLog
e2fsck/unix.c

index 946de76..084a604 100644 (file)
@@ -1,5 +1,9 @@
 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.
 
index b81a00b..675bb90 100644 (file)
@@ -438,7 +438,7 @@ static void signal_progress_off(int sig)
 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
@@ -483,6 +483,17 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
                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':