1
/* Copyright (C) 2000-2006 MySQL AB
2
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
3
4
This program is free software; you can redistribute it and/or modify
4
5
it under the terms of the GNU General Public License as published by
12
13
You should have received a copy of the GNU General Public License
13
14
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
15
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
516
520
tmp_arg[res_length-1]=tail; // save extra length
517
521
tmp_value.realloc(res_length+1);
518
522
tmp_value.length(res_length+1);
523
tmp_value.set_charset(&my_charset_bin);
519
524
tmp_value[0]=(char) (128 | key_number);
520
525
// Real encryption
521
526
bzero((char*) &ivec,sizeof(ivec));
1144
1150
/* if "unsigned_flag" is set, we have a *huge* positive number. */
1145
1151
if ((length <= 0) && (!args[1]->unsigned_flag))
1146
return &my_empty_string;
1152
return make_empty_result();
1148
1153
if ((res->length() <= (ulonglong) length) ||
1149
1154
(res->length() <= (char_pos= res->charpos((int) length))))
1188
1193
/* if "unsigned_flag" is set, we have a *huge* positive number. */
1189
1194
if ((length <= 0) && (!args[1]->unsigned_flag))
1190
return &my_empty_string; /* purecov: inspected */
1195
return make_empty_result(); /* purecov: inspected */
1192
1197
if (res->length() <= (ulonglong) length)
1193
1198
return res; /* purecov: inspected */
1226
1231
/* Negative or zero length, will return empty string. */
1227
1232
if ((arg_count == 3) && (length <= 0) &&
1228
1233
(length == 0 || !args[2]->unsigned_flag))
1229
return &my_empty_string;
1234
return make_empty_result();
1231
1236
/* Assumes that the maximum length of a String is < INT_MAX32. */
1232
1237
/* Set here so that rest of code sees out-of-bound value as such. */
1237
1242
/* Assumes that the maximum length of a String is < INT_MAX32. */
1238
1243
if ((!args[1]->unsigned_flag && (start < INT_MIN32 || start > INT_MAX32)) ||
1239
1244
(args[1]->unsigned_flag && ((ulonglong) start > INT_MAX32)))
1240
return &my_empty_string;
1245
return make_empty_result();
1242
1247
start= ((start < 0) ? res->numchars() + start : start - 1);
1243
1248
start= res->charpos((int) start);
1244
1249
if ((start < 0) || ((uint) start + 1 > res->length()))
1245
return &my_empty_string;
1250
return make_empty_result();
1247
1252
length= res->charpos((int) length, (uint32) start);
1248
1253
tmp_length= res->length() - start;
1306
1311
uint delimiter_length= delimiter->length();
1307
1312
if (!res->length() || !delimiter_length || !count)
1308
return &my_empty_string; // Wrong parameters
1313
return make_empty_result(); // Wrong parameters
1310
1315
res->set_charset(collation.collation);
1654
1659
if ((null_value=args[0]->null_value))
1656
1661
if (res->length() == 0)
1657
return &my_empty_string;
1662
return make_empty_result();
1658
1663
my_make_scrambled_password(tmp_value, res->ptr(), res->length());
1659
1664
str->set(tmp_value, SCRAMBLED_PASSWORD_CHAR_LENGTH, res->charset());
1678
1683
if ((null_value=args[0]->null_value))
1680
1685
if (res->length() == 0)
1681
return &my_empty_string;
1686
return make_empty_result();
1682
1687
my_make_scrambled_password_323(tmp_value, res->ptr(), res->length());
1683
1688
str->set(tmp_value, SCRAMBLED_PASSWORD_CHAR_LENGTH_323, res->charset());
1967
1971
for ( ; ; ) /* Skip pre-space */
1969
1973
if ((rc= cs->cset->mb_wc(cs, &wc, (uchar*) from, (uchar*) end)) <= 0)
1970
return &my_empty_string; /* EOL or invalid byte sequence */
1974
return make_empty_result(); /* EOL or invalid byte sequence */
1972
1976
if (rc == 1 && cs->ctype)
2299
2303
{ // Copy data to tmp_str
2300
2304
if (tmp_str.alloc(result->length()+res->length()+1) ||
2301
2305
tmp_str.copy(*result))
2302
return &my_empty_string;
2306
return make_empty_result();
2303
2307
result= &tmp_str;
2305
2309
if (tmp_str.append(STRING_WITH_LEN(","), &my_charset_bin) || tmp_str.append(*res))
2306
return &my_empty_string;
2310
return make_empty_result();
2444
2448
if (count <= 0 && (count == 0 || !args[1]->unsigned_flag))
2445
return &my_empty_string;
2449
return make_empty_result();
2447
2451
/* Assumes that the maximum length of a String is < INT_MAX32. */
2448
2452
/* Bounds check on count: If this is triggered, we will error. */
2751
2755
ptr= longlong2str(dec, ans, to_base);
2752
2756
if (str->copy(ans, (uint32) (ptr-ans), default_charset()))
2753
return &my_empty_string;
2757
return make_empty_result();
2760
2764
DBUG_ASSERT(fixed == 1);
2761
2765
if (use_cached_value)
2762
2766
return null_value ? 0 : &str_value;
2764
Here we don't pass 'str' as a parameter to args[0]->val_str()
2765
as 'str' may point to 'str_value' (e.g. see Item::save_in_field()),
2766
which we use below to convert string.
2767
Use argument's 'str_value' instead.
2769
String *arg= args[0]->val_str(&args[0]->str_value);
2767
String *arg= args[0]->val_str(str);
2770
2768
uint dummy_errors;
2776
null_value= str_value.copy(arg->ptr(),arg->length(),arg->charset(),
2774
null_value= tmp_value.copy(arg->ptr(), arg->length(), arg->charset(),
2777
2775
conv_charset, &dummy_errors);
2778
return null_value ? 0 : check_well_formed_result(&str_value);
2776
return null_value ? 0 : check_well_formed_result(&tmp_value);
2781
2779
void Item_func_conv_charset::fix_length_and_dec()
2918
2916
ptr= longlong2str(dec,ans,16);
2919
2917
if (str->copy(ans,(uint32) (ptr-ans),default_charset()))
2920
return &my_empty_string; // End of memory
2918
return make_empty_result(); // End of memory
3219
3217
arg_length= arg->length();
3220
new_length= arg_length+2; /* for beginning and ending ' signs */
3222
for (from= (char*) arg->ptr(), end= from + arg_length; from < end; from++)
3223
new_length+= get_esc_bit(escmask, (uchar) *from);
3219
if (collation.collation->mbmaxlen == 1)
3221
new_length= arg_length + 2; /* for beginning and ending ' signs */
3222
for (from= (char*) arg->ptr(), end= from + arg_length; from < end; from++)
3223
new_length+= get_esc_bit(escmask, (uchar) *from);
3227
new_length= (arg_length * 2) + /* For string characters */
3228
(2 * collation.collation->mbmaxlen); /* For quotes */
3225
3231
if (tmp_value.alloc(new_length))
3234
if (collation.collation->mbmaxlen > 1)
3236
CHARSET_INFO *cs= collation.collation;
3239
to= (char*) tmp_value.ptr();
3240
to_end= (uchar*) to + new_length;
3242
/* Put leading quote */
3243
if ((mblen= cs->cset->wc_mb(cs, '\'', (uchar *) to, to_end)) <= 0)
3247
for (start= (char*) arg->ptr(), end= start + arg_length; start < end; )
3251
if ((mblen= cs->cset->mb_wc(cs, &wc, (uchar*) start, (uchar*) end)) <= 0)
3255
case 0: escape= 1; wc= '0'; break;
3256
case '\032': escape= 1; wc= 'Z'; break;
3257
case '\'': escape= 1; break;
3258
case '\\': escape= 1; break;
3259
default: escape= 0; break;
3263
if ((mblen= cs->cset->wc_mb(cs, '\\', (uchar*) to, to_end)) <= 0)
3267
if ((mblen= cs->cset->wc_mb(cs, wc, (uchar*) to, to_end)) <= 0)
3272
/* Put trailing quote */
3273
if ((mblen= cs->cset->wc_mb(cs, '\'', (uchar *) to, to_end)) <= 0)
3276
new_length= to - tmp_value.ptr();
3229
3281
We replace characters from the end to the beginning
3412
3466
push_warning_printf(current_thd,MYSQL_ERROR::WARN_LEVEL_ERROR,
3413
3467
ER_TOO_BIG_FOR_UNCOMPRESS,
3414
3468
ER(ER_TOO_BIG_FOR_UNCOMPRESS),
3415
current_thd->variables.max_allowed_packet);
3469
static_cast<int>(current_thd->variables.
3470
max_allowed_packet));
3418
3473
if (buffer.realloc((uint32)new_size))