mirror of
				https://gitlab.gnome.org/GNOME/glib.git
				synced 2025-11-04 01:58:54 +01:00 
			
		
		
		
	Add NULL checks to the base64 functions that take pointers. (#399611,
2007-03-06 Matthias Clasen <mclasen@redhat.com> * glib/gbase64.c: Add NULL checks to the base64 functions that take pointers. (#399611, Martyn Russell) svn path=/trunk/; revision=5371
This commit is contained in:
		
				
					committed by
					
						
						Matthias Clasen
					
				
			
			
				
	
			
			
			
						parent
						
							04b0520e09
						
					
				
				
					commit
					5ae803a47f
				
			@@ -1,3 +1,8 @@
 | 
				
			|||||||
 | 
					2007-03-06  Matthias Clasen  <mclasen@redhat.com>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						* glib/gbase64.c: Add NULL checks to the base64 
 | 
				
			||||||
 | 
						functions that take pointers.  (#399611, Martyn Russell)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
2007-03-06  Matthias Clasen  <mclasen@redhat.com>
 | 
					2007-03-06  Matthias Clasen  <mclasen@redhat.com>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Work with Solaris gettext (#341988, Laszlo Peter)
 | 
						Work with Solaris gettext (#341988, Laszlo Peter)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -38,8 +38,8 @@ static const char base64_alphabet[] =
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * g_base64_encode_step:
 | 
					 * g_base64_encode_step:
 | 
				
			||||||
 * @in: the binary data to encode.
 | 
					 * @in: the binary data to encode
 | 
				
			||||||
 * @len: the length of @in.
 | 
					 * @len: the length of @in
 | 
				
			||||||
 * @break_lines: whether to break long lines
 | 
					 * @break_lines: whether to break long lines
 | 
				
			||||||
 * @out: pointer to destination buffer
 | 
					 * @out: pointer to destination buffer
 | 
				
			||||||
 * @state: Saved state between steps, initialize to 0
 | 
					 * @state: Saved state between steps, initialize to 0
 | 
				
			||||||
@@ -76,6 +76,11 @@ g_base64_encode_step (const guchar *in,
 | 
				
			|||||||
  char *outptr;
 | 
					  char *outptr;
 | 
				
			||||||
  const guchar *inptr;
 | 
					  const guchar *inptr;
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
 | 
					  g_return_val_if_fail (in != NULL, 0);
 | 
				
			||||||
 | 
					  g_return_val_if_fail (out != NULL, 0);
 | 
				
			||||||
 | 
					  g_return_val_if_fail (state != NULL, 0);
 | 
				
			||||||
 | 
					  g_return_val_if_fail (save != NULL, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (len <= 0)
 | 
					  if (len <= 0)
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
@@ -172,6 +177,10 @@ g_base64_encode_close (gboolean  break_lines,
 | 
				
			|||||||
  int c1, c2;
 | 
					  int c1, c2;
 | 
				
			||||||
  char *outptr = out;
 | 
					  char *outptr = out;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_return_val_if_fail (out != NULL, 0);
 | 
				
			||||||
 | 
					  g_return_val_if_fail (state != NULL, 0);
 | 
				
			||||||
 | 
					  g_return_val_if_fail (save != NULL, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  c1 = ((unsigned char *) save) [1];
 | 
					  c1 = ((unsigned char *) save) [1];
 | 
				
			||||||
  c2 = ((unsigned char *) save) [2];
 | 
					  c2 = ((unsigned char *) save) [2];
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
@@ -201,8 +210,8 @@ g_base64_encode_close (gboolean  break_lines,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * g_base64_encode:
 | 
					 * g_base64_encode:
 | 
				
			||||||
 * @data: the binary data to encode.
 | 
					 * @data: the binary data to encode
 | 
				
			||||||
 * @len: the length of @data.
 | 
					 * @len: the length of @data
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Encode a sequence of binary data into its Base-64 stringified
 | 
					 * Encode a sequence of binary data into its Base-64 stringified
 | 
				
			||||||
 * representation.
 | 
					 * representation.
 | 
				
			||||||
@@ -220,6 +229,9 @@ g_base64_encode (const guchar *data,
 | 
				
			|||||||
  gint state = 0, outlen;
 | 
					  gint state = 0, outlen;
 | 
				
			||||||
  gint save = 0;
 | 
					  gint save = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_return_val_if_fail (data != NULL, NULL);
 | 
				
			||||||
 | 
					  g_return_val_if_fail (len > 1, NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* We can use a smaller limit here, since we know the saved state is 0 */
 | 
					  /* We can use a smaller limit here, since we know the saved state is 0 */
 | 
				
			||||||
  out = g_malloc (len * 4 / 3 + 4);
 | 
					  out = g_malloc (len * 4 / 3 + 4);
 | 
				
			||||||
  outlen = g_base64_encode_step (data, len, FALSE, out, &state, &save);
 | 
					  outlen = g_base64_encode_step (data, len, FALSE, out, &state, &save);
 | 
				
			||||||
@@ -284,6 +296,14 @@ g_base64_decode_step (const gchar  *in,
 | 
				
			|||||||
  guchar last[2];
 | 
					  guchar last[2];
 | 
				
			||||||
  unsigned int v;
 | 
					  unsigned int v;
 | 
				
			||||||
  int i;
 | 
					  int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_return_val_if_fail (in != NULL, 0);
 | 
				
			||||||
 | 
					  g_return_val_if_fail (out != NULL, 0);
 | 
				
			||||||
 | 
					  g_return_val_if_fail (state != NULL, 0);
 | 
				
			||||||
 | 
					  g_return_val_if_fail (save != NULL, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (len <= 0)
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  inend = (const guchar *)in+len;
 | 
					  inend = (const guchar *)in+len;
 | 
				
			||||||
  outptr = out;
 | 
					  outptr = out;
 | 
				
			||||||
@@ -323,8 +343,8 @@ g_base64_decode_step (const gchar  *in,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * g_base64_decode:
 | 
					 * g_base64_decode:
 | 
				
			||||||
 * @text: zero-terminated string with base64 text to decode.
 | 
					 * @text: zero-terminated string with base64 text to decode
 | 
				
			||||||
 * @out_len: The length of the decoded data is written here.
 | 
					 * @out_len: The length of the decoded data is written here
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Decode a sequence of Base-64 encoded text into binary data
 | 
					 * Decode a sequence of Base-64 encoded text into binary data
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
@@ -341,6 +361,9 @@ g_base64_decode (const gchar *text,
 | 
				
			|||||||
  gint inlen, state = 0;
 | 
					  gint inlen, state = 0;
 | 
				
			||||||
  guint save = 0;
 | 
					  guint save = 0;
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
 | 
					  g_return_val_if_fail (text != NULL, NULL);
 | 
				
			||||||
 | 
					  g_return_val_if_fail (out_len != NULL, NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  inlen = strlen (text);
 | 
					  inlen = strlen (text);
 | 
				
			||||||
  ret = g_malloc0 (inlen * 3 / 4);
 | 
					  ret = g_malloc0 (inlen * 3 / 4);
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user