Changeset 389

Show
Ignore:
Timestamp:
02/19/10 04:13:07 (7 months ago)
Author:
walter
Message:

test AA's for equality; tighten security on file imports

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/dmd-1.x/src/e2ir.c

    r266 r389  
    20252025#endif 
    20262026    e = el_bin(OPcall, TYint, el_var(rtlsym[rtlfunc]), ep); 
    20272027    if (op == TOKnotequal) 
    20282028        e = el_bin(OPxor, TYint, e, el_long(TYint, 1)); 
    20292029    el_setLoc(e,loc); 
     2030    } 
     2031    else if (t1->ty == Taarray && t2->ty == Taarray) 
     2032    {   TypeAArray *taa = (TypeAArray *)t1; 
     2033    Symbol *s = taa->aaGetSymbol("Equal", 0); 
     2034    elem *ti = taa->getTypeInfo(NULL)->toElem(irs); 
     2035    elem *ea1 = e1->toElem(irs); 
     2036    elem *ea2 = e2->toElem(irs); 
     2037    // aaEqual(ti, e1, e2) 
     2038    elem *ep = el_params(ea2, ea1, ti, NULL); 
     2039    e = el_bin(OPcall, TYnptr, el_var(s), ep); 
     2040    if (op == TOKnotequal) 
     2041        e = el_bin(OPxor, TYint, e, el_long(TYint, 1)); 
     2042    el_setLoc(e,loc); 
     2043    return e; 
    20302044    } 
    20312045    else 
    20322046    e = toElemBin(irs, eop); 
    20332047    return e; 
    20342048} 
  • branches/dmd-1.x/src/expression.c

    r382 r389  
    52555255    name = (char *)se->string; 
    52565256 
    52575257    if (!global.params.fileImppath) 
    52585258    {   error("need -Jpath switch to import text file %s", name); 
    52595259    goto Lerror; 
     5260    } 
     5261 
     5262    /* Be wary of CWE-22: Improper Limitation of a Pathname to a Restricted Directory 
     5263     * ('Path Traversal') attacks. 
     5264     * http://cwe.mitre.org/data/definitions/22.html 
     5265     */ 
     5266 
     5267    /* Do harsh sanitizing by limiting the name's character set. 
     5268     */ 
     5269    for (const char *p = name; *p; p++) 
     5270    { 
     5271    if (!(isalnum(*p) || *p == '.' || *p == '_')) 
     5272    { 
     5273        error("file name characters are restricted to [a-zA-Z0-9._] not '%c'", *p); 
     5274        goto Lerror; 
     5275    } 
    52605276    } 
    52615277 
    52625278    if (name != FileName::name(name)) 
    52635279    {   error("use -Jpath switch to provide path for filename %s", name); 
    52645280    goto Lerror; 
  • trunk/src/e2ir.c

    r368 r389  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2009 by Digital Mars 
     3// Copyright (c) 1999-2010 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
    66// http://www.digitalmars.com 
    77// License for redistribution is by either the Artistic License 
    88// in artistic.txt, or the GNU General Public License in gnu.txt. 
     
    23102310#endif 
    23112311    e = el_bin(OPcall, TYint, el_var(rtlsym[rtlfunc]), ep); 
    23122312    if (op == TOKnotequal) 
    23132313        e = el_bin(OPxor, TYint, e, el_long(TYint, 1)); 
    23142314    el_setLoc(e,loc); 
     2315    } 
     2316    else if (t1->ty == Taarray && t2->ty == Taarray) 
     2317    {   TypeAArray *taa = (TypeAArray *)t1; 
     2318    Symbol *s = taa->aaGetSymbol("Equal", 0); 
     2319    elem *ti = taa->getTypeInfo(NULL)->toElem(irs); 
     2320    elem *ea1 = e1->toElem(irs); 
     2321    elem *ea2 = e2->toElem(irs); 
     2322    // aaEqual(ti, e1, e2) 
     2323    elem *ep = el_params(ea2, ea1, ti, NULL); 
     2324    e = el_bin(OPcall, TYnptr, el_var(s), ep); 
     2325    if (op == TOKnotequal) 
     2326        e = el_bin(OPxor, TYint, e, el_long(TYint, 1)); 
     2327    el_setLoc(e,loc); 
     2328    return e; 
    23152329    } 
    23162330    else 
    23172331    e = toElemBin(irs, eop); 
    23182332    return e; 
    23192333} 
  • trunk/src/expression.c

    r382 r389  
    55995599    if (!global.params.fileImppath) 
    56005600    {   error("need -Jpath switch to import text file %s", name); 
    56015601    goto Lerror; 
    56025602    } 
    56035603 
     5604    /* Be wary of CWE-22: Improper Limitation of a Pathname to a Restricted Directory 
     5605     * ('Path Traversal') attacks. 
     5606     * http://cwe.mitre.org/data/definitions/22.html 
     5607     */ 
     5608 
     5609    /* Do harsh sanitizing by limiting the name's character set. 
     5610     */ 
     5611    for (const char *p = name; *p; p++) 
     5612    { 
     5613    if (!(isalnum(*p) || *p == '.' || *p == '_')) 
     5614    { 
     5615        error("file name characters are restricted to [a-zA-Z0-9._] not '%c'", *p); 
     5616        goto Lerror; 
     5617    } 
     5618    } 
     5619 
    56045620    if (name != FileName::name(name)) 
    56055621    {   error("use -Jpath switch to provide path for filename %s", name); 
    56065622    goto Lerror; 
    56075623    } 
    56085624