Changeset 76 for trunk/src/sh_database.c
- Timestamp:
- Dec 19, 2006, 10:01:59 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_database.c
r68 r76 1197 1197 long len; 1198 1198 1199 if (!end || !val || !size) 1200 return end; 1201 1202 if (val[0] == '\0') 1203 { 1204 return end; 1205 } 1206 else 1207 { 1208 if (*size > 1) 1199 if (!((end == NULL) || (val == NULL) || (size == NULL))) 1200 { 1201 if (val[0] != '\0') 1209 1202 { 1210 *end = ','; ++end; (*size) -= 1; 1211 if (flag == 1) { *end = '\''; ++end; (*size) -= 1; } 1212 *end = '\0'; 1203 if (*size > 1) 1204 { 1205 *end = ','; ++end; (*size) -= 1; 1206 if (flag == 1) { *end = '\''; ++end; (*size) -= 1; } 1207 *end = '\0'; 1208 } 1209 len = (long) strlen(val); 1210 if ((long) *size > (len+1)) 1211 { 1212 (void) sl_strlcat(end, val, (size_t) *size); 1213 end += len; (*size) -= len; 1214 if (flag == 1) { *end = '\''; ++end; (*size) -= 1; } 1215 *end = '\0'; 1216 } 1213 1217 } 1214 len = (long) strlen(val); 1215 if ((long) *size > (len+1)) 1216 { 1217 (void) sl_strlcat(end, val, (size_t) *size); 1218 end += len; (*size) -= len; 1219 if (flag == 1) { *end = '\''; ++end; (*size) -= 1; } 1220 *end = '\0'; 1221 } 1222 } 1223 1218 } 1219 1224 1220 return end; 1225 1221 } … … 1250 1246 char md5out[33]; 1251 1247 int cnt; 1248 1249 size_t len_val; 1250 size_t len_col; 1252 1251 1253 1252 SL_ENTER(_("sh_database_entry")); … … 1331 1330 /*@+type@*/ 1332 1331 1333 size = (int) (SH_QUERY_MAX - strlen(values)); 1334 end = values + strlen(values); 1335 c_size = 1023 - (int) strlen(columns); /* sizeof(colums) == 1024 */ 1336 c_end = columns + strlen(columns); 1332 len_val = strlen(values); 1333 size = (int) (SH_QUERY_MAX - len_val); 1334 end = values + len_val; 1335 1336 len_col = strlen(columns); 1337 c_size = 1023 - (int) len_col; /* sizeof(colums) == 1024 */ 1338 c_end = columns + len_col; 1337 1339 1338 1340 i = 4; … … 1354 1356 if (p != end) 1355 1357 { 1356 /* 1357 * 'host' is a reserved word in SQL 1358 */ 1359 if (attr_tab[i].val == SH_SLOT_HOST) 1360 c_end = null_or_val (c_end, _("fromhost"), &c_size,0); 1361 /* 1362 * 'group' is a reserved word in SQL 1363 */ 1364 else if (attr_tab[i].val == SH_SLOT_GROUP) 1365 c_end = null_or_val (c_end, _("grp"), &c_size,0); 1358 if ((attr_tab[i].val != SH_SLOT_HOST) && 1359 (attr_tab[i].val != SH_SLOT_GROUP)) 1360 { 1361 c_end = null_or_val (c_end, attr_tab[i].attr, &c_size,0); 1362 } 1366 1363 else 1367 c_end = null_or_val (c_end, attr_tab[i].attr, &c_size,0); 1364 { 1365 /* 1366 * 'host' is a reserved word in SQL 1367 */ 1368 if (attr_tab[i].val == SH_SLOT_HOST) 1369 c_end = null_or_val (c_end, _("fromhost"), &c_size,0); 1370 /* 1371 * 'group' is a reserved word in SQL 1372 */ 1373 else /* if (attr_tab[i].val == SH_SLOT_GROUP) */ 1374 c_end = null_or_val (c_end, _("grp"), &c_size,0); 1375 } 1368 1376 } 1369 1377 /*@-type@*//* byte* versus char[..] */ … … 1523 1531 unsigned char * p = (unsigned char *) p_in; 1524 1532 1525 while (*p != '\0')1526 { 1527 if (*p == '\\')1533 if (*p != '\0') 1534 { 1535 do 1528 1536 { 1529 escp = (escp == 1) ? 0 : 1; 1530 } 1531 else if ((*p == '\'' || *p == '\"') && escp == 0) 1532 { 1533 retv = S_FALSE; 1534 } 1535 else if (*p > 0x7F) 1536 { 1537 retv = S_FALSE; 1538 } 1539 else 1540 { 1541 escp = 0; 1542 } 1543 ++p; 1544 } 1545 if (escp == 1) 1546 retv = S_FALSE; 1547 return retv; 1537 if (*p <= 0x7F) 1538 { 1539 if (escp == 0) 1540 { 1541 if (!((*p == '\'') || (*p == '\"') || (*p != '\\'))) 1542 /* do nothing */; 1543 else if (*p == '\\') escp = 1; 1544 else retv = S_FALSE; /* (*p == '\'' || *p == '\"') */ 1545 } 1546 else /* escp == 1 */ 1547 { 1548 escp = 0; 1549 } 1550 } 1551 else /* *p > 0x7F */ 1552 { 1553 retv = S_FALSE; 1554 } 1555 1556 ++p; 1557 1558 } 1559 while (*p != '\0'); 1560 } 1561 1562 if (escp == 0) 1563 return retv; 1564 else 1565 return S_FALSE; 1548 1566 } 1549 1567 … … 1580 1598 SL_RETURN (NULL, _("sh_database_parse")); 1581 1599 1582 while (( p != NULL) && (*p != '\0') && (*p != '>'))1600 while ((*p != '\0') && (*p != '>')) 1583 1601 { 1584 1602 if (p[0] == 'l' && p[1] == 'o' && p[2] == 'g' && … … 1631 1649 /* non-whitespace 1632 1650 */ 1633 i = 0;1634 1651 for (i=0; i < 64; ++i) 1635 1652 { 1636 key_str[i] = p[i]; 1637 if (p[i] == '=') 1653 if (p[i] != '=') 1654 { 1655 key_str[i] = p[i]; 1656 } 1657 else 1638 1658 { 1639 1659 key_str[i] = '\0'; … … 1653 1673 { 1654 1674 q = strchr(&p[j+2], '"'); 1655 if (!q) 1656 { 1657 SL_RETURN(NULL, _("sh_database_parse")); 1658 } 1659 else 1675 if (q) 1660 1676 { 1661 1677 *q = '\0'; 1662 1678 1663 if (S_FALSE == is_escaped(&p[j+2])) { 1679 if (S_TRUE == is_escaped(&p[j+2])) { 1680 1681 if (res->val == 1) 1682 (void) sl_strlcpy(db_entry->sev, &p[j+2], 1683 (size_t)res->size); 1684 else if (res->val == 2) 1685 { 1686 z = strchr(&p[j+2], 'T'); 1687 if (z) *z = ' '; 1688 (void) sl_strlcpy(db_entry->time, &p[j+2], 20); 1689 } 1690 else if (res->val == 3) 1691 (void) sl_strlcpy(db_entry->host, &p[j+2], 1692 (size_t) res->size); 1693 else if (res->val == 4) 1694 (void) sl_strlcpy(db_entry->msg, &p[j+2], 1695 (size_t) res->size); 1696 else if (res->size != 0) 1697 { 1698 (void) sl_strlcpy( (((char *)(db_entry))+ res->off), 1699 &p[j+2], 1700 (size_t) res->size); 1701 } 1702 else if (res->val >= START_SEC_LONGS) 1703 { 1704 db_entry->long_data[res->val-START_SEC_LONGS] 1705 = atol(&p[j+2]); 1706 } 1707 1708 *q = '"'; 1709 p = q; 1710 ++p; 1711 1712 goto parse; 1713 } 1714 else { /* S_FALSE == is_escaped(&p[j+2]) */ 1664 1715 sh_error_handle((-1), FIL__, __LINE__, 0, MSG_E_SUBGEN, 1665 1716 _("Message not properly escaped"), … … 1667 1718 SL_RETURN(NULL, _("sh_database_parse")); 1668 1719 } 1669 1670 if (res->val == 1) 1671 (void) sl_strlcpy(db_entry->sev, &p[j+2], 1672 (size_t)res->size); 1673 else if (res->val == 2) 1674 { 1675 z = strchr(&p[j+2], 'T'); 1676 if (z) *z = ' '; 1677 (void) sl_strlcpy(db_entry->time, &p[j+2], 20); 1678 } 1679 else if (res->val == 3) 1680 (void) sl_strlcpy(db_entry->host, &p[j+2], 1681 (size_t) res->size); 1682 else if (res->val == 4) 1683 (void) sl_strlcpy(db_entry->msg, &p[j+2], 1684 (size_t) res->size); 1685 else if (res->size != 0) 1686 { 1687 (void) sl_strlcpy( (((char *)(db_entry))+ res->off), 1688 &p[j+2], 1689 (size_t) res->size); 1690 } 1691 else if (res->val >= START_SEC_LONGS) 1692 { 1693 db_entry->long_data[res->val-START_SEC_LONGS] 1694 = atol(&p[j+2]); 1695 } 1696 1697 *q = '"'; 1698 p = q; 1699 ++p; 1700 1701 goto parse; 1720 } 1721 else /* q == NULL */ 1722 { 1723 SL_RETURN(NULL, _("sh_database_parse")); 1702 1724 } 1703 1725 }
Note:
See TracChangeset
for help on using the changeset viewer.