~ubuntu-branches/ubuntu/natty/mysql-5.1/natty-proposed

« back to all changes in this revision

Viewing changes to sql/sql_view.cc

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 08:30:45 UTC
  • mfrom: (1.4.1)
  • Revision ID: package-import@ubuntu.com-20120222083045-2rd53r4bnyx7qus4
Tags: 5.1.61-0ubuntu0.11.04.1
* SECURITY UPDATE: Update to 5.1.61 to fix multiple security issues
  (LP: #937869)
  - http://www.oracle.com/technetwork/topics/security/cpujan2012-366304.html
  - CVE-2011-2262
  - CVE-2012-0075
  - CVE-2012-0112
  - CVE-2012-0113
  - CVE-2012-0114
  - CVE-2012-0115
  - CVE-2012-0116
  - CVE-2012-0117
  - CVE-2012-0118
  - CVE-2012-0119
  - CVE-2012-0120
  - CVE-2012-0484
  - CVE-2012-0485
  - CVE-2012-0486
  - CVE-2012-0487
  - CVE-2012-0488
  - CVE-2012-0489
  - CVE-2012-0490
  - CVE-2012-0491
  - CVE-2012-0492
  - CVE-2012-0493
  - CVE-2012-0494
  - CVE-2012-0495
  - CVE-2012-0496

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2004 MySQL AB
 
1
/* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
2
2
 
3
3
   This program is free software; you can redistribute it and/or modify
4
4
   it under the terms of the GNU General Public License as published by
545
545
  }
546
546
 
547
547
  /* prepare select to resolve all fields */
548
 
  lex->view_prepare_mode= 1;
 
548
  lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_VIEW;
549
549
  if (unit->prepare(thd, 0, 0))
550
550
  {
551
551
    /*
1255
1255
    TABLE_LIST *view_tables= lex->query_tables;
1256
1256
    TABLE_LIST *view_tables_tail= 0;
1257
1257
    TABLE_LIST *tbl;
 
1258
    Security_context *security_ctx;
1258
1259
 
1259
1260
    /*
1260
1261
      Check rights to run commands (EXPLAIN SELECT & SHOW CREATE) which show
1264
1265
    if (!table->prelocking_placeholder &&
1265
1266
        (old_lex->sql_command == SQLCOM_SELECT && old_lex->describe))
1266
1267
    {
1267
 
      if (check_table_access(thd, SELECT_ACL, view_tables, UINT_MAX, TRUE) &&
1268
 
          check_table_access(thd, SHOW_VIEW_ACL, table, UINT_MAX, TRUE))
 
1268
      /*
 
1269
        The user we run EXPLAIN as (either the connected user who issued
 
1270
        the EXPLAIN statement, or the definer of a SUID stored routine
 
1271
        which contains the EXPLAIN) should have both SHOW_VIEW_ACL and
 
1272
        SELECT_ACL on the view being opened as well as on all underlying
 
1273
        views since EXPLAIN will disclose their structure. This user also
 
1274
        should have SELECT_ACL on all underlying tables of the view since
 
1275
        this EXPLAIN will disclose information about the number of rows in it.
 
1276
 
 
1277
        To perform this privilege check we create auxiliary TABLE_LIST object
 
1278
        for the view in order a) to avoid trashing "table->grant" member for
 
1279
        original table list element, which contents can be important at later
 
1280
        stage for column-level privilege checking b) get TABLE_LIST object
 
1281
        with "security_ctx" member set to 0, i.e. forcing check_table_access()
 
1282
        to use active user's security context.
 
1283
 
 
1284
        There is no need for creating similar copies of TABLE_LIST elements
 
1285
        for underlying tables since they just have been constructed and thus
 
1286
        have TABLE_LIST::security_ctx == 0 and fresh TABLE_LIST::grant member.
 
1287
 
 
1288
        Finally at this point making sure we have SHOW_VIEW_ACL on the views
 
1289
        will suffice as we implicitly require SELECT_ACL anyway.
 
1290
      */
 
1291
        
 
1292
      TABLE_LIST view_no_suid;
 
1293
      bzero(static_cast<void *>(&view_no_suid), sizeof(TABLE_LIST));
 
1294
      view_no_suid.db= table->db;
 
1295
      view_no_suid.table_name= table->table_name;
 
1296
 
 
1297
      DBUG_ASSERT(view_tables == NULL || view_tables->security_ctx == NULL);
 
1298
 
 
1299
      if (check_table_access(thd, SELECT_ACL, view_tables, UINT_MAX, TRUE) ||
 
1300
          check_table_access(thd, SHOW_VIEW_ACL, &view_no_suid, UINT_MAX, TRUE))
1269
1301
      {
1270
1302
        my_message(ER_VIEW_NO_EXPLAIN, ER(ER_VIEW_NO_EXPLAIN), MYF(0));
1271
1303
        goto err;
1396
1428
    if (table->view_suid)
1397
1429
    {
1398
1430
      /*
1399
 
        Prepare a security context to check underlying objects of the view
 
1431
        For suid views prepare a security context for checking underlying
 
1432
        objects of the view.
1400
1433
      */
1401
1434
      if (!(table->view_sctx= (Security_context *)
1402
1435
            thd->stmt_arena->alloc(sizeof(Security_context))))
1403
1436
        goto err;
1404
 
      /* Assign the context to the tables referenced in the view */
1405
 
      if (view_tables)
1406
 
      {
1407
 
        DBUG_ASSERT(view_tables_tail);
1408
 
        for (tbl= view_tables; tbl != view_tables_tail->next_global;
1409
 
             tbl= tbl->next_global)
1410
 
          tbl->security_ctx= table->view_sctx;
1411
 
      }
1412
 
      /* assign security context to SELECT name resolution contexts of view */
1413
 
      for(SELECT_LEX *sl= lex->all_selects_list;
1414
 
          sl;
1415
 
          sl= sl->next_select_in_list())
1416
 
        sl->context.security_ctx= table->view_sctx;
1417
 
    }
 
1437
      security_ctx= table->view_sctx;
 
1438
    }
 
1439
    else
 
1440
    {
 
1441
      /*
 
1442
        For non-suid views inherit security context from view's table list.
 
1443
        This allows properly handle situation when non-suid view is used
 
1444
        from within suid view.
 
1445
      */
 
1446
      security_ctx= table->security_ctx;
 
1447
    }
 
1448
 
 
1449
    /* Assign the context to the tables referenced in the view */
 
1450
    if (view_tables)
 
1451
    {
 
1452
      DBUG_ASSERT(view_tables_tail);
 
1453
      for (tbl= view_tables; tbl != view_tables_tail->next_global;
 
1454
           tbl= tbl->next_global)
 
1455
        tbl->security_ctx= security_ctx;
 
1456
    }
 
1457
 
 
1458
    /* assign security context to SELECT name resolution contexts of view */
 
1459
    for(SELECT_LEX *sl= lex->all_selects_list;
 
1460
        sl;
 
1461
        sl= sl->next_select_in_list())
 
1462
      sl->context.security_ctx= security_ctx;
1418
1463
 
1419
1464
    /*
1420
1465
      Setup an error processor to hide error messages issued by stored