| 1366 | */ |
| 1367 | |
| 1368 | static size_t escape_string_hide_passwords(const char *str, unsigned int len, |
| 1369 | char *result, size_t result_len, |
| 1370 | const char *word1, size_t word1_len, |
| 1371 | const char *word2, size_t word2_len, |
| 1372 | const char *word0, size_t word0_len, |
| 1373 | char chr0) |
| 1374 | { |
| 1375 | const char *res_start= result; |
| 1376 | const char *res_end= result + result_len - 2; |
| 1377 | size_t d_len; |
| 1378 | |
| 1379 | while (len) |
| 1380 | { |
| 1381 | int word1_found= (word1 && len > word1_len + 1 && |
| 1382 | strncasecmp(str, word1, word1_len) == 0); |
| 1383 | int word0_found= (word0 && len > word0_len + 1 && |
| 1384 | strncasecmp(str, word0, word0_len) == 0); |
| 1385 | if (word1_found || word0_found) |
| 1386 | { |
| 1387 | const char *next_s; |
| 1388 | size_t c; |
| 1389 | |
| 1390 | if (word0_found) |
| 1391 | { |
| 1392 | next_s= str + word0_len; |
| 1393 | if (chr0) |
| 1394 | { |
| 1395 | SKIP_SPACES(next_s); |
| 1396 | if (len < (size_t)(next_s - str) + 1 + 1 || |
| 1397 | next_s[0] != chr0) |
| 1398 | goto no_password; |
| 1399 | next_s++; |
| 1400 | } |
| 1401 | while (*next_s && *next_s != '\'' && *next_s != '"') |
| 1402 | ++next_s; |
| 1403 | } |
| 1404 | else |
| 1405 | { |
| 1406 | next_s= str + word1_len; |
| 1407 | if (word2) |
| 1408 | { |
| 1409 | SKIP_SPACES(next_s); |
| 1410 | if (len < (next_s - str) + word2_len + 1 || |
| 1411 | strncasecmp(next_s, word2, word2_len) != 0) |
| 1412 | goto no_password; |
| 1413 | next_s+= word2_len; |
| 1414 | } |
| 1415 | |
| 1416 | while (*next_s && *next_s != '\'' && *next_s != '"') |
| 1417 | ++next_s; |
| 1418 | } |
| 1419 | |
| 1420 | d_len= next_s - str; |
| 1421 | if (result + d_len + 5 > res_end) |
| 1422 | break; |
| 1423 | |
| 1424 | for (c=0; c<d_len; c++) |
| 1425 | result[c]= is_space(str[c]) ? ' ' : str[c]; |
no test coverage detected