aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorChong Yidong2012-05-02 21:06:08 +0800
committerChong Yidong2012-05-02 21:06:08 +0800
commit687d464f5c60cfe135436dab3dc29620ea8d1f95 (patch)
treecfb029be2384fa7d42125e4048c7b3768bc04951 /lib-src
parentc635b6d5458afe1e86f044a407a0331ee75dc816 (diff)
downloademacs-687d464f5c60cfe135436dab3dc29620ea8d1f95.tar.gz
emacs-687d464f5c60cfe135436dab3dc29620ea8d1f95.zip
Backport Bug#11374 fix from trunk
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/ChangeLog5
-rw-r--r--lib-src/emacsclient.c40
2 files changed, 26 insertions, 19 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog
index 8e07193ae0c..90fd722141b 100644
--- a/lib-src/ChangeLog
+++ b/lib-src/ChangeLog
@@ -1,4 +1,7 @@
12012-05-02 Jim Meyering <meyering@redhat.com> 12012-05-02 Jim Meyering <jim@meyering.net>
2
3 * emacsclient.c (send_to_emacs): Avoid invalid strcpy upon partial
4 send (Bug#11374).
2 5
3 * lib-src/pop.c (pop_stat, pop_list, pop_multi_first, pop_last): 6 * lib-src/pop.c (pop_stat, pop_list, pop_multi_first, pop_last):
4 NUL-terminate the error buffer (Bug#11372). 7 NUL-terminate the error buffer (Bug#11372).
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index 48b4384d487..931f6d10c5c 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -119,6 +119,8 @@ char *(getcwd) (char *, size_t);
119# define IF_LINT(Code) /* empty */ 119# define IF_LINT(Code) /* empty */
120#endif 120#endif
121 121
122#define min(x, y) (((x) < (y)) ? (x) : (y))
123
122 124
123/* Name used to invoke this program. */ 125/* Name used to invoke this program. */
124const char *progname; 126const char *progname;
@@ -783,33 +785,35 @@ sock_err_message (const char *function_name)
783static void 785static void
784send_to_emacs (HSOCKET s, const char *data) 786send_to_emacs (HSOCKET s, const char *data)
785{ 787{
786 while (data) 788 size_t dlen;
789
790 if (!data)
791 return;
792
793 dlen = strlen (data);
794 while (*data)
787 { 795 {
788 size_t dlen = strlen (data); 796 size_t part = min (dlen, SEND_BUFFER_SIZE - sblen);
789 if (dlen + sblen >= SEND_BUFFER_SIZE) 797 memcpy (&send_buffer[sblen], data, part);
790 { 798 data += part;
791 int part = SEND_BUFFER_SIZE - sblen; 799 sblen += part;
792 strncpy (&send_buffer[sblen], data, part);
793 data += part;
794 sblen = SEND_BUFFER_SIZE;
795 }
796 else if (dlen)
797 {
798 strcpy (&send_buffer[sblen], data);
799 data = NULL;
800 sblen += dlen;
801 }
802 else
803 break;
804 800
805 if (sblen == SEND_BUFFER_SIZE 801 if (sblen == SEND_BUFFER_SIZE
806 || (sblen > 0 && send_buffer[sblen-1] == '\n')) 802 || (sblen > 0 && send_buffer[sblen-1] == '\n'))
807 { 803 {
808 int sent = send (s, send_buffer, sblen, 0); 804 int sent = send (s, send_buffer, sblen, 0);
805 if (sent < 0)
806 {
807 message (TRUE, "%s: failed to send %d bytes to socket: %s\n",
808 progname, sblen, strerror (errno));
809 fail ();
810 }
809 if (sent != sblen) 811 if (sent != sblen)
810 strcpy (send_buffer, &send_buffer[sent]); 812 memmove (send_buffer, &send_buffer[sent], sblen - sent);
811 sblen -= sent; 813 sblen -= sent;
812 } 814 }
815
816 dlen -= part;
813 } 817 }
814} 818}
815 819