From: Paul Eggert Date: Mon, 18 Jul 2011 21:08:22 +0000 (-0700) Subject: * fileio.c: Integer overflow issues with file modes. X-Git-Tag: emacs-pretest-24.0.90~104^2~152^2~140 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=18c525570121d8d3df377f85ec5b6f44fe39524a;p=emacs.git * fileio.c: Integer overflow issues with file modes. (Fset_file_modes, auto_save_1): Don't assume EMACS_INT fits in int. --- diff --git a/src/ChangeLog b/src/ChangeLog index 869e2637cf4..c516a346a89 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,8 @@ 2011-07-18 Paul Eggert + * fileio.c: Integer overflow issues with file modes. + (Fset_file_modes, auto_save_1): Don't assume EMACS_INT fits in int. + * charset.c (read_hex): New arg OVERFLOW. All uses changed. Remove unreachable code. (read_hex, load_charset_map_from_file): Check for integer overflow. diff --git a/src/fileio.c b/src/fileio.c index bdea302a0d6..af11e927059 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -2893,7 +2893,7 @@ symbolic notation, like the `chmod' command from GNU Coreutils. */) encoded_absname = ENCODE_FILE (absname); - if (chmod (SSDATA (encoded_absname), XINT (mode)) < 0) + if (chmod (SSDATA (encoded_absname), XINT (mode) & 07777) < 0) report_file_error ("Doing chmod", Fcons (absname, Qnil)); return Qnil; @@ -5095,11 +5095,11 @@ auto_save_1 (void) { if (stat (SSDATA (BVAR (current_buffer, filename)), &st) >= 0) /* But make sure we can overwrite it later! */ - auto_save_mode_bits = st.st_mode | 0600; + auto_save_mode_bits = (st.st_mode | 0600) & 0777; else if ((modes = Ffile_modes (BVAR (current_buffer, filename)), INTEGERP (modes))) /* Remote files don't cooperate with stat. */ - auto_save_mode_bits = XINT (modes) | 0600; + auto_save_mode_bits = (XINT (modes) | 0600) & 0777; } return