Branch: Tag:

2015-06-30

2015-06-30 20:43:07 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Mysql: Use the new precompiler string checking feature.

This simplifies argument checking somewhat by using the
precompiler's new string range checker.

Adjusts the argument types for a few functions accordingly.

720:    *! cases it's possible that @[set_charset] works better (provided    *! the server is 4.1 or newer).    */ - PIKEFUN void create(string(8bit)|void host, string(8bit)|void database, -  string(8bit)|void user, string(8bit)|void password, + PIKEFUN void create(string(1..255)|void host, string(1..255)|void database, +  string(1..255)|void user, string(1..255)|void password,    mapping|void options)   {   #if defined(HAVE_MYSQL_OPTIONS) && defined(HAVE_MYSQL_OPT_LOCAL_INFILE)
731:    (char *)&allowed);   #endif /* HAVE_MYSQL_OPTIONS && HAVE_MYSQL_OPT_LOCAL_INFILE */    -  if (args >= 1) { -  CHECK_8BIT_NONBINARY_STRING ("create", 1); +     if (host && host->len) {    add_ref(PIKE_MYSQL->host = host);    } -  -  if (args >= 2) { -  CHECK_8BIT_NONBINARY_STRING ("create", 2); -  if (sp[1-args].u.string->len) { +  if (database && database->len) {    add_ref(PIKE_MYSQL->database = database);    } -  -  if (args >= 3) { -  CHECK_8BIT_NONBINARY_STRING ("create", 3); -  if (sp[2-args].u.string->len) { +  if (user && user->len) {    add_ref(PIKE_MYSQL->user = user);    } -  -  if (args >= 4) { -  CHECK_8BIT_NONBINARY_STRING ("create", 4); -  if (sp[3-args].u.string->len) { +  if (password && password->len) {    add_ref(PIKE_MYSQL->password = password);    }    if (args >= 5) {
764:    pike_mysql_set_options(options);    }    } -  } -  } -  } -  } +        pike_mysql_set_ssl(PIKE_MYSQL->options);   
1049:    *! @seealso    *! @[create()], @[create_db()], @[drop_db()]    */ - PIKEFUN void select_db(string(8bit) database) + PIKEFUN void select_db(string(1..255) database)   {    MYSQL *mysql = PIKE_MYSQL->mysql;    int tmp = -1;    -  CHECK_8BIT_NONBINARY_STRING ("select_db", 1); -  +     if (mysql) {    MYSQL_ALLOW();   
1212:    *! @[select_db()], @[drop_db()]    */   #ifdef USE_OLD_FUNCTIONS - PIKEFUN void create_db(string(8bit) database) + PIKEFUN void create_db(string(1..255) database)   {    MYSQL *mysql = PIKE_MYSQL->mysql;    int tmp = -1;    -  CHECK_8BIT_NONBINARY_STRING ("create_db", 1); +     if (database->len > 127) {    if (database->len < 1024) {    Pike_error("Database name \"%s\" is too long (max 127 characters)\n",
1252:    *! @seealso    *! @[create_db()], @[select_db()]    */ - PIKEFUN void drop_db(string(8bit) database) + PIKEFUN void drop_db(string(1..255) database)   {    MYSQL *mysql = PIKE_MYSQL->mysql;    int tmp = -1;    -  CHECK_8BIT_NONBINARY_STRING ("drop_db", 1); +     if (database->len > 127) {    if (database->len < 1024) {    Pike_error("Database name \"%s\" is too long (max 127 characters)\n",
1495:    *! @[list_tables()], @[list_fields()], @[list_processes()],    *! @[Mysql.mysql_result]    */ - PIKEFUN object list_dbs(string|void wild) + PIKEFUN object list_dbs(string(1..255)|void wild)   {    MYSQL *mysql = PIKE_MYSQL->mysql;    MYSQL_RES *result = NULL;       if (wild) { -  CHECK_8BIT_NONBINARY_STRING ("Mysql.mysql->list_dbs", 1); +     if (wild->len > 80) {    if (wild->len < 1024) {    Pike_error("Wildcard \"%s\" is too long (max 80 characters)\n",
1552:    *! @[list_dbs()], @[list_fields()], @[list_processes()],    *! @[Mysql.mysql_result]    */ - PIKEFUN object list_tables(string|void wild) + PIKEFUN object list_tables(string(1..255)|void wild)   {    MYSQL *mysql = PIKE_MYSQL->mysql;    MYSQL_RES *result = NULL;       if (wild) { -  CHECK_8BIT_NONBINARY_STRING ("Mysql.mysql->list_tables", 1); +     if (wild->len > 80) {    if (wild->len < 1024) {    Pike_error("Wildcard \"%s\" is too long (max 80 characters)\n",
1670:    *! @[list_dbs()], @[list_tables()], @[list_processes()],    *! @[Mysql.mysql_result.fetch_field()]    */ - PIKEFUN array(int|mapping(string:mixed)) list_fields(string(8bit) table, -  string(8bit)|void wild) + PIKEFUN array(int|mapping(string:mixed)) list_fields(string(1..255) table, +  string(1..255)|void wild)   {    MYSQL *mysql = PIKE_MYSQL->mysql;    MYSQL_RES *result = NULL;    MYSQL_FIELD *field;    int i = 0;    -  CHECK_8BIT_NONBINARY_STRING ("list_fields", 1); +     if (table->len > 125) {    if (table->len < 1024) {    Pike_error("Table name \"%s\" is too long (max 125 characters)\n",
1689:    }    }    if (wild) { -  CHECK_8BIT_NONBINARY_STRING ("Mysql.mysql->list_fields", 2); +     if (wild->len + table->len > 125) {    /* The length of the table name has already been checked. */    if (wild->len < 1024) {