Changeset 34 for trunk/src/sh_hash.c
- Timestamp:
- May 19, 2006, 8:09:51 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_hash.c
r27 r34 69 69 #define QUOTE_CHAR '=' 70 70 71 static char * unquote_string (char * str)72 { 73 int i = 0, j, k = 0, len, t1, t2, l2;71 char * unquote_string (const char * str) 72 { 73 int i = 0, t1, t2; 74 74 char * tmp = NULL; 75 size_t len, l2, j, k = 0; 75 76 76 77 SL_ENTER(_("unquote_string")); … … 115 116 char * int2hex (unsigned char i) 116 117 { 117 int j, k; 118 119 j = i / 16; 120 k = i - (j*16); 121 if (j < 10) 122 i2h[0] = '0'+j; 123 else 124 i2h[0] = 'A'+(j-10); 125 126 if (k < 10) 127 i2h[1] = '0'+k; 128 else 129 i2h[1] = 'A'+(k-10); 118 static char hexchars[] = "0123456789ABCDEF"; 119 120 i2h[0] = hexchars[(((i) & 0xF0) >> 4)]; /* high */ 121 i2h[1] = hexchars[((i) & 0x0F)]; /* low */ 130 122 131 123 return i2h; 132 124 } 133 125 134 static char * quote_string (char * str) 135 { 136 int i = 0, j, k = 0, len; 126 127 char * quote_string (const char * str) 128 { 137 129 char * tmp; 138 130 char * tmp2; 131 size_t len, l2, j, i = 0, k = 0; 139 132 140 133 SL_ENTER(_("quote_string")); … … 150 143 if (str[j] == '\n' || str[j] == QUOTE_CHAR) ++i; 151 144 152 tmp = SH_ALLOC(len + 1 + 3*i); 145 l2 = len + 1; 146 if (sl_ok_muls(3, i) && sl_ok_adds(l2, (3*i))) 147 { 148 tmp = SH_ALLOC(len + 1 + 3*i); 149 } 150 else 151 { 152 sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN, 153 _("integer overflow"), 154 _("quote_string")); 155 SL_RETURN(NULL, _("quote_string")); 156 } 157 153 158 for (j = 0; j <= len; ++j) 154 159 { … … 492 497 if (0 != i) 493 498 { 494 ptr = sh_util_ basename (p->fullpath);499 ptr = sh_util_dirname (p->fullpath); 495 500 if (ptr) 496 501 { … … 724 729 725 730 if (sizeofline < 2) { 726 line[0] = '\0';731 if (sizeofline > 0) line[0] = '\0'; 727 732 return 0; 728 733 } … … 736 741 if (n > 1) { 737 742 --n; 738 line[n] = '\0'; 743 line[n] = '\0'; /* remove terminating '\n' */ 739 744 } 740 745 return n; … … 791 796 while (1) 792 797 { 793 i = sh_hash_getline (sh_fin_fd, line, size -1);798 i = sh_hash_getline (sh_fin_fd, line, size); 794 799 if (i < 0 ) 795 800 { … … 860 865 sh_filestore_t ft; 861 866 long i; 867 size_t len; 862 868 char * fullpath; 863 869 char * linkpath; … … 910 916 /* Read next record -- Part Two -- Fullpath 911 917 */ 912 i = sh_hash_getline (sh_fin_fd, line, size -1);918 i = sh_hash_getline (sh_fin_fd, line, size); 913 919 if (i < 0 ) 914 920 { … … 926 932 927 933 tmp = unquote_string (line); 928 i= sl_strlen(tmp)+1;929 fullpath = SH_ALLOC( i);930 sl_strlcpy (fullpath, tmp, i);934 len = sl_strlen(tmp)+1; 935 fullpath = SH_ALLOC(len); 936 (void) sl_strlcpy (fullpath, tmp, len); 931 937 if (tmp) 932 938 SH_FREE(tmp); 933 if (fullpath[ i-2] == '\n')934 fullpath[ i-2] = '\0';939 if (fullpath[len-2] == '\n') 940 fullpath[len-2] = '\0'; 935 941 936 942 /* Read next record -- Part Three -- Linkpath 937 943 */ 938 i = sh_hash_getline (sh_fin_fd, line, size -1);944 i = sh_hash_getline (sh_fin_fd, line, size); 939 945 if (i < 0 ) 940 946 { … … 953 959 954 960 tmp = unquote_string (line); 955 i= sl_strlen(tmp)+1;956 linkpath = SH_ALLOC( i);957 sl_strlcpy (linkpath, tmp, i);961 len = sl_strlen(tmp)+1; 962 linkpath = SH_ALLOC(len); 963 (void) sl_strlcpy (linkpath, tmp, len); 958 964 if (tmp) 959 965 SH_FREE(tmp); 960 if (linkpath[ i-2] == '\n')961 linkpath[ i-2] = '\0';966 if (linkpath[len-2] == '\n') 967 linkpath[len-2] = '\0'; 962 968 963 969 /* Read next record -- Part Four -- Decode … … 1004 1010 void sh_hash_init () 1005 1011 { 1012 1013 #define FGETS_BUF 16384 1014 1006 1015 sh_file_t * p; 1007 1016 SL_TICKET fd = (-1); … … 1111 1120 1112 1121 fin_cp = fdopen(get_the_fd(fd), "rb"); 1113 buf = (char *) SH_ALLOC(8192); 1114 1115 1116 /* while ( (bufc = sh_unix_getline (fd, buf, 8191)) > 0) */ 1117 while (NULL != fgets(buf, 8192, fin_cp)) 1122 buf = SH_ALLOC(FGETS_BUF); 1123 1124 while (NULL != fgets(buf, FGETS_BUF, fin_cp)) 1118 1125 { 1119 1126 bufc = 0; 1120 while (bufc < 8192) {1127 while (bufc < FGETS_BUF) { 1121 1128 if (buf[bufc] == '\n') { ++bufc; break; } 1122 1129 ++bufc; … … 1273 1280 int sh_hash_version_string(const char * str) 1274 1281 { 1275 int i;1276 1282 if (str) 1277 1283 { 1278 i = sl_strlen(str);1279 1284 if (sh_db_version_string != NULL) { 1280 1285 SH_FREE(sh_db_version_string); … … 1285 1290 return 0; 1286 1291 } 1287 sh_db_version_string = SH_ALLOC(i+1); 1288 sl_strlcpy(sh_db_version_string, str, i+1); 1292 sh_db_version_string = sh_util_strdup(str); 1289 1293 return 0; 1290 1294 } … … 1292 1296 } 1293 1297 1294 #if 01295 void sh_hash_pushdata_reset ()1296 {1297 if (!SL_ISERROR(pushdata_fd))1298 {1299 sl_close(pushdata_fd);1300 pushdata_fd = -1;1301 }1302 pushdata_isfirst = 1;1303 }1304 #endif1305 1298 1306 1299 void sh_hash_pushdata (file_type * buf, char * fileHash) … … 1457 1450 #endif 1458 1451 1459 if (tmp _len <= MAX_PATH_STORE)1452 if (tmp && tmp_len <= MAX_PATH_STORE) 1460 1453 { 1461 1454 sl_strlcpy(fullpath, buf->fullpath, MAX_PATH_STORE+1); … … 1475 1468 KEY_LEN+1); 1476 1469 } 1470 if (tmp) SH_FREE(tmp); 1471 } 1472 1473 #if defined(SH_STEALTH) 1474 sh_do_encode(fullpath, sl_strlen(fullpath)); 1475 #endif 1476 1477 tmp = quote_string(fullpath); 1478 if (tmp) { 1479 sl_strlcpy(fullpath, tmp, MAX_PATH_STORE+1); 1477 1480 SH_FREE(tmp); 1478 1481 } 1479 1480 #if defined(SH_STEALTH)1481 sh_do_encode(fullpath, sl_strlen(fullpath));1482 #endif1483 1484 tmp = quote_string(fullpath);1485 sl_strlcpy(fullpath, tmp, MAX_PATH_STORE+1);1486 SH_FREE(tmp);1487 1482 1488 1483 if (buf != NULL && buf->c_mode[0] == 'l' && buf->linkpath != NULL) … … 1499 1494 #endif 1500 1495 1501 if (tmp _len <= MAX_PATH_STORE)1496 if (tmp && tmp_len <= MAX_PATH_STORE) 1502 1497 { 1503 1498 sl_strlcpy(linkpath, buf->linkpath, MAX_PATH_STORE+1); … … 1510 1505 KEY_LEN+1); 1511 1506 } 1512 SH_FREE(tmp);1507 if (tmp) SH_FREE(tmp); 1513 1508 1514 1509 #if defined(SH_STEALTH) … … 1516 1511 #endif 1517 1512 tmp = quote_string(linkpath); 1518 sl_strlcpy(linkpath, tmp, MAX_PATH_STORE+1); 1519 SH_FREE(tmp); 1513 if (tmp) 1514 { 1515 sl_strlcpy(linkpath, tmp, MAX_PATH_STORE+1); 1516 SH_FREE(tmp); 1517 } 1520 1518 } 1521 1519 … … 1977 1975 sh_file_t * fp; 1978 1976 sh_filestore_t p; 1979 long i; 1977 1978 size_t len; 1980 1979 char * fullpath; 1981 1980 char * linkpath; … … 2014 2013 fp->modi_mask = 0L; 2015 2014 2016 i= sl_strlen(buf->fullpath);2017 if ( i<= MAX_PATH_STORE)2018 { 2019 fullpath = SH_ALLOC( i+1);2020 sl_strlcpy(fullpath, buf->fullpath, i+1);2015 len = sl_strlen(buf->fullpath); 2016 if (len <= MAX_PATH_STORE) 2017 { 2018 fullpath = SH_ALLOC(len+1); 2019 sl_strlcpy(fullpath, buf->fullpath, len+1); 2021 2020 } 2022 2021 else … … 2024 2023 fullpath = SH_ALLOC(KEY_LEN + 1); 2025 2024 sl_strlcpy(fullpath, 2026 sh_tiger_hash (buf->fullpath, TIGER_DATA, i),2025 sh_tiger_hash (buf->fullpath, TIGER_DATA, len), 2027 2026 KEY_LEN+1); 2028 2027 } … … 2031 2030 if (buf->c_mode[0] == 'l') 2032 2031 { 2033 i= sl_strlen(buf->linkpath);2034 if ( i<= MAX_PATH_STORE)2035 { 2036 linkpath = SH_ALLOC( i+1);2037 sl_strlcpy(linkpath, buf->linkpath, i+1);2032 len = sl_strlen(buf->linkpath); 2033 if (len <= MAX_PATH_STORE) 2034 { 2035 linkpath = SH_ALLOC(len+1); 2036 sl_strlcpy(linkpath, buf->linkpath, len+1); 2038 2037 } 2039 2038 else … … 2041 2040 linkpath = SH_ALLOC(KEY_LEN + 1); 2042 2041 sl_strlcpy(linkpath, 2043 sh_tiger_hash (buf->linkpath, TIGER_DATA, i),2042 sh_tiger_hash (buf->linkpath, TIGER_DATA, len), 2044 2043 KEY_LEN+1); 2045 2044 } … … 2942 2941 if (p->linkpath != NULL) 2943 2942 SH_FREE(p->linkpath); 2944 p->linkpath = (char*)SH_ALLOC (sl_strlen(theFile->linkpath) + 1); 2945 sl_strlcpy(p->linkpath, theFile->linkpath, 2946 sl_strlen(theFile->linkpath) + 1); 2943 p->linkpath = sh_util_strdup(theFile->linkpath); 2947 2944 } 2948 2945 #endif … … 3026 3023 if (p->linkpath != NULL) 3027 3024 SH_FREE(p->linkpath); 3028 p->linkpath = SH_ALLOC(1 + strlen(theFile->linkpath)); 3029 sl_strlcpy(p->linkpath, theFile->linkpath, 3030 1 + strlen(theFile->linkpath)); 3025 p->linkpath = sh_util_strdup(theFile->linkpath); 3031 3026 } 3032 3027 else
Note:
See TracChangeset
for help on using the changeset viewer.