~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle-2.0/query.cc

  • Committer: Brian Aker
  • Date: 2011-11-18 02:03:41 UTC
  • mto: (2463.1.1 drizzle-include)
  • mto: This revision was merged to the branch mainline in revision 2462.
  • Revision ID: brian@tangent.org-20111118020341-mgz2m1kjo62al44e
Fix safety issues around calling API with no check for NULL

Show diffs side-by-side

added added

removed removed

Lines of Context:
351
351
  return DRIZZLE_RETURN_OK;
352
352
}
353
353
 
354
 
ssize_t drizzle_safe_escape_string(char *to, size_t max_to_size, const char *from, size_t from_size)
 
354
ssize_t drizzle_escape_string(char *to, size_t max_to_size, const char *from, size_t from_size)
355
355
{
356
356
  ssize_t to_size= 0;
357
357
  char newchar;
393
393
    if (newchar != '\0')
394
394
    {
395
395
      if ((size_t)to_size + 2 > max_to_size)
 
396
      {
396
397
        return -1;
 
398
      }
397
399
 
398
400
      *to++= '\\';
399
401
      *to++= newchar;
402
404
    else
403
405
    {
404
406
      if ((size_t)to_size + 1 > max_to_size)
 
407
      {
405
408
        return -1;
 
409
      }
406
410
 
407
411
      *to++= *from;
408
412
    }
414
418
  return to_size;
415
419
}
416
420
 
417
 
size_t drizzle_escape_string(char *to, const char *from, size_t from_size)
418
 
{
419
 
  return (size_t) drizzle_safe_escape_string(to, (from_size * 2), from, from_size);
420
 
}
421
 
 
422
421
size_t drizzle_hex_string(char *to, const char *from, size_t from_size)
423
422
{
424
423
  static const char hex_map[]= "0123456789ABCDEF";