CVS: rdesktop disk.c, 1.62, 1.63 printercache.c, 1.11, 1.12 proto.h, 1.109, 1.110 rdesktop.c, 1.161, 1.162 rdp.c, 1.101, 1.102 rdpdr.c, 1.52, 1.53

Matt Chapman <[email protected]> Fri, 04 Jan 2008 21:43:05 -0800
Newsgroups gmane.network.rdesktop.cvs
Message-ID <[email protected]>
Update of /cvsroot/rdesktop/rdesktop
In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv7265

Modified Files:
	disk.c printercache.c proto.h rdesktop.c rdp.c rdpdr.c 
Log Message:
Add some more warnings and sanity checks.


Index: disk.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/disk.c,v
retrieving revision 1.62
retrieving revision 1.63
diff -C2 -d -r1.62 -r1.63
*** disk.c	10 Apr 2007 11:22:10 -0000	1.62
--- disk.c	5 Jan 2008 05:43:02 -0000	1.63
***************
*** 803,807 ****
  			if (length && (length / 2) < 256)
  			{
! 				rdp_in_unistr(in, newname, length);
  				convert_to_unix_filename(newname);
  			}
--- 803,807 ----
  			if (length && (length / 2) < 256)
  			{
! 				rdp_in_unistr(in, newname, sizeof(newname), length);
  				convert_to_unix_filename(newname);
  			}

Index: printercache.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/printercache.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** printercache.c	8 Jan 2007 04:47:05 -0000	1.11
--- printercache.c	5 Jan 2008 05:43:02 -0000	1.12
***************
*** 246,251 ****
  			/* NOTE - 'driver' doesn't contain driver, it contains the new printer name */
  
! 			rdp_in_unistr(s, printer, printer_length);
! 			rdp_in_unistr(s, driver, driver_length);
  
  			printercache_rename_blob(printer, driver);
--- 246,251 ----
  			/* NOTE - 'driver' doesn't contain driver, it contains the new printer name */
  
! 			rdp_in_unistr(s, printer, sizeof(printer), printer_length);
! 			rdp_in_unistr(s, driver, sizeof(driver), driver_length);
  
  			printercache_rename_blob(printer, driver);
***************
*** 255,259 ****
  			in_uint8(s, printer_unicode_length);
  			in_uint8s(s, 0x3);	/* padding */
! 			printer_length = rdp_in_unistr(s, printer, printer_unicode_length);
  			printercache_unlink_blob(printer);
  			break;
--- 255,259 ----
  			in_uint8(s, printer_unicode_length);
  			in_uint8s(s, 0x3);	/* padding */
! 			rdp_in_unistr(s, printer, sizeof(printer), printer_unicode_length);
  			printercache_unlink_blob(printer);
  			break;
***************
*** 265,269 ****
  			if (printer_unicode_length < 2 * 255)
  			{
! 				rdp_in_unistr(s, printer, printer_unicode_length);
  				printercache_save_blob(printer, s->p, blob_length);
  			}
--- 265,269 ----
  			if (printer_unicode_length < 2 * 255)
  			{
! 				rdp_in_unistr(s, printer, sizeof(printer), printer_unicode_length);
  				printercache_save_blob(printer, s->p, blob_length);
  			}

Index: proto.h
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/proto.h,v
retrieving revision 1.109
retrieving revision 1.110
diff -C2 -d -r1.109 -r1.110
*** proto.h	18 Jun 2007 12:00:33 -0000	1.109
--- proto.h	5 Jan 2008 05:43:02 -0000	1.110
***************
*** 112,116 ****
  void exit_if_null(void *ptr);
  char *xstrdup(const char *s);
! void *xrealloc(void *oldmem, int size);
  void xfree(void *mem);
  void error(char *format, ...);
--- 112,116 ----
  void exit_if_null(void *ptr);
  char *xstrdup(const char *s);
! void *xrealloc(void *oldmem, size_t size);
  void xfree(void *mem);
  void error(char *format, ...);
***************
*** 138,142 ****
  /* rdp.c */
  void rdp_out_unistr(STREAM s, char *string, int len);
! int rdp_in_unistr(STREAM s, char *string, int uni_len);
  void rdp_send_input(uint32 time, uint16 message_type, uint16 device_flags, uint16 param1,
  		    uint16 param2);
--- 138,142 ----
  /* rdp.c */
  void rdp_out_unistr(STREAM s, char *string, int len);
! int rdp_in_unistr(STREAM s, char *string, int str_len, int in_len);
  void rdp_send_input(uint32 time, uint16 message_type, uint16 device_flags, uint16 param1,
  		    uint16 param2);

Index: rdesktop.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/rdesktop.c,v
retrieving revision 1.161
retrieving revision 1.162
diff -C2 -d -r1.161 -r1.162
*** rdesktop.c	30 Aug 2007 04:47:36 -0000	1.161
--- rdesktop.c	5 Jan 2008 05:43:02 -0000	1.162
***************
*** 1132,1145 ****
  /* realloc; exit if out of memory */
  void *
! xrealloc(void *oldmem, int size)
  {
  	void *mem;
  
! 	if (size < 1)
  		size = 1;
  	mem = realloc(oldmem, size);
  	if (mem == NULL)
  	{
! 		error("xrealloc %d\n", size);
  		exit(1);
  	}
--- 1132,1145 ----
  /* realloc; exit if out of memory */
  void *
! xrealloc(void *oldmem, size_t size)
  {
  	void *mem;
  
! 	if (size == 0)
  		size = 1;
  	mem = realloc(oldmem, size);
  	if (mem == NULL)
  	{
! 		error("xrealloc %ld\n", size);
  		exit(1);
  	}

Index: rdp.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/rdp.c,v
retrieving revision 1.101
retrieving revision 1.102
diff -C2 -d -r1.101 -r1.102
*** rdp.c	23 Dec 2007 07:07:50 -0000	1.101
--- rdp.c	5 Jan 2008 05:43:02 -0000	1.102
***************
*** 244,251 ****
   */
  int
! rdp_in_unistr(STREAM s, char *string, int uni_len)
  {
  #ifdef HAVE_ICONV
! 	size_t ibl = uni_len, obl = uni_len;
  	char *pin = (char *) s->p, *pout = string;
  	static iconv_t iconv_h = (iconv_t) - 1;
--- 244,251 ----
   */
  int
! rdp_in_unistr(STREAM s, char *string, int str_size, int in_len)
  {
  #ifdef HAVE_ICONV
! 	size_t ibl = in_len, obl = str_size-1;
  	char *pin = (char *) s->p, *pout = string;
  	static iconv_t iconv_h = (iconv_t) - 1;
***************
*** 261,265 ****
  
  				g_iconv_works = False;
! 				return rdp_in_unistr(s, string, uni_len);
  			}
  		}
--- 261,265 ----
  
  				g_iconv_works = False;
! 				return rdp_in_unistr(s, string, str_size, in_len);
  			}
  		}
***************
*** 267,281 ****
  		if (iconv(iconv_h, (ICONV_CONST char **) &pin, &ibl, &pout, &obl) == (size_t) - 1)
  		{
! 			iconv_close(iconv_h);
! 			iconv_h = (iconv_t) - 1;
! 			warning("rdp_in_unistr: iconv fail, errno %d\n", errno);
  
! 			g_iconv_works = False;
! 			return rdp_in_unistr(s, string, uni_len);
  		}
  
  		/* we must update the location of the current STREAM for future reads of s->p */
! 		s->p += uni_len;
  
  		return pout - string;
  	}
--- 267,289 ----
  		if (iconv(iconv_h, (ICONV_CONST char **) &pin, &ibl, &pout, &obl) == (size_t) - 1)
  		{
! 			if (errno == E2BIG)
! 			{
! 				warning("server sent an unexpectedly long string, truncating\n");
! 			}
! 			else
! 			{
! 				iconv_close(iconv_h);
! 				iconv_h = (iconv_t) - 1;
! 				warning("rdp_in_unistr: iconv fail, errno %d\n", errno);
  
! 				g_iconv_works = False;
! 				return rdp_in_unistr(s, string, str_size, in_len);
! 			}
  		}
  
  		/* we must update the location of the current STREAM for future reads of s->p */
! 		s->p += in_len;
  
+ 		*pout = 0;
  		return pout - string;
  	}
***************
*** 284,289 ****
  	{
  		int i = 0;
  
! 		while (i < uni_len / 2)
  		{
  			in_uint8a(s, &string[i++], 1);
--- 292,306 ----
  	{
  		int i = 0;
+ 		int len = in_len/2;
+ 		int rem = 0;
  
! 		if (len > str_size-1)
! 		{
! 			warning("server sent an unexpectedly long string, truncating\n");
! 			len = str_size-1;
! 			rem = in_len - 2*len;
! 		}
! 
! 		while (i < len)
  		{
  			in_uint8a(s, &string[i++], 1);
***************
*** 291,295 ****
  		}
  
! 		return i - 1;
  	}
  }
--- 308,314 ----
  		}
  
! 		in_uint8s(s, rem);
! 		string[len] = 0;
! 		return len;
  	}
  }
***************
*** 1326,1330 ****
  
  	/* read ip string */
! 	rdp_in_unistr(s, g_redirect_server, len);
  
  	/* read length of cookie string */
--- 1345,1349 ----
  
  	/* read ip string */
! 	rdp_in_unistr(s, g_redirect_server, sizeof(g_redirect_server), len);
  
  	/* read length of cookie string */
***************
*** 1332,1336 ****
  
  	/* read cookie string (plain ASCII) */
! 	in_uint8a(s, g_redirect_cookie, len);
  	g_redirect_cookie[len] = 0;
  
--- 1351,1367 ----
  
  	/* read cookie string (plain ASCII) */
! 	if (len > sizeof(g_redirect_cookie)-1)
! 	{
! 		uint32 rem = len - (sizeof(g_redirect_cookie)-1);
! 		len = sizeof(g_redirect_cookie)-1;
! 
! 		warning("Unexpectedly large redirection cookie\n");
! 		in_uint8a(s, g_redirect_cookie, len);
! 		in_uint8s(s, rem);
! 	}
! 	else
! 	{
! 		in_uint8a(s, g_redirect_cookie, len);
! 	}
  	g_redirect_cookie[len] = 0;
  
***************
*** 1339,1343 ****
  
  	/* read username string */
! 	rdp_in_unistr(s, g_redirect_username, len);
  
  	/* read length of domain string */
--- 1370,1374 ----
  
  	/* read username string */
! 	rdp_in_unistr(s, g_redirect_username, sizeof(g_redirect_username), len);
  
  	/* read length of domain string */
***************
*** 1345,1349 ****
  
  	/* read domain string */
! 	rdp_in_unistr(s, g_redirect_domain, len);
  
  	/* read length of password string */
--- 1376,1380 ----
  
  	/* read domain string */
! 	rdp_in_unistr(s, g_redirect_domain, sizeof(g_redirect_domain), len);
  
  	/* read length of password string */
***************
*** 1351,1355 ****
  
  	/* read password string */
! 	rdp_in_unistr(s, g_redirect_password, len);
  
  	g_redirect = True;
--- 1382,1386 ----
  
  	/* read password string */
! 	rdp_in_unistr(s, g_redirect_password, sizeof(g_redirect_password), len);
  
  	g_redirect = True;

Index: rdpdr.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/rdpdr.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -C2 -d -r1.52 -r1.53
*** rdpdr.c	3 Jul 2007 14:08:06 -0000	1.52
--- rdpdr.c	5 Jan 2008 05:43:02 -0000	1.53
***************
*** 430,434 ****
  			if (length && (length / 2) < 256)
  			{
! 				rdp_in_unistr(s, filename, length);
  				convert_to_unix_filename(filename);
  			}
--- 430,434 ----
  			if (length && (length / 2) < 256)
  			{
! 				rdp_in_unistr(s, filename, sizeof(filename), length);
  				convert_to_unix_filename(filename);
  			}
***************
*** 623,627 ****
  					if (length && length < 2 * 255)
  					{
! 						rdp_in_unistr(s, filename, length);
  						convert_to_unix_filename(filename);
  					}
--- 623,627 ----
  					if (length && length < 2 * 255)
  					{
! 						rdp_in_unistr(s, filename, sizeof(filename), length);
  						convert_to_unix_filename(filename);
  					}


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/