From 18c525570121d8d3df377f85ec5b6f44fe39524a Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 18 Jul 2011 14:08:22 -0700 Subject: [PATCH] * fileio.c: Integer overflow issues with file modes. (Fset_file_modes, auto_save_1): Don't assume EMACS_INT fits in int. --- src/ChangeLog | 3 +++ src/fileio.c | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) 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 -- 2.39.2