~ubuntu-branches/ubuntu/precise/mapserver/precise-security

« back to all changes in this revision

Viewing changes to maplayer.c

  • Committer: Package Import Robot
  • Author(s): Jamie Strandboge
  • Date: 2011-09-09 09:46:09 UTC
  • Revision ID: package-import@ubuntu.com-20110909094609-iituzvjk5w0v57w2
Tags: 5.6.6-1.1ubuntu1
* SECURITY UPDATE: SQL Injection and buffer overflows (LP: #809133)
  - debian/patches/wfs_sql_injection.dpatch: Fix possible WFS SQL injection
    and buffer overflows in OGC Filter Encoding support. Patch from Natty
    refreshed for Oneiric.
  - http://trac.osgeo.org/mapserver/ticket/3874
  - http://trac.osgeo.org/mapserver/ticket/3903]
  - CVE-2011-2703, CVE-2011-2704

Show diffs side-by-side

added added

removed removed

Lines of Context:
1051
1051
  return MS_FAILURE;
1052
1052
}
1053
1053
 
 
1054
/************************************************************************/
 
1055
/*                          LayerDefaultEscapeSQLParam                  */
 
1056
/*                                                                      */
 
1057
/*      Default function used to escape strings and avoid sql           */
 
1058
/*      injection. Specific drivers should redefine if an escaping      */
 
1059
/*      function is available in the driver.                            */
 
1060
/************************************************************************/
 
1061
char *LayerDefaultEscapeSQLParam(layerObj *layer, const char* pszString)
 
1062
{
 
1063
     char *pszEscapedStr=NULL;
 
1064
     if (pszString)
 
1065
     {
 
1066
         int nSrcLen;
 
1067
         char c;
 
1068
         int i=0, j=0;
 
1069
         nSrcLen = (int)strlen(pszString);
 
1070
         pszEscapedStr = (char*) malloc( 2 * nSrcLen + 1);
 
1071
         for(i = 0, j = 0; i < nSrcLen; i++)
 
1072
         {
 
1073
             c = pszString[i];
 
1074
             if (c == '\'')
 
1075
             {
 
1076
                 pszEscapedStr[j++] = '\'';
 
1077
                 pszEscapedStr[j++] = '\'';
 
1078
             }
 
1079
             else if (c == '\\')
 
1080
             {
 
1081
                 pszEscapedStr[j++] = '\\';
 
1082
                 pszEscapedStr[j++] = '\\';
 
1083
             }
 
1084
             else
 
1085
               pszEscapedStr[j++] = c;
 
1086
         }
 
1087
         pszEscapedStr[j] = 0;
 
1088
     }  
 
1089
     return pszEscapedStr;
 
1090
}
 
1091
 
 
1092
/************************************************************************/
 
1093
/*                          LayerDefaultEscapePropertyName              */
 
1094
/*                                                                      */
 
1095
/*      Return the property name in a properly escaped and quoted form. */
 
1096
/************************************************************************/
 
1097
char *LayerDefaultEscapePropertyName(layerObj *layer, const char* pszString)
 
1098
{
 
1099
     char* pszEscapedStr=NULL;
 
1100
     int i, j = 0;   
 
1101
 
 
1102
     if (layer && pszString && strlen(pszString) > 0)
 
1103
     {
 
1104
         int nLength = strlen(pszString);
 
1105
 
 
1106
         pszEscapedStr = (char*) malloc( 1 + 2 * nLength + 1 + 1);
 
1107
         pszEscapedStr[j++] = '"';
 
1108
 
 
1109
         for (i=0; i<nLength; i++)
 
1110
         {
 
1111
             char c = pszString[i];
 
1112
             if (c == '"')
 
1113
             {
 
1114
                 pszEscapedStr[j++] = '"';
 
1115
                 pszEscapedStr[j++] ='"';
 
1116
             }
 
1117
             else if (c == '\\')
 
1118
             {
 
1119
                 pszEscapedStr[j++] = '\\';
 
1120
                 pszEscapedStr[j++] = '\\';
 
1121
             }
 
1122
             else
 
1123
               pszEscapedStr[j++] = c;
 
1124
         }
 
1125
         pszEscapedStr[j++] = '"';
 
1126
         pszEscapedStr[j++] = 0;
 
1127
        
 
1128
     }
 
1129
     return pszEscapedStr;
 
1130
}
 
1131
 
 
1132
 
1054
1133
/*
1055
1134
 * msConnectLayer
1056
1135
 *
1108
1187
    
1109
1188
  vtable->LayerGetNumFeatures = LayerDefaultGetNumFeatures;
1110
1189
 
 
1190
  vtable->LayerEscapeSQLParam = LayerDefaultEscapeSQLParam;
 
1191
 
 
1192
  vtable->LayerEscapePropertyName = LayerDefaultEscapePropertyName;
 
1193
 
1111
1194
  return MS_SUCCESS;
1112
1195
}
1113
1196
 
1280
1363
    return i;
1281
1364
}
1282
1365
 
 
1366
 
 
1367
 
 
1368
/*
 
1369
Returns an escaped string
 
1370
*/
 
1371
char  *msLayerEscapeSQLParam(layerObj *layer, const char*pszString) 
 
1372
{
 
1373
    if ( ! layer->vtable) {
 
1374
        int rv =  msInitializeVirtualTable(layer);
 
1375
        if (rv != MS_SUCCESS)
 
1376
            return "";
 
1377
    }
 
1378
    return layer->vtable->LayerEscapeSQLParam(layer, pszString);
 
1379
}
 
1380
 
 
1381
char  *msLayerEscapePropertyName(layerObj *layer, const char*pszString) 
 
1382
{
 
1383
    if ( ! layer->vtable) {
 
1384
        int rv =  msInitializeVirtualTable(layer);
 
1385
        if (rv != MS_SUCCESS)
 
1386
            return "";
 
1387
    }
 
1388
    return layer->vtable->LayerEscapePropertyName(layer, pszString);
 
1389
}
 
1390
 
 
1391
 
1283
1392
int
1284
1393
msINLINELayerInitializeVirtualTable(layerObj *layer)
1285
1394
{
1312
1421
    /* layer->vtable->LayerCreateItems, use default */
1313
1422
    layer->vtable->LayerGetNumFeatures = msINLINELayerGetNumFeatures;
1314
1423
 
 
1424
    /*layer->vtable->LayerEscapeSQLParam, use default*/
 
1425
    /*layer->vtable->LayerEscapePropertyName, use default*/
1315
1426
    return MS_SUCCESS;
1316
1427
}