]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
unix: do not close stdin in grub_passwd_get
authorAndrei Borzenkov <arvidjaar@gmail.com>
Wed, 18 Nov 2015 19:23:58 +0000 (22:23 +0300)
committerAndrei Borzenkov <arvidjaar@gmail.com>
Wed, 18 Nov 2015 19:23:58 +0000 (22:23 +0300)
This makes it impossible to read from stdin without controlling tty:

10:/mnt # echo -e passwd\\npasswd | setsid ./grub-mkpasswd-pbkdf2
Enter password:
Reenter password: ./grub-mkpasswd-pbkdf2: error: failure to read password.
10:/mnt

grub-core/osdep/unix/password.c

index 4b9507bce94d4090e3404364847821cc9d86dffa..9996b244b6b6c8005289bb3cdd30432638535cb3 100644 (file)
@@ -54,7 +54,8 @@ grub_password_get (char buf[], unsigned buf_size)
   grub_memset (buf, 0, buf_size);
   if (!fgets (buf, buf_size, stdin))
     {
-      fclose (in);
+      if (in != stdin)
+       fclose (in);
       return 0;
     }
   ptr = buf + strlen (buf) - 1;
@@ -67,7 +68,8 @@ grub_password_get (char buf[], unsigned buf_size)
   grub_xputs ("\n");
   grub_refresh ();
 
-  fclose (in);
+  if (in != stdin)
+    fclose (in);
 
   return 1;
 }