Changeset 587 for vendor/current/source3/libsmb/nmblib.c
- Timestamp:
- Jun 29, 2011, 7:36:41 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/libsmb/nmblib.c
r414 r587 1238 1238 /**************************************************************************** 1239 1239 Interpret the weird netbios "name" into a unix fstring. Return the name type. 1240 Returns -1 on error. 1240 1241 ****************************************************************************/ 1241 1242 1242 static int name_interpret(char *in, fstring name) 1243 { 1243 static 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; 1244 1247 int ret; 1245 int len = (*in++) / 2;1248 unsigned int len; 1246 1249 fstring out_string; 1247 char *out =out_string;1250 unsigned char *out = (unsigned char *)out_string; 1248 1251 1249 1252 *out=0; 1250 1253 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 } 1253 1262 1254 1263 while (len--) { 1264 if (&in[1] >= end_ptr) { 1265 return -1; 1266 } 1255 1267 if (in[0] < 'A' || in[0] > 'P' || in[1] < 'A' || in[1] > 'P') { 1256 1268 *out = 0; … … 1260 1272 in += 2; 1261 1273 out++; 1274 if (PTR_DIFF(out,out_string) >= sizeof(fstring)) { 1275 return -1; 1276 } 1262 1277 } 1263 1278 ret = out[-1]; 1264 1279 out[-1] = 0; 1265 1280 1266 #ifdef NETBIOS_SCOPE1267 /* 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 #endif1277 1281 pull_ascii_fstring(name, out_string); 1278 1282 … … 1353 1357 ****************************************************************************/ 1354 1358 1355 static char *name_ptr(char *buf,int ofs) 1356 { 1357 unsigned char c = *(unsigned char *)(buf+ofs); 1358 1359 static 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); 1359 1368 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 } 1361 1378 DEBUG(5,("name ptr to pos %d from %d is %s\n",l,ofs,buf+l)); 1362 1379 return(buf + l); … … 1368 1385 /**************************************************************************** 1369 1386 Extract a netbios name from a buf (into a unix string) return name type. 1387 Returns -1 on error. 1370 1388 ****************************************************************************/ 1371 1389 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); 1390 int 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); 1376 1393 1377 1394 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)); 1381 1399 } 1382 1400 1383 1401 /**************************************************************************** 1384 1402 Return the total storage length of a mangled name. 1403 Returns -1 on error. 1385 1404 ****************************************************************************/ 1386 1405 1387 int name_len( char *s1)1406 int name_len(unsigned char *s1, size_t buf_len) 1388 1407 { 1389 1408 /* NOTE: this argument _must_ be unsigned */ 1390 1409 unsigned char *s = (unsigned char *)s1; 1391 int len; 1392 1410 int len = 0; 1411 1412 if (buf_len < 1) { 1413 return -1; 1414 } 1393 1415 /* 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 } 1395 1420 return(2); 1421 } 1396 1422 1397 1423 /* Add up the length bytes. */ 1398 1424 for (len = 1; (*s); s += (*s) + 1) { 1399 1425 len += *s + 1; 1400 SMB_ASSERT(len < 80); 1426 if (len > buf_len) { 1427 return -1; 1428 } 1401 1429 } 1402 1430
Note:
See TracChangeset
for help on using the changeset viewer.