aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJoakim Verona2013-08-24 04:36:40 +0200
committerJoakim Verona2013-08-24 04:36:40 +0200
commit202cca22fe9e2451a8d3cabe0c443ba985289503 (patch)
treee81f63d5a3a578ef23839b43b071854d015613a8 /src
parent4bd3d0459af0b4c8ec3128d0d0d67ff2cbc2750d (diff)
parent9c05bccfb9cd29ab66b5c46643467671315a0f29 (diff)
downloademacs-202cca22fe9e2451a8d3cabe0c443ba985289503.tar.gz
emacs-202cca22fe9e2451a8d3cabe0c443ba985289503.zip
merge from trunk
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog16
-rw-r--r--src/process.c13
-rw-r--r--src/sysdep.c55
3 files changed, 55 insertions, 29 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 73fdb0221ce..3eccf6ff557 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,19 @@
12013-08-24 Paul Eggert <eggert@cs.ucla.edu>
2
3 System-dependent integer overflow fixes.
4 * process.c (Fset_process_window_size): Signal an error if
5 the window size is outside the range supported by the lower level.
6 * sysdep.c (set_window_size): Return negative on error,
7 nonnegative on success, rather than -1, 0, 1 on not in system,
8 failure, success. This is simpler. Caller changed.
9 (serial_configure): Remove unnecessary initialization of local.
10 (procfs_get_total_memory) [GNU_LINUX]: Don't assume system memory
11 size fits in unsigned long; this isn't true on some 32-bit hosts.
12 Avoid buffer overrun if some future version of /proc/meminfo has a
13 variable name longer than 20 bytes.
14 (system_process_attributes) [__FreeBSD__]:
15 Don't assume hw.availpages fits in 'int'.
16
12013-08-23 Paul Eggert <eggert@cs.ucla.edu> 172013-08-23 Paul Eggert <eggert@cs.ucla.edu>
2 18
3 Don't let very long directory names overrun the stack. 19 Don't let very long directory names overrun the stack.
diff --git a/src/process.c b/src/process.c
index ea1129ffbb8..c5e691bf602 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1140,15 +1140,18 @@ See `set-process-sentinel' for more info on sentinels. */)
1140DEFUN ("set-process-window-size", Fset_process_window_size, 1140DEFUN ("set-process-window-size", Fset_process_window_size,
1141 Sset_process_window_size, 3, 3, 0, 1141 Sset_process_window_size, 3, 3, 0,
1142 doc: /* Tell PROCESS that it has logical window size HEIGHT and WIDTH. */) 1142 doc: /* Tell PROCESS that it has logical window size HEIGHT and WIDTH. */)
1143 (register Lisp_Object process, Lisp_Object height, Lisp_Object width) 1143 (Lisp_Object process, Lisp_Object height, Lisp_Object width)
1144{ 1144{
1145 CHECK_PROCESS (process); 1145 CHECK_PROCESS (process);
1146 CHECK_RANGED_INTEGER (height, 0, INT_MAX); 1146
1147 CHECK_RANGED_INTEGER (width, 0, INT_MAX); 1147 /* All known platforms store window sizes as 'unsigned short'. */
1148 CHECK_RANGED_INTEGER (height, 0, USHRT_MAX);
1149 CHECK_RANGED_INTEGER (width, 0, USHRT_MAX);
1148 1150
1149 if (XPROCESS (process)->infd < 0 1151 if (XPROCESS (process)->infd < 0
1150 || set_window_size (XPROCESS (process)->infd, 1152 || (set_window_size (XPROCESS (process)->infd,
1151 XINT (height), XINT (width)) <= 0) 1153 XINT (height), XINT (width))
1154 < 0))
1152 return Qnil; 1155 return Qnil;
1153 else 1156 else
1154 return Qt; 1157 return Qt;
diff --git a/src/sysdep.c b/src/sysdep.c
index c6d5f9942ab..0d732526528 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -1170,7 +1170,8 @@ get_tty_size (int fd, int *widthp, int *heightp)
1170} 1170}
1171 1171
1172/* Set the logical window size associated with descriptor FD 1172/* Set the logical window size associated with descriptor FD
1173 to HEIGHT and WIDTH. This is used mainly with ptys. */ 1173 to HEIGHT and WIDTH. This is used mainly with ptys.
1174 Return a negative value on failure. */
1174 1175
1175int 1176int
1176set_window_size (int fd, int height, int width) 1177set_window_size (int fd, int height, int width)
@@ -1182,10 +1183,7 @@ set_window_size (int fd, int height, int width)
1182 size.ws_row = height; 1183 size.ws_row = height;
1183 size.ws_col = width; 1184 size.ws_col = width;
1184 1185
1185 if (ioctl (fd, TIOCSWINSZ, &size) == -1) 1186 return ioctl (fd, TIOCSWINSZ, &size);
1186 return 0; /* error */
1187 else
1188 return 1;
1189 1187
1190#else 1188#else
1191#ifdef TIOCSSIZE 1189#ifdef TIOCSSIZE
@@ -1195,10 +1193,7 @@ set_window_size (int fd, int height, int width)
1195 size.ts_lines = height; 1193 size.ts_lines = height;
1196 size.ts_cols = width; 1194 size.ts_cols = width;
1197 1195
1198 if (ioctl (fd, TIOCGSIZE, &size) == -1) 1196 return ioctl (fd, TIOCGSIZE, &size);
1199 return 0;
1200 else
1201 return 1;
1202#else 1197#else
1203 return -1; 1198 return -1;
1204#endif /* not SunOS-style */ 1199#endif /* not SunOS-style */
@@ -2459,7 +2454,7 @@ serial_configure (struct Lisp_Process *p,
2459 Lisp_Object childp2 = Qnil; 2454 Lisp_Object childp2 = Qnil;
2460 Lisp_Object tem = Qnil; 2455 Lisp_Object tem = Qnil;
2461 struct termios attr; 2456 struct termios attr;
2462 int err = -1; 2457 int err;
2463 char summary[4] = "???"; /* This usually becomes "8N1". */ 2458 char summary[4] = "???"; /* This usually becomes "8N1". */
2464 2459
2465 childp2 = Fcopy_sequence (p->childp); 2460 childp2 = Fcopy_sequence (p->childp);
@@ -2826,29 +2821,41 @@ procfs_ttyname (int rdev)
2826 return build_string (name); 2821 return build_string (name);
2827} 2822}
2828 2823
2829static unsigned long 2824static uintmax_t
2830procfs_get_total_memory (void) 2825procfs_get_total_memory (void)
2831{ 2826{
2832 FILE *fmem; 2827 FILE *fmem;
2833 unsigned long retval = 2 * 1024 * 1024; /* default: 2GB */ 2828 uintmax_t retval = 2 * 1024 * 1024; /* default: 2 GiB */
2829 int c;
2834 2830
2835 block_input (); 2831 block_input ();
2836 fmem = emacs_fopen ("/proc/meminfo", "r"); 2832 fmem = emacs_fopen ("/proc/meminfo", "r");
2837 2833
2838 if (fmem) 2834 if (fmem)
2839 { 2835 {
2840 unsigned long entry_value; 2836 uintmax_t entry_value;
2841 char entry_name[20]; /* the longest I saw is 13+1 */ 2837 bool done;
2838
2839 do
2840 switch (fscanf (fmem, "MemTotal: %"SCNuMAX, &entry_value))
2841 {
2842 case 1:
2843 retval = entry_value;
2844 done = 1;
2845 break;
2846
2847 case 0:
2848 while ((c = getc (fmem)) != EOF && c != '\n')
2849 continue;
2850 done = c == EOF;
2851 break;
2852
2853 default:
2854 done = 1;
2855 break;
2856 }
2857 while (!done);
2842 2858
2843 while (!feof (fmem) && !ferror (fmem))
2844 {
2845 if (fscanf (fmem, "%s %lu kB\n", entry_name, &entry_value) >= 2
2846 && strcmp (entry_name, "MemTotal:") == 0)
2847 {
2848 retval = entry_value;
2849 break;
2850 }
2851 }
2852 fclose (fmem); 2859 fclose (fmem);
2853 } 2860 }
2854 unblock_input (); 2861 unblock_input ();
@@ -3249,7 +3256,7 @@ system_process_attributes (Lisp_Object pid)
3249{ 3256{
3250 int proc_id; 3257 int proc_id;
3251 int pagesize = getpagesize (); 3258 int pagesize = getpagesize ();
3252 int npages; 3259 unsigned long npages;
3253 int fscale; 3260 int fscale;
3254 struct passwd *pw; 3261 struct passwd *pw;
3255 struct group *gr; 3262 struct group *gr;