Ignore:
Timestamp:
Jun 29, 2011, 7:36:41 AM (14 years ago)
Author:
Herwig Bauernfeind
Message:

Samba 3.5: Update vendor to version 3.5.6

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/libsmb/nmblib.c

    r414 r587  
    12381238/****************************************************************************
    12391239 Interpret the weird netbios "name" into a unix fstring. Return the name type.
     1240 Returns -1 on error.
    12401241****************************************************************************/
    12411242
    1242 static int name_interpret(char *in, fstring name)
    1243 {
     1243static int name_interpret(unsigned char *buf, size_t buf_len,
     1244                unsigned char *in, fstring name)
     1245{
     1246        unsigned char *end_ptr = buf + buf_len;
    12441247        int ret;
    1245         int len = (*in++) / 2;
     1248        unsigned int len;
    12461249        fstring out_string;
    1247         char *out = out_string;
     1250        unsigned char *out = (unsigned char *)out_string;
    12481251
    12491252        *out=0;
    12501253
    1251         if (len > 30 || len<1)
    1252                 return(0);
     1254        if (in >= end_ptr) {
     1255                return -1;
     1256        }
     1257        len = (*in++) / 2;
     1258
     1259        if (len<1) {
     1260                return -1;
     1261        }
    12531262
    12541263        while (len--) {
     1264                if (&in[1] >= end_ptr) {
     1265                        return -1;
     1266                }
    12551267                if (in[0] < 'A' || in[0] > 'P' || in[1] < 'A' || in[1] > 'P') {
    12561268                        *out = 0;
     
    12601272                in += 2;
    12611273                out++;
     1274                if (PTR_DIFF(out,out_string) >= sizeof(fstring)) {
     1275                        return -1;
     1276                }
    12621277        }
    12631278        ret = out[-1];
    12641279        out[-1] = 0;
    12651280
    1266 #ifdef NETBIOS_SCOPE
    1267         /* Handle any scope names */
    1268         while(*in) {
    1269                 *out++ = '.'; /* Scope names are separated by periods */
    1270                 len = *(unsigned char *)in++;
    1271                 StrnCpy(out, in, len);
    1272                 out += len;
    1273                 *out=0;
    1274                 in += len;
    1275         }
    1276 #endif
    12771281        pull_ascii_fstring(name, out_string);
    12781282
     
    13531357****************************************************************************/
    13541358
    1355 static char *name_ptr(char *buf,int ofs)
    1356 {
    1357         unsigned char c = *(unsigned char *)(buf+ofs);
    1358 
     1359static unsigned char *name_ptr(unsigned char *buf, size_t buf_len, unsigned int ofs)
     1360{
     1361        unsigned char c = 0;
     1362
     1363        if (ofs > buf_len || buf_len < 1) {
     1364                return NULL;
     1365        }
     1366
     1367        c = *(unsigned char *)(buf+ofs);
    13591368        if ((c & 0xC0) == 0xC0) {
    1360                 uint16 l = RSVAL(buf, ofs) & 0x3FFF;
     1369                uint16 l = 0;
     1370
     1371                if (ofs > buf_len - 1) {
     1372                        return NULL;
     1373                }
     1374                l = RSVAL(buf, ofs) & 0x3FFF;
     1375                if (l > buf_len) {
     1376                        return NULL;
     1377                }
    13611378                DEBUG(5,("name ptr to pos %d from %d is %s\n",l,ofs,buf+l));
    13621379                return(buf + l);
     
    13681385/****************************************************************************
    13691386 Extract a netbios name from a buf (into a unix string) return name type.
     1387 Returns -1 on error.
    13701388****************************************************************************/
    13711389
    1372 int name_extract(char *buf,int ofs, fstring name)
    1373 {
    1374         char *p = name_ptr(buf,ofs);
    1375         int d = PTR_DIFF(p,buf+ofs);
     1390int name_extract(unsigned char *buf, size_t buf_len, unsigned int ofs, fstring name)
     1391{
     1392        unsigned char *p = name_ptr(buf,buf_len,ofs);
    13761393
    13771394        name[0] = '\0';
    1378         if (d < -50 || d > 50)
    1379                 return(0);
    1380         return(name_interpret(p,name));
     1395        if (p == NULL) {
     1396                return -1;
     1397        }
     1398        return(name_interpret(buf,buf_len,p,name));
    13811399}
    13821400
    13831401/****************************************************************************
    13841402 Return the total storage length of a mangled name.
     1403 Returns -1 on error.
    13851404****************************************************************************/
    13861405
    1387 int name_len(char *s1)
     1406int name_len(unsigned char *s1, size_t buf_len)
    13881407{
    13891408        /* NOTE: this argument _must_ be unsigned */
    13901409        unsigned char *s = (unsigned char *)s1;
    1391         int len;
    1392 
     1410        int len = 0;
     1411
     1412        if (buf_len < 1) {
     1413                return -1;
     1414        }
    13931415        /* If the two high bits of the byte are set, return 2. */
    1394         if (0xC0 == (*s & 0xC0))
     1416        if (0xC0 == (*s & 0xC0)) {
     1417                if (buf_len < 2) {
     1418                        return -1;
     1419                }
    13951420                return(2);
     1421        }
    13961422
    13971423        /* Add up the length bytes. */
    13981424        for (len = 1; (*s); s += (*s) + 1) {
    13991425                len += *s + 1;
    1400                 SMB_ASSERT(len < 80);
     1426                if (len > buf_len) {
     1427                        return -1;
     1428                }
    14011429        }
    14021430
Note: See TracChangeset for help on using the changeset viewer.