~ubuntu-branches/ubuntu/utopic/mysql-5.6/utopic-proposed

« back to all changes in this revision

Viewing changes to sql/sql_load.cc

  • Committer: Package Import Robot
  • Author(s): James Page, Bjoern Boschman
  • Date: 2014-07-21 14:01:12 UTC
  • mfrom: (5.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20140721140112-1yqdrd6ds8y7nt76
Tags: 5.6.19-1~exp1
[ Bjoern Boschman ]
* SECURITY UPDATE: New upstream release (LP: #1330168).
  - www.oracle.com/technetwork/topics/security/cpujul2014-1972956.html
  - CVE-2014-2484
  - CVE-2014-4258
  - CVE-2014-4260
  - CVE-2014-4238
  - CVE-2014-4233
  - CVE-2014-4240
  - CVE-2014-4214

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
   Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
 
2
   Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
3
3
 
4
4
   This program is free software; you can redistribute it and/or modify
5
5
   it under the terms of the GNU General Public License as published by
61
61
}
62
62
 
63
63
 
 
64
#define GET (stack_pos != stack ? *--stack_pos : my_b_get(&cache))
 
65
#define PUSH(A) *(stack_pos++)=(A)
 
66
 
64
67
class READ_INFO {
65
68
  File  file;
66
69
  uchar *buffer,                        /* Buffer for read text */
67
70
        *end_of_buff;                   /* Data in bufferts ends here */
68
71
  uint  buff_length,                    /* Length of buffert */
69
72
        max_length;                     /* Max length of row */
70
 
  const char *field_term_ptr, *line_term_ptr, *line_start_ptr, *line_start_end;
 
73
  const uchar *field_term_ptr, *line_term_ptr;
 
74
  const char *line_start_ptr, *line_start_end;
71
75
  uint  field_term_length,line_term_length,enclosed_length;
72
76
  int   field_term_char,line_term_char,enclosed_char,escape_char;
73
77
  int   *stack,*stack_pos;
94
98
  int read_fixed_length(void);
95
99
  int next_line(void);
96
100
  char unescape(char chr);
97
 
  int terminator(const char *ptr,uint length);
 
101
  int terminator(const uchar *ptr, uint length);
98
102
  bool find_start_of_fields();
99
103
  /* load xml */
100
104
  List<XML_TAG> taglist;
118
122
    either the table or THD value
119
123
  */
120
124
  void set_io_cache_arg(void* arg) { cache.arg = arg; }
 
125
 
 
126
  /**
 
127
    skip all data till the eof.
 
128
  */
 
129
  void skip_data_till_eof()
 
130
  {
 
131
    while (GET != my_b_EOF)
 
132
      ;
 
133
  }
121
134
};
122
135
 
123
136
static int read_fixed_length(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
541
554
  if (error)
542
555
  {
543
556
    if (read_file_from_client)
544
 
      while (!read_info.next_line())
545
 
        ;
 
557
      read_info.skip_data_till_eof();
546
558
 
547
559
#ifndef EMBEDDED_LIBRARY
548
560
    if (mysql_bin_log.is_open())
751
763
                        strlen(item->item_name.ptr()));
752
764
      // Extract exact Item value
753
765
      str->copy();
754
 
      pfields.append((char *)str->ptr());
 
766
      pfields.append(str->ptr());
755
767
      str->free();
756
768
    }
757
769
    /*
767
779
  if (!(load_data_query= (char *)thd->alloc(lle.get_query_buffer_length() + 1 + pl)))
768
780
    return TRUE;
769
781
 
770
 
  lle.print_query(FALSE, (const char *) ex->cs?ex->cs->csname:NULL,
 
782
  lle.print_query(FALSE, ex->cs ? ex->cs->csname : NULL,
771
783
                  load_data_query, &end,
772
 
                  (char **)&fname_start, (char **)&fname_end);
 
784
                  &fname_start, &fname_end);
773
785
 
774
786
  strcpy(end, p);
775
787
  end += pl;
776
788
 
777
789
  Execute_load_query_log_event
778
790
    e(thd, load_data_query, end-load_data_query,
779
 
      (uint) ((char*) fname_start - load_data_query - 1),
780
 
      (uint) ((char*) fname_end - load_data_query),
 
791
      static_cast<uint>(fname_start - load_data_query - 1),
 
792
      static_cast<uint>(fname_end - load_data_query),
781
793
      (duplicates == DUP_REPLACE) ? LOAD_DUP_REPLACE :
782
794
      (ignore ? LOAD_DUP_IGNORE : LOAD_DUP_ERROR),
783
795
      transactional_table, FALSE, FALSE, errcode);
1358
1370
   found_end_of_line(false), eof(false), need_end_io_cache(false),
1359
1371
   error(false), line_cuted(false), found_null(false), read_charset(cs)
1360
1372
{
1361
 
  field_term_ptr= field_term.ptr();
 
1373
  /*
 
1374
    Field and line terminators must be interpreted as sequence of unsigned char.
 
1375
    Otherwise, non-ascii terminators will be negative on some platforms,
 
1376
    and positive on others (depending on the implementation of char).
 
1377
  */
 
1378
  field_term_ptr=
 
1379
    static_cast<const uchar*>(static_cast<const void*>(field_term.ptr()));
1362
1380
  field_term_length= field_term.length();
1363
 
  line_term_ptr= line_term.ptr();
 
1381
  line_term_ptr=
 
1382
    static_cast<const uchar*>(static_cast<const void*>(line_term.ptr()));
1364
1383
  line_term_length= line_term.length();
 
1384
 
1365
1385
  level= 0; /* for load xml */
1366
1386
  if (line_start.length() == 0)
1367
1387
  {
1370
1390
  }
1371
1391
  else
1372
1392
  {
1373
 
    line_start_ptr=(char*) line_start.ptr();
 
1393
    line_start_ptr= line_start.ptr();
1374
1394
    line_start_end=line_start_ptr+line_start.length();
1375
1395
    start_of_line= 1;
1376
1396
  }
1379
1399
      !memcmp(field_term_ptr,line_term_ptr,field_term_length))
1380
1400
  {
1381
1401
    line_term_length=0;
1382
 
    line_term_ptr=(char*) "";
 
1402
    line_term_ptr= NULL;
1383
1403
  }
1384
1404
  enclosed_char= (enclosed_length=enclosed_par.length()) ?
1385
1405
    (uchar) enclosed_par[0] : INT_MAX;
1386
 
  field_term_char= field_term_length ? (uchar) field_term_ptr[0] : INT_MAX;
1387
 
  line_term_char= line_term_length ? (uchar) line_term_ptr[0] : INT_MAX;
 
1406
  field_term_char= field_term_length ? field_term_ptr[0] : INT_MAX;
 
1407
  line_term_char= line_term_length ? line_term_ptr[0] : INT_MAX;
1388
1408
 
1389
1409
 
1390
1410
  /* Set of a stack for unget if long terminators */
1442
1462
}
1443
1463
 
1444
1464
 
1445
 
#define GET (stack_pos != stack ? *--stack_pos : my_b_get(&cache))
1446
 
#define PUSH(A) *(stack_pos++)=(A)
1447
 
 
1448
 
 
1449
 
inline int READ_INFO::terminator(const char *ptr,uint length)
 
1465
inline int READ_INFO::terminator(const uchar *ptr, uint length)
1450
1466
{
1451
1467
  int chr=0;                                    // Keep gcc happy
1452
1468
  uint i;
1453
1469
  for (i=1 ; i < length ; i++)
1454
1470
  {
1455
 
    if ((chr=GET) != *++ptr)
 
1471
    chr= GET;
 
1472
    if (chr != *++ptr)
1456
1473
    {
1457
1474
      break;
1458
1475
    }
1461
1478
    return 1;
1462
1479
  PUSH(chr);
1463
1480
  while (i-- > 1)
1464
 
    PUSH((uchar) *--ptr);
 
1481
    PUSH(*--ptr);
1465
1482
  return 0;
1466
1483
}
1467
1484
 
1592
1609
      if (my_mbcharlen(read_charset, chr) > 1 &&
1593
1610
          to + my_mbcharlen(read_charset, chr) <= end_of_buff)
1594
1611
      {
1595
 
        uchar* p= (uchar*) to;
 
1612
        uchar* p= to;
1596
1613
        int ml, i;
1597
1614
        *to++ = chr;
1598
1615
 
1617
1634
                        (const char *)to))
1618
1635
          continue;
1619
1636
        for (i= 0; i < ml; i++)
1620
 
          PUSH((uchar) *--to);
 
1637
          PUSH(*--to);
1621
1638
        chr= GET;
1622
1639
      }
1623
1640
#endif
1779
1796
      PUSH(chr);
1780
1797
      while (--ptr != line_start_ptr)
1781
1798
      {                                         // Restart with next char
1782
 
        PUSH((uchar) *ptr);
 
1799
        PUSH( *ptr);
1783
1800
      }
1784
1801
      goto try_again;
1785
1802
    }
1975
1992
      
1976
1993
      // row tag should be in ROWS IDENTIFIED BY '<row>' - stored in line_term 
1977
1994
      if((tag.length() == line_term_length -2) &&
1978
 
         (strncmp(tag.c_ptr_safe(), line_term_ptr + 1, tag.length()) == 0))
 
1995
         (memcmp(tag.ptr(), line_term_ptr + 1, tag.length()) == 0))
1979
1996
      {
1980
1997
        DBUG_PRINT("read_xml", ("start-of-row: %i %s %s", 
1981
1998
                                level,tag.c_ptr_safe(), line_term_ptr));
2037
2054
      }
2038
2055
      
2039
2056
      if((tag.length() == line_term_length -2) &&
2040
 
         (strncmp(tag.c_ptr_safe(), line_term_ptr + 1, tag.length()) == 0))
 
2057
         (memcmp(tag.ptr(), line_term_ptr + 1, tag.length()) == 0))
2041
2058
      {
2042
2059
         DBUG_PRINT("read_xml", ("found end-of-row %i %s", 
2043
2060
                                 level, tag.c_ptr_safe()));