diff options
Diffstat (limited to 'storage/connect/ha_connect.cc')
-rw-r--r-- | storage/connect/ha_connect.cc | 89 |
1 files changed, 45 insertions, 44 deletions
diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index 9ac1571e5ac..2bf4f6b53cb 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -1403,7 +1403,8 @@ char *ha_connect::GetRealString(PCSZ s) if (IsPartitioned() && s && *partname) { sv= (char*)PlugSubAlloc(xp->g, NULL, 0); - sprintf(sv, s, partname); + PPOOLHEADER pph = (PPOOLHEADER)xp->g->Sarea; + snprintf(sv, xp->g->Sarea_Size - pph->To_Free, s, partname); PlugSubAlloc(xp->g, NULL, strlen(sv) + 1); } else sv= (char*)s; @@ -2079,7 +2080,7 @@ int ha_connect::OpenTable(PGLOBAL g, bool del) // Trying to update a column used for partitioning // This cannot be currently done because it may require // a row to be moved in another partition. - sprintf(g->Message, + snprintf(g->Message, sizeof(g->Message), "Cannot update column %s because it is used for partitioning", p); return HA_ERR_INTERNAL_ERROR; @@ -2134,7 +2135,7 @@ bool ha_connect::CheckColumnList(PGLOBAL g) for (field= table->field; (fp= *field); field++) if (bitmap_is_set(map, fp->field_index)) { if (!(colp= tdbp->ColDB(g, (PSZ)fp->field_name.str, 0))) { - sprintf(g->Message, "Column %s not found in %s", + snprintf(g->Message, sizeof(g->Message), "Column %s not found in %s", fp->field_name.str, tdbp->GetName()); throw 1; } // endif colp @@ -2293,7 +2294,7 @@ int ha_connect::MakeRecord(char *buf) char buf[256]; THD *thd= ha_thd(); - sprintf(buf, "Out of range value %.140s for column '%s' at row %ld", + snprintf(buf, sizeof(buf), "Out of range value %.140s for column '%s' at row %ld", value->GetCharString(val), fp->field_name.str, thd->get_stmt_da()->current_row_for_warning()); @@ -2575,7 +2576,7 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, PSTRG qry, OPVAL vop, char q, op= OP_LE; break; default: - sprintf(g->Message, "cannot handle flag %d", ranges[i]->flag); + snprintf(g->Message, sizeof(g->Message), "cannot handle flag %d", ranges[i]->flag); goto err; } // endswitch flag @@ -4897,7 +4898,7 @@ int ha_connect::external_lock(THD *thd, int lock_type) && sqlcom != SQLCOM_FLUSH && sqlcom != SQLCOM_BEGIN && sqlcom != SQLCOM_DROP_TABLE) { - sprintf(g->Message, "external_lock: unexpected command %d", sqlcom); + snprintf(g->Message, sizeof(g->Message), "external_lock: unexpected command %d", sqlcom); push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message); DBUG_RETURN(0); } else if (g->Xchk) { @@ -4907,7 +4908,7 @@ int ha_connect::external_lock(THD *thd, int lock_type) push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message); DBUG_RETURN(0); } else if (!tdbp->GetDef()->Indexable()) { - sprintf(g->Message, "external_lock: Table %s is not indexable", tdbp->GetName()); + snprintf(g->Message, sizeof(g->Message), "external_lock: Table %s is not indexable", tdbp->GetName()); // DBUG_RETURN(HA_ERR_INTERNAL_ERROR); causes assert error push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message); DBUG_RETURN(0); @@ -5818,7 +5819,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, #endif // PROMPT_OK } else if (!dsn) { - sprintf(g->Message, "Missing %s connection string", topt->type); + snprintf(g->Message, sizeof(g->Message), "Missing %s connection string", topt->type); } else { // Store ODBC additional parameters sop= (POPARM)PlugSubAlloc(g, NULL, sizeof(ODBCPARM)); @@ -5873,9 +5874,9 @@ static int connect_assisted_discovery(handlerton *, THD* thd, // fall through case TAB_CSV: if (!fn && fnc != FNC_NO) - sprintf(g->Message, "Missing %s file name", topt->type); + snprintf(g->Message, sizeof(g->Message), "Missing %s file name", topt->type); else if (sep && strlen(sep) > 1) - sprintf(g->Message, "Invalid separator %s", sep); + snprintf(g->Message, sizeof(g->Message), "Invalid separator %s", sep); else ok= true; @@ -5933,7 +5934,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, case TAB_OCCUR: if (!src && !stricmp(tab, create_info->alias.str) && (!db || !stricmp(db, table_s->db.str))) - sprintf(g->Message, "A %s table cannot refer to itself", topt->type); + snprintf(g->Message, sizeof(g->Message), "A %s table cannot refer to itself", topt->type); else ok= true; @@ -5955,7 +5956,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, dsn= strz(g, create_info->connect_string); if (!fn && !zfn && !mul && !dsn) - sprintf(g->Message, "Missing %s file name", topt->type); + snprintf(g->Message, sizeof(g->Message), "Missing %s file name", topt->type); else if (dsn && !topt->tabname) topt->tabname= tab; @@ -5982,13 +5983,13 @@ static int connect_assisted_discovery(handlerton *, THD* thd, ok= true; break; default: - sprintf(g->Message, "Cannot get column info for table type %s", topt->type); + snprintf(g->Message, sizeof(g->Message), "Cannot get column info for table type %s", topt->type); break; } // endif ttp // Check for supported catalog function if (ok && !(supfnc & fnc)) { - sprintf(g->Message, "Unsupported catalog function %s for table type %s", + snprintf(g->Message, sizeof(g->Message), "Unsupported catalog function %s for table type %s", fncn, topt->type); ok= false; } // endif supfnc @@ -6044,7 +6045,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, qrp= ODBCDrivers(g, mxr, true); break; default: - sprintf(g->Message, "invalid catfunc %s", fncn); + snprintf(g->Message, sizeof(g->Message), "invalid catfunc %s", fncn); break; } // endswitch info @@ -6075,7 +6076,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, qrp= JDBCDrivers(g, mxr, true); break; default: - sprintf(g->Message, "invalid catfunc %s", fncn); + snprintf(g->Message, sizeof(g->Message), "invalid catfunc %s", fncn); break; } // endswitch info @@ -6182,9 +6183,9 @@ static int connect_assisted_discovery(handlerton *, THD* thd, // Not a catalog table if (!qrp->Nblin) { if (tab) - sprintf(g->Message, "Cannot get columns from %s", tab); + snprintf(g->Message, sizeof(g->Message), "Cannot get columns from %s", tab); else - strcpy(g->Message, "Fail to retrieve columns"); + strncpy(g->Message, "Fail to retrieve columns", sizeof(g->Message)); rc= HA_ERR_INTERNAL_ERROR; goto err; @@ -6271,7 +6272,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, #if defined(ODBC_SUPPORT) || defined(JAVA_SUPPORT) if ((ttp == TAB_ODBC || ttp == TAB_JDBC) && crp->Kdata) { if (schem && stricmp(schem, crp->Kdata->GetCharValue(i))) { - sprintf(g->Message, + snprintf(g->Message, sizeof(g->Message), "Several %s tables found, specify DBNAME", tab); rc= HA_ERR_INTERNAL_ERROR; goto err; @@ -6293,12 +6294,12 @@ static int connect_assisted_discovery(handlerton *, THD* thd, if (!(plgtyp= TranslateSQLType(typ, dec, prec, v, w))) { if (GetTypeConv() == TPC_SKIP) { // Skip this column - sprintf(g->Message, "Column %s skipped (unsupported type %d)", + snprintf(g->Message, sizeof(g->Message), "Column %s skipped (unsupported type %d)", cnm, typ); push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message); continue; } else { - sprintf(g->Message, "Unsupported SQL type %d", typ); + snprintf(g->Message, sizeof(g->Message), "Unsupported SQL type %d", typ); rc= HA_ERR_INTERNAL_ERROR; goto err; } // endif type_conv @@ -6309,7 +6310,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, switch (typ) { case TYPE_STRING: if (w) { - sprintf(g->Message, "Column %s is wide characters", cnm); + snprintf(g->Message, sizeof(g->Message), "Column %s is wide characters", cnm); push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, 0, g->Message); } // endif w @@ -6335,12 +6336,12 @@ static int connect_assisted_discovery(handlerton *, THD* thd, if (!(plgtyp= TranslateJDBCType(typ, tn, dec, prec, v))) { if (GetTypeConv() == TPC_SKIP) { // Skip this column - sprintf(g->Message, "Column %s skipped (unsupported type %d)", + snprintf(g->Message, sizeof(g->Message), "Column %s skipped (unsupported type %d)", cnm, typ); push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message); continue; } else { - sprintf(g->Message, "Unsupported SQL type %d", typ); + snprintf(g->Message, sizeof(g->Message), "Unsupported SQL type %d", typ); rc= HA_ERR_INTERNAL_ERROR; goto err; } // endif type_conv @@ -6499,13 +6500,13 @@ int ha_connect::create(const char *name, TABLE *table_arg, #endif // REST_SUPPORT (options->tabname) ? "PROXY" : "DOS"; type= GetTypeID(options->type); - sprintf(g->Message, "No table_type. Will be set to %s", options->type); + snprintf(g->Message, sizeof(g->Message), "No table_type. Will be set to %s", options->type); if (sqlcom == SQLCOM_CREATE_TABLE) push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message); } else if (type == TAB_NIY) { - sprintf(g->Message, "Unsupported table type %s", options->type); + snprintf(g->Message, sizeof(g->Message), "Unsupported table type %s", options->type); my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); DBUG_RETURN(HA_ERR_INTERNAL_ERROR); } // endif ttp @@ -6556,7 +6557,7 @@ int ha_connect::create(const char *name, TABLE *table_arg, if (!stricmp(options->tabname, create_info->alias.str) && (!options->dbname || !stricmp(options->dbname, table_arg->s->db.str))) { - sprintf(g->Message, "A %s table cannot refer to itself", + snprintf(g->Message, sizeof(g->Message), "A %s table cannot refer to itself", options->type); my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); DBUG_RETURN(HA_ERR_INTERNAL_ERROR); @@ -6665,7 +6666,7 @@ int ha_connect::create(const char *name, TABLE *table_arg, int pretty= atoi(GetListOption(g, "Pretty", options->oplist, "2")); if (!options->lrecl && pretty != 2) { - sprintf(g->Message, "LRECL must be specified for pretty=%d", pretty); + snprintf(g->Message, sizeof(g->Message), "LRECL must be specified for pretty=%d", pretty); my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); rc= HA_ERR_INTERNAL_ERROR; DBUG_RETURN(rc); @@ -6677,7 +6678,7 @@ int ha_connect::create(const char *name, TABLE *table_arg, const char *sep= options->separator; if (sep && strlen(sep) > 1) { - sprintf(g->Message, "Invalid separator %s", sep); + snprintf(g->Message, sizeof(g->Message), "Invalid separator %s", sep); my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); rc= HA_ERR_INTERNAL_ERROR; DBUG_RETURN(rc); @@ -6700,7 +6701,7 @@ int ha_connect::create(const char *name, TABLE *table_arg, } // endif flags if (fp->flags & (BLOB_FLAG | ENUM_FLAG | SET_FLAG)) { - sprintf(g->Message, "Unsupported type for column %s", + snprintf(g->Message, sizeof(g->Message), "Unsupported type for column %s", fp->field_name.str); my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); rc= HA_ERR_INTERNAL_ERROR; @@ -6737,7 +6738,7 @@ int ha_connect::create(const char *name, TABLE *table_arg, case MYSQL_TYPE_STRING: #if 0 if (!fp->field_length) { - sprintf(g->Message, "Unsupported 0 length for column %s", + snprintf(g->Message, sizeof(g->Message), "Unsupported 0 length for column %s", fp->field_name.str); rc= HA_ERR_INTERNAL_ERROR; my_printf_error(ER_UNKNOWN_ERROR, @@ -6758,7 +6759,7 @@ int ha_connect::create(const char *name, TABLE *table_arg, case MYSQL_TYPE_GEOMETRY: default: // fprintf(stderr, "Unsupported type column %s\n", fp->field_name.str); - sprintf(g->Message, "Unsupported type for column %s", + snprintf(g->Message, sizeof(g->Message), "Unsupported type for column %s", fp->field_name.str); rc= HA_ERR_INTERNAL_ERROR; my_printf_error(ER_UNKNOWN_ERROR, "Unsupported type for column %s", @@ -6778,10 +6779,10 @@ int ha_connect::create(const char *name, TABLE *table_arg, bool b= false; if ((b= fp->field_name.length > 10)) - sprintf(g->Message, "DBF: Column name '%s' is too long (max=10)", + snprintf(g->Message, sizeof(g->Message), "DBF: Column name '%s' is too long (max=10)", fp->field_name.str); else if ((b= fp->field_length > 255)) - sprintf(g->Message, "DBF: Column length too big for '%s' (max=255)", + snprintf(g->Message, sizeof(g->Message), "DBF: Column length too big for '%s' (max=255)", fp->field_name.str); if (b) { @@ -6844,7 +6845,7 @@ int ha_connect::create(const char *name, TABLE *table_arg, *p= 0; } else { strcat(strcat(strcpy(buf, GetTableName()), "."), lwt); - sprintf(g->Message, "No file name. Table will use %s", buf); + snprintf(g->Message, sizeof(g->Message), "No file name. Table will use %s", buf); if (sqlcom == SQLCOM_CREATE_TABLE) push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message); @@ -6856,9 +6857,9 @@ int ha_connect::create(const char *name, TABLE *table_arg, if ((h= ::open(fn, O_CREAT | O_EXCL, 0666)) == -1) { if (errno == EEXIST) - sprintf(g->Message, "Default file %s already exists", fn); + snprintf(g->Message, sizeof(g->Message), "Default file %s already exists", fn); else - sprintf(g->Message, "Error %d creating file %s", errno, fn); + snprintf(g->Message, sizeof(g->Message), "Error %d creating file %s", errno, fn); push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message); } else @@ -6921,7 +6922,7 @@ int ha_connect::create(const char *name, TABLE *table_arg, if (g->Alchecked == 0 && (!IsFileType(type) || FileExists(options->filename, false))) { if (part_info) { - sprintf(g->Message, "Data repartition in %s is unchecked", partname); + snprintf(g->Message, sizeof(g->Message), "Data repartition in %s is unchecked", partname); push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message); } else if (sqlcom == SQLCOM_ALTER_TABLE) { // This is an ALTER to CONNECT from another engine. @@ -6973,7 +6974,7 @@ int ha_connect::create(const char *name, TABLE *table_arg, } // endif Check } else if (!GetIndexType(type)) { - sprintf(g->Message, "Table type %s is not indexable", options->type); + snprintf(g->Message, sizeof(g->Message), "Table type %s is not indexable", options->type); my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); rc= HA_ERR_UNSUPPORTED; } // endif index type @@ -7006,8 +7007,8 @@ bool ha_connect::FileExists(const char *fn, bool bf) if (table) { const char *s; - char tfn[_MAX_PATH], filename[_MAX_PATH], path[_MAX_PATH]; - bool b= false; + char tfn[_MAX_PATH], filename[_MAX_PATH], path[_MAX_PATH]; + bool b= false; int n; struct stat info; @@ -7017,7 +7018,7 @@ bool ha_connect::FileExists(const char *fn, bool bf) s= "/"; #endif // !_WIN32 if (IsPartitioned()) { - sprintf(tfn, fn, GetPartName()); + snprintf(tfn, sizeof(tfn), fn, GetPartName()); // This is to avoid an initialization error raised by the // test on check_table_flags made in ha_partition::open @@ -7034,7 +7035,7 @@ bool ha_connect::FileExists(const char *fn, bool bf) if (errno != ENOENT) { char buf[_MAX_PATH + 20]; - sprintf(buf, "Error %d for file %s", errno, filename); + snprintf(buf, sizeof(buf), "Error %d for file %s", errno, filename); push_warning(table->in_use, Sql_condition::WARN_LEVEL_WARN, 0, buf); return true; } else @@ -7262,7 +7263,7 @@ ha_connect::check_if_supported_inplace_alter(TABLE *altered_table, } // endif Check } else if (!GetIndexType(type)) { - sprintf(g->Message, "Table type %s is not indexable", oldopt->type); + snprintf(g->Message, sizeof(g->Message), "Table type %s is not indexable", oldopt->type); my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); DBUG_RETURN(HA_ALTER_ERROR); } // endif index type |