Skip to content

Commit b20487a

Browse files
Merge branch 'mysql-5.5' into mysql-5.6
2 parents 6623ee7 + 0dbd5a8 commit b20487a

File tree

4 files changed

+42
-24
lines changed

4 files changed

+42
-24
lines changed

client/mysql_plugin.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -406,7 +406,7 @@ static int get_default_values()
406406
static void usage(void)
407407
{
408408
PRINT_VERSION;
409-
puts("Copyright (c) 2011, Oracle and/or its affiliates. "
409+
puts("Copyright (c) 2011, 2015, Oracle and/or its affiliates. "
410410
"All rights reserved.\n");
411411
puts("Enable or disable plugins.");
412412
printf("\nUsage: %s [options] <plugin> ENABLE|DISABLE\n\nOptions:\n",
@@ -793,6 +793,11 @@ static int check_options(int argc, char **argv, char *operation)
793793
/* read the plugin config file and check for match against argument */
794794
else
795795
{
796+
if (strlen(argv[i]) + 4 + 1 > FN_REFLEN)
797+
{
798+
fprintf(stderr, "ERROR: argument is too long.\n");
799+
return 1;
800+
}
796801
strcpy(plugin_name, argv[i]);
797802
strcpy(config_file, argv[i]);
798803
strcat(config_file, ".ini");
@@ -884,6 +889,7 @@ static int process_options(int argc, char *argv[], char *operation)
884889
if (opt_basedir[i-1] != FN_LIBCHAR || opt_basedir[i-1] != FN_LIBCHAR2)
885890
{
886891
char buff[FN_REFLEN];
892+
memset(buff, 0, sizeof(buff));
887893

888894
strncpy(buff, opt_basedir, sizeof(buff) - 1);
889895
#ifdef __WIN__

client/mysqlshow.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ list_dbs(MYSQL *mysql,const char *wild)
400400
uint length, counter = 0;
401401
ulong rowcount = 0L;
402402
char tables[NAME_LEN+1], rows[NAME_LEN+1];
403-
char query[255];
403+
char query[NAME_LEN + 100];
404404
MYSQL_FIELD *field;
405405
MYSQL_RES *result;
406406
MYSQL_ROW row= NULL, rrow;
@@ -467,7 +467,8 @@ list_dbs(MYSQL *mysql,const char *wild)
467467
MYSQL_ROW trow;
468468
while ((trow = mysql_fetch_row(tresult)))
469469
{
470-
sprintf(query,"SELECT COUNT(*) FROM `%s`",trow[0]);
470+
my_snprintf(query, sizeof(query),
471+
"SELECT COUNT(*) FROM `%s`", trow[0]);
471472
if (!(mysql_query(mysql,query)))
472473
{
473474
MYSQL_RES *rresult;
@@ -523,7 +524,7 @@ list_tables(MYSQL *mysql,const char *db,const char *table)
523524
{
524525
const char *header;
525526
uint head_length, counter = 0;
526-
char query[255], rows[NAME_LEN], fields[16];
527+
char query[NAME_LEN + 100], rows[NAME_LEN], fields[16];
527528
MYSQL_FIELD *field;
528529
MYSQL_RES *result;
529530
MYSQL_ROW row, rrow;
@@ -608,7 +609,8 @@ list_tables(MYSQL *mysql,const char *db,const char *table)
608609
if (opt_verbose > 1)
609610
{
610611
/* Print the count of rows for each table */
611-
sprintf(query,"SELECT COUNT(*) FROM `%s`",row[0]);
612+
my_snprintf(query, sizeof(query), "SELECT COUNT(*) FROM `%s`",
613+
row[0]);
612614
if (!(mysql_query(mysql,query)))
613615
{
614616
if ((rresult = mysql_store_result(mysql)))
@@ -668,13 +670,15 @@ list_tables(MYSQL *mysql,const char *db,const char *table)
668670
static int
669671
list_table_status(MYSQL *mysql,const char *db,const char *wild)
670672
{
671-
char query[1024],*end;
673+
char query[NAME_LEN + 100];
674+
int len;
672675
MYSQL_RES *result;
673676
MYSQL_ROW row;
674677

675-
end=strxmov(query,"show table status from `",db,"`",NullS);
676-
if (wild && wild[0])
677-
strxmov(end," like '",wild,"'",NullS);
678+
len= sizeof(query);
679+
len-= my_snprintf(query, len, "show table status from `%s`", db);
680+
if (wild && wild[0] && len)
681+
strxnmov(query + strlen(query), len, " like '", wild, "'", NullS);
678682
if (mysql_query(mysql,query) || !(result=mysql_store_result(mysql)))
679683
{
680684
fprintf(stderr,"%s: Cannot get status for db: %s, table: %s: %s\n",
@@ -706,7 +710,8 @@ static int
706710
list_fields(MYSQL *mysql,const char *db,const char *table,
707711
const char *wild)
708712
{
709-
char query[1024],*end;
713+
char query[NAME_LEN + 100];
714+
int len;
710715
MYSQL_RES *result;
711716
MYSQL_ROW row;
712717
ulong UNINIT_VAR(rows);
@@ -720,7 +725,7 @@ list_fields(MYSQL *mysql,const char *db,const char *table,
720725

721726
if (opt_count)
722727
{
723-
sprintf(query,"select count(*) from `%s`", table);
728+
my_snprintf(query, sizeof(query), "select count(*) from `%s`", table);
724729
if (mysql_query(mysql,query) || !(result=mysql_store_result(mysql)))
725730
{
726731
fprintf(stderr,"%s: Cannot get record count for db: %s, table: %s: %s\n",
@@ -732,9 +737,11 @@ list_fields(MYSQL *mysql,const char *db,const char *table,
732737
mysql_free_result(result);
733738
}
734739

735-
end=strmov(strmov(strmov(query,"show /*!32332 FULL */ columns from `"),table),"`");
736-
if (wild && wild[0])
737-
strxmov(end," like '",wild,"'",NullS);
740+
len= sizeof(query);
741+
len-= my_snprintf(query, len, "show /*!32332 FULL */ columns from `%s`",
742+
table);
743+
if (wild && wild[0] && len)
744+
strxnmov(query + strlen(query), len, " like '", wild, "'", NullS);
738745
if (mysql_query(mysql,query) || !(result=mysql_store_result(mysql)))
739746
{
740747
fprintf(stderr,"%s: Cannot list columns in db: %s, table: %s: %s\n",
@@ -755,7 +762,7 @@ list_fields(MYSQL *mysql,const char *db,const char *table,
755762
print_res_top(result);
756763
if (opt_show_keys)
757764
{
758-
end=strmov(strmov(strmov(query,"show keys from `"),table),"`");
765+
my_snprintf(query, sizeof(query), "show keys from `%s`", table);
759766
if (mysql_query(mysql,query) || !(result=mysql_store_result(mysql)))
760767
{
761768
fprintf(stderr,"%s: Cannot list keys in db: %s, table: %s: %s\n",

libmysql/conf_to_src.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -118,7 +118,7 @@ print_arrays_for(char *set)
118118
{
119119
FILE *f;
120120

121-
sprintf(buf, "%s.conf", set);
121+
snprintf(buf, sizeof(buf), "%s.conf", set);
122122

123123
if ((f = fopen(buf, "r")) == NULL) {
124124
fprintf(stderr, "%s: can't read conf file for charset %s\n", prog, set);

regex/main.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,8 @@ char *should;
498498
(sub.rm_so != -1 && sub.rm_eo == -1) ||
499499
(sub.rm_so != -1 && sub.rm_so < 0) ||
500500
(sub.rm_eo != -1 && sub.rm_eo < 0) ) {
501-
sprintf(grump, "start %ld end %ld", (long)sub.rm_so,
501+
snprintf(grump, sizeof(grump),
502+
"start %ld end %ld", (long)sub.rm_so,
502503
(long)sub.rm_eo);
503504
return(grump);
504505
}
@@ -511,7 +512,8 @@ char *should;
511512

512513
/* check for in range */
513514
if ((int) sub.rm_eo > (int) strlen(str)) {
514-
sprintf(grump, "start %ld end %ld, past end of string",
515+
snprintf(grump, sizeof(grump),
516+
"start %ld end %ld, past end of string",
515517
(long)sub.rm_so, (long)sub.rm_eo);
516518
return(grump);
517519
}
@@ -522,13 +524,15 @@ char *should;
522524

523525
/* check for not supposed to match */
524526
if (should == NULL) {
525-
sprintf(grump, "matched `%.*s'", len, p);
527+
snprintf(grump, sizeof(grump),
528+
"matched `%.*s'", len, p);
526529
return(grump);
527530
}
528531

529532
/* check for wrong match */
530533
if (len != shlen || strncmp(p, should, (size_t)shlen) != 0) {
531-
sprintf(grump, "matched `%.*s' instead", len, p);
534+
snprintf(grump, sizeof(grump),
535+
"matched `%.*s' instead", len, p);
532536
return(grump);
533537
}
534538
if (shlen > 0)
@@ -541,7 +545,8 @@ char *should;
541545
if (shlen == 0)
542546
shlen = 1; /* force check for end-of-string */
543547
if (strncmp(p, at, shlen) != 0) {
544-
sprintf(grump, "matched null at `%.20s'", p);
548+
snprintf(grump, sizeof(grump),
549+
"matched null at `%.20s'", p);
545550
return(grump);
546551
}
547552
return(NULL);
@@ -574,7 +579,7 @@ char *name;
574579
static char efbuf[100];
575580
my_regex_t re;
576581

577-
sprintf(efbuf, "MY_REG_%s", name);
582+
snprintf(efbuf, sizeof(efbuf), "MY_REG_%s", name);
578583
assert(strlen(efbuf) < sizeof(efbuf));
579584
re.re_endp = efbuf;
580585
(void) my_regerror(MY_REG_ATOI, &re, efbuf, sizeof(efbuf));

0 commit comments

Comments
 (0)