Changeset 34
- Timestamp:
- May 19, 2006, 8:09:51 PM (19 years ago)
- Location:
- trunk
- Files:
-
- 36 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Makefile.in
r28 r34 1094 1094 $(srcsrc)/cutest_slib.c \ 1095 1095 $(srcsrc)/cutest_zAVLTree.c \ 1096 $(srcsrc)/cutest_sh_hash.c \ 1096 1097 $(srcsrc)/cutest_sh_tiger0.c 1097 1098 … … 1101 1102 cutest_slib.o \ 1102 1103 cutest_zAVLTree.o \ 1104 cutest_sh_hash.o \ 1103 1105 cutest_sh_tiger0.o 1104 1106 -
trunk/docs/Changelog
r30 r34 1 * Code cleanup 2 * fix manual version in spec file, noticed by Imre Gergely 3 1 4 2.2.0: 2 5 * patch by Jim Simmons for samhainadmin.pl.in -
trunk/include/samhain.h
r30 r34 302 302 */ 303 303 int safe_logger (int signal, int method, char * details); 304 void safe_fatal ( int signal, int method,char * details, char *f, int l);304 void safe_fatal (char * details, char *f, int l); 305 305 306 306 #define SH_VALIDATE_EQ(a,b) \ 307 307 do { \ 308 if ((a) != (b)) safe_fatal( 0, 0,#a " != " #b, FIL__, __LINE__);\308 if ((a) != (b)) safe_fatal(#a " != " #b, FIL__, __LINE__);\ 309 309 } while (0) 310 310 311 311 #define SH_VALIDATE_NE(a,b) \ 312 312 do { \ 313 if ((a) == (b)) safe_fatal( 0, 0,#a " == " #b, FIL__, __LINE__);\313 if ((a) == (b)) safe_fatal(#a " == " #b, FIL__, __LINE__);\ 314 314 } while (0) 315 315 -
trunk/include/sh_utils.h
r22 r34 144 144 /* returns freshly allocated memory, return value should be free'd 145 145 */ 146 char * sh_util_ filename(char * fullpath);146 char * sh_util_dirname(const char * fullpath); 147 147 148 148 /* returns freshly allocated memory, return value should be free'd … … 160 160 /* returns freshly allocated memory, return value should be free'd 161 161 */ 162 char * sh_util_basename(c har * fullpath);162 char * sh_util_basename(const char * fullpath); 163 163 164 164 #endif -
trunk/include/slib.h
r20 r34 401 401 int sl_ok_subi (int a, int b); 402 402 403 int sl_ok_muls (size_t a, size_t b); 404 int sl_ok_adds (size_t a, size_t b); 405 406 403 407 #ifdef __cplusplus 404 408 } -
trunk/samhain.spec.in
r1 r34 179 179 %dir @mylogdir@ 180 180 %doc docs/BUGS COPYING docs/Changelog docs/TODO 181 %doc LICENSE docs/FAQ.html docs/HOWTO* docs/MANUAL-2_ 0.* docs/README*181 %doc LICENSE docs/FAQ.html docs/HOWTO* docs/MANUAL-2_2.* docs/README* 182 182 @mydataroot@ 183 183 %if "%{withstg_prg}" == "xsamhain_stealth" … … 196 196 197 197 %changelog 198 * Tue May 16 2006 Rainer Wichmann 199 - fix manual version, noticed by Imre Gergely 200 198 201 * Tue Apr 05 2005 Rainer Wichmann 199 202 - disable automatic stripping, use sstrip -
trunk/scripts/redhat_i386.client.spec.in
r1 r34 136 136 %dir /var/log 137 137 #%doc docs/BUGS COPYING docs/Changelog docs/TODO 138 #%doc LICENSE docs/HOWTO* docs/MANUAL-2_ 0.* docs/README*138 #%doc LICENSE docs/HOWTO* docs/MANUAL-2_2.* docs/README* 139 139 /etc 140 140 /usr/local/sbin/samhain -
trunk/scripts/samhain.spec.in
r1 r34 122 122 %dir %{_localstatedir}/log 123 123 %doc docs/BUGS COPYING docs/Changelog docs/TODO 124 %doc LICENSE docs/HOWTO* docs/MANUAL-2_ 0.* docs/README*124 %doc LICENSE docs/HOWTO* docs/MANUAL-2_2.* docs/README* 125 125 %{_localstatedir}/lib/%{name} 126 126 %{_sbindir}/%{name} -
trunk/src/cutest_sh_utils.c
r22 r34 6 6 #include "samhain.h" 7 7 #include "sh_utils.h" 8 9 void Test_sh_util_strdup_ok (CuTest *tc) { 10 char * ret = 0; 11 char inp[] = "foobar"; 12 13 ret = sh_util_strdup(inp); 14 CuAssertPtrNotNull(tc, ret); 15 CuAssert(tc, "expected inp != ret, but inp == ret", (inp != ret)); 16 CuAssertStrEquals(tc, "foobar", ret); 17 return; 18 } 19 20 void Test_sh_util_strconcat_ok (CuTest *tc) { 21 char * ret = 0; 22 23 ret = sh_util_strconcat("foo", NULL); 24 CuAssertPtrNotNull(tc, ret); 25 CuAssertStrEquals(tc, "foo", ret); 26 27 ret = sh_util_strconcat("foo", "bar", NULL); 28 CuAssertPtrNotNull(tc, ret); 29 CuAssertStrEquals(tc, "foobar", ret); 30 31 ret = sh_util_strconcat("/", "foo", "/", "bar", NULL); 32 CuAssertPtrNotNull(tc, ret); 33 CuAssertStrEquals(tc, "/foo/bar", ret); 34 35 return; 36 } 37 38 void Test_sh_util_dirname_ok (CuTest *tc) { 39 char * ret = 0; 40 41 char input0[] = "/foo/bar"; 42 char res0[] = "/foo"; 43 44 char input1[] = "/foo/bar/"; 45 char res1[] = "/foo"; 46 47 char input2[] = "/foo"; 48 char res2[] = "/"; 49 50 char input3[] = "/"; 51 char res3[] = "/"; 52 53 ret = sh_util_dirname(input0); 54 CuAssertPtrNotNull(tc, ret); 55 CuAssertStrEquals(tc, res0, ret); 56 57 ret = sh_util_dirname(input1); 58 CuAssertPtrNotNull(tc, ret); 59 CuAssertStrEquals(tc, res1, ret); 60 61 ret = sh_util_dirname(input2); 62 CuAssertPtrNotNull(tc, ret); 63 CuAssertStrEquals(tc, res2, ret); 64 65 ret = sh_util_dirname(input3); 66 CuAssertPtrNotNull(tc, ret); 67 CuAssertStrEquals(tc, res3, ret); 68 return; 69 } 70 71 void Test_sh_util_basename_ok (CuTest *tc) { 72 char * ret = 0; 73 74 char input0[] = "/foo/bar"; 75 char res0[] = "bar"; 76 77 char input1[] = "/foo/"; 78 char res1[] = "foo"; 79 80 char input2[] = "/foo"; 81 char res2[] = "foo"; 82 83 char input3[] = "/"; 84 char res3[] = "/"; 85 86 char input4[] = "/foo/bar/"; 87 char res4[] = "bar"; 88 89 ret = sh_util_basename(input0); 90 CuAssertPtrNotNull(tc, ret); 91 CuAssertStrEquals(tc, res0, ret); 92 93 ret = sh_util_basename(input1); 94 CuAssertPtrNotNull(tc, ret); 95 CuAssertStrEquals(tc, res1, ret); 96 97 ret = sh_util_basename(input2); 98 CuAssertPtrNotNull(tc, ret); 99 CuAssertStrEquals(tc, res2, ret); 100 101 ret = sh_util_basename(input3); 102 CuAssertPtrNotNull(tc, ret); 103 CuAssertStrEquals(tc, res3, ret); 104 105 ret = sh_util_basename(input4); 106 CuAssertPtrNotNull(tc, ret); 107 CuAssertStrEquals(tc, res4, ret); 108 109 return; 110 } 8 111 9 112 void Test_sh_util_obscure_ok (CuTest *tc) { -
trunk/src/samhain.c
r25 r34 817 817 if (!fp) 818 818 { if (errno != ENOENT) perror(_("fopen")); return 0; } 819 if (NULL == fgets(line, 255, fp))819 if (NULL == fgets(line, sizeof(line), fp)) 820 820 { perror(_("fgets")); (void) fclose(fp); return 0; } 821 821 (void) fclose(fp); … … 1114 1114 1115 1115 #if defined (SH_STEALTH_NOCL) 1116 char * command_line;1116 char command_line[256]; 1117 1117 int my_argc = 0; 1118 1118 char * my_argv[32]; … … 1280 1280 strlen(argv[1]) > 0 && strlen(NOCL_CODE) > 0) 1281 1281 { 1282 if ( 0 == strcmp(argv[1], NOCL_CODE) && 1283 NULL != (command_line = (char *) SH_ALLOC(256 * sizeof(char)))) 1282 if ( 0 == strcmp(argv[1], NOCL_CODE) ) 1284 1283 { 1285 1284 my_argv[0] = argv[0]; ++my_argc; 1286 1285 command_line[0] = '\0'; 1287 (void*) fgets (command_line, 255, stdin);1288 command_line[ 255] = '\0';1286 (void*) fgets (command_line, sizeof(command_line), stdin); 1287 command_line[sizeof(command_line)-1] = '\0'; 1289 1288 do { 1290 1289 my_argv[my_argc] = … … 1301 1300 1302 1301 (void) sh_getopt_get (my_argc, my_argv); 1303 SH_FREE (command_line);1304 1302 } 1305 1303 else -
trunk/src/samhain_stealth.c
r1 r34 390 390 391 391 fprintf(stdout, _(" .. hide %s in %s .. \n"), argv[3], argv[2]); 392 while (fgets(buf, 1023, infil))392 while (fgets(buf, sizeof(buf), infil)) 393 393 { 394 394 lseek(fd, off_data, SEEK_SET); -
trunk/src/sh_err_log.c
r22 r34 390 390 (void) fflush(stdout); 391 391 key[0] = '\0'; 392 (void) fgets(key, KEY_LEN+2, stdin);392 (void) fgets(key, sizeof(key), stdin); 393 393 if (key[0] != '\n') 394 394 { … … 553 553 { 554 554 tmp = sh_util_safe_name (logfile); 555 len = 6 + sl_strlen(tmp); 555 len = sl_strlen(tmp); 556 if (sl_ok_adds (6, len)) 557 len += 6; 556 558 lockfile = SH_ALLOC(len); 557 559 (void) sl_strlcpy(lockfile, tmp, len); … … 634 636 635 637 SL_TICKET fd = -1; 636 long intstatus;638 size_t status; 637 639 struct _sh_log_buf log_msg; 638 640 … … 749 751 */ 750 752 751 status = (long) sl_strlen (errmsg); 753 status = sl_strlen (errmsg); 754 if (!sl_ok_adds(status, (2*KEY_LEN)) || !sl_ok_adds((2*KEY_LEN + status),32)) 755 { 756 SL_RETURN ((-1), _("sh_log_file")); 757 } 758 752 759 log_msg.msg = (char *) SH_ALLOC ((size_t) (2*KEY_LEN + status + 32)); 753 760 -
trunk/src/sh_error.c
r27 r34 1144 1144 */ 1145 1145 export_block = 1; 1146 ex_len = 64 + sl_strlen(lmsg->msg) + 1; 1146 /* ex_len = 64 + sl_strlen(lmsg->msg) + 1; */ 1147 ex_len = sl_strlen(lmsg->msg); 1148 if (sl_ok_adds(ex_len, 65)) 1149 ex_len = 64 + ex_len + 1; 1147 1150 ex_msg = SH_ALLOC (ex_len); 1148 1151 … … 1497 1500 /*@i@*/required = sl_vsnprintf(&(lmsg->msg[len]), 1498 1501 (lmsg->msg_len - len), lmsg->format, vl); 1499 if ( (required + len) > (lmsg->msg_len - 4) ) 1502 if ((required >= 0) && 1503 sl_ok_adds(required, len) && 1504 sl_ok_adds((required+len), 4) && 1505 ((required + len) > (lmsg->msg_len - 4)) ) 1500 1506 { 1501 1507 /*@i@*/p = SH_ALLOC(required + len + 4); -
trunk/src/sh_extern.c
r29 r34 664 664 sv = strlen(val) + 1; 665 665 666 if (!sl_ok_adds(sk, sv)) 667 { 668 SL_RETURN (-1, _("sh_ext_tas_add_envv")); 669 } 666 670 si = tas->envc; 667 671 tas->envv[si] = SH_ALLOC(sk + sv); … … 845 849 int sh_ext_add_envv(const char * key, const char * val) 846 850 { 851 int retval; 852 847 853 SL_ENTER(_("sh_ext_add_envv")); 848 854 … … 854 860 } 855 861 856 (void) sh_ext_tas_add_envv(&(ext_coms->tas), key, val); 857 858 SL_RETURN (0, _("sh_ext_add_envv")); 862 retval = sh_ext_tas_add_envv(&(ext_coms->tas), key, val); 863 864 if (retval >= 0) 865 retval = 0; 866 867 SL_RETURN (retval, _("sh_ext_add_envv")); 859 868 } 860 869 -
trunk/src/sh_files.c
r27 r34 200 200 201 201 dirstack_t * ptr; 202 char * base;202 char * dir; 203 203 char * file; 204 204 … … 215 215 if (ptr->checked == S_FALSE) 216 216 { 217 base = sh_util_basename (ptr->name);218 file = sh_util_ filename (ptr->name);217 dir = sh_util_dirname (ptr->name); 218 file = sh_util_basename (ptr->name); 219 219 #if defined(WITH_TPT) 220 220 tmp = sh_util_safe_name (ptr->name); … … 231 231 232 232 BREAKEXIT(sh_files_filecheck); 233 status = sh_files_filecheck (ptr->class, base, file,233 status = sh_files_filecheck (ptr->class, dir, file, 234 234 (int *) &(ptr->reported), 0); 235 235 … … 348 348 } 349 349 SH_FREE(file); 350 SH_FREE( base);350 SH_FREE(dir); 351 351 352 352 ptr->checked = S_TRUE; … … 729 729 #endif 730 730 731 int sh_files_push_file_int (int class, const char * str_s, int len)731 int sh_files_push_file_int (int class, const char * str_s, size_t len) 732 732 { 733 733 dirstack_t * new_item_ptr; … … 777 777 static int sh_files_pushfile (int class, const char * str_s) 778 778 { 779 intlen;779 size_t len; 780 780 char * tmp; 781 781 char * p; … … 1132 1132 } 1133 1133 1134 int sh_files_push_dir_int (int class, char * tail, int len, int rdepth)1134 int sh_files_push_dir_int (int class, char * tail, size_t len, int rdepth) 1135 1135 { 1136 1136 zAVLTree * tree; … … 1194 1194 { 1195 1195 char * tmp; 1196 intlen;1196 size_t len; 1197 1197 int rdepth = 0; 1198 1198 char * tail = NULL; … … 1326 1326 SH_FREE(p); 1327 1327 SL_RETURN((0), _("sh_files_pushdir")); 1328 } 1328 } 1329 1329 1330 1330 struct sh_dirent { … … 1354 1354 { 1355 1355 struct sh_dirent * this; 1356 int i;1356 size_t len; 1357 1357 1358 1358 if (thisEntry == NULL) 1359 1359 return dirlist; 1360 1360 1361 i= sl_strlen(thisEntry->d_name);1362 if ( i== 0)1361 len = sl_strlen(thisEntry->d_name); 1362 if (len == 0) 1363 1363 return dirlist; 1364 ++ i;1364 ++len; 1365 1365 1366 1366 this = SH_ALLOC(sizeof(struct sh_dirent)); … … 1368 1368 return dirlist; 1369 1369 1370 this->sh_d_name = SH_ALLOC( i);1371 sl_strlcpy(this->sh_d_name, thisEntry->d_name, i);1370 this->sh_d_name = SH_ALLOC(len); 1371 sl_strlcpy(this->sh_d_name, thisEntry->d_name, len); 1372 1372 1373 1373 this->next = dirlist; … … 1492 1492 1493 1493 int hardlink_num = 0; 1494 1494 #if !defined(HOST_IS_DARWIN) 1495 size_t len; 1496 #endif 1495 1497 1496 1498 SL_ENTER(_("sh_files_checkdir")); … … 1866 1868 if (0 != sh_files_hle_test(hardlink_num-theDir.NumDirs, iname)) 1867 1869 { 1868 tmpcat = SH_ALLOC(strlen(tmpname) + 256); 1869 sl_snprintf(tmpcat, strlen(tmpname) + 256, 1870 len = strlen(tmpname); 1871 if (sl_ok_adds(len, 256)) 1872 len += 256; 1873 tmpcat = SH_ALLOC(len); 1874 sl_snprintf(tmpcat, len, 1870 1875 _("%s: subdirectory count (%d) != hardlinks (%d)"), 1871 1876 tmpname, theDir.NumDirs, hardlink_num); … … 1886 1891 1887 1892 static ShFileType sh_files_filecheck (int class, char * dirName, 1888 char * fileName,1893 char * infileName, 1889 1894 int * reported, 1890 1895 int rsrcflag) … … 1898 1903 char * tmpdir; 1899 1904 char * tmpname; 1905 char * fileName; 1900 1906 struct utimbuf utime_buf; 1901 1907 … … 1905 1911 if (0 == (rand() % 2)) 1906 1912 (void) sh_derr(); 1913 1914 if (dirName && infileName && (dirName[0] == '/') && (dirName[1] == '\0') 1915 && (infileName[0] == '/') && (infileName[1] == '\0')) 1916 { 1917 fileName = NULL; 1918 } 1919 else 1920 { 1921 fileName = infileName; 1922 } 1907 1923 1908 1924 /* fileName may be NULL if this is a directory -
trunk/src/sh_forward.c
r27 r34 139 139 #include "rijndael-api-fst.h" 140 140 char * sh_tools_makePack (unsigned char * header, 141 char * payload, intpayload_size,141 char * payload, unsigned long payload_size, 142 142 keyInstance * keyInstE); 143 143 char * sh_tools_revertPack (unsigned char * header, char * message, … … 305 305 } 306 306 307 len = sl_strlen(salt) + sl_strlen(skey->vernam) + 1; 308 if (nounce != NULL) 307 len = sl_strlen(salt) + 1; 308 if (sl_ok_adds(len, sl_strlen(skey->vernam))) 309 len += sl_strlen(skey->vernam); 310 if (nounce != NULL && sl_ok_adds(len, sl_strlen(nounce))) 309 311 len += sl_strlen(nounce); 310 312 … … 394 396 { 395 397 put_header (head, (int)protocol, &length, micro); 396 msg2buf = sh_tools_makePack (head, msgbuf, (int)length,398 msg2buf = sh_tools_makePack (head, msgbuf, length, 397 399 &(skey->keyInstE)); 398 400 /*@-usedef@*/ … … 406 408 blkfac = length/B_SIZ; 407 409 rem = (int) (length - (B_SIZ * blkfac)); 408 length2 = (B_SIZ * blkfac) + ((rem == 0) ? 0 : B_SIZ); 410 length2 = (B_SIZ * blkfac); 411 if ((rem > 0) && (length2+B_SIZ) > length2) 412 length2 += B_SIZ; 413 else 414 rem = 0; 409 415 410 416 msg2buf = SH_ALLOC((size_t)length2); … … 549 555 SL_ENTER(_("sh_forward_receive_intern")); 550 556 557 #ifdef SH_ENCRYPT 558 /* make sure length is not multiple of B_SIZ, see below 559 */ 560 ASSERT_RET((length % B_SIZ != 0), _("length % 16 != 0"), flag_err); 561 #endif 562 551 563 if (micro != NULL) 552 564 micro[4] = '\0'; … … 608 620 head_length = (unsigned long) (256 * (unsigned int)head[1] + 609 621 (unsigned int)head[2]); 610 head_length = (head_length > length ? length : head_length); 611 length = head_length; 622 623 /* 624 * revertPack returns header with length <= (original_length-16), so 625 * the following msgbuf[length] = '\0' is always safe. 626 * Nevertheless, check for proper length. 627 */ 628 if (head_length <= (length-1)) 629 length = head_length; 630 else 631 --length; 612 632 613 633 memcpy(msgbuf, tmp, (size_t)length); … … 627 647 */ 628 648 blkfac = countbytes/B_SIZ; 629 /* length2 = (B_SIZ * blkfac); */ 649 630 650 p = msgbuf; 631 651 q = msgbuf; … … 638 658 _("sh_forward_receive_intern: cipherInit")); 639 659 660 /* here we want to have (length % B_SIZ != 0), such that the 661 * terminating '\0' cannot be overwritten 662 */ 640 663 for (j = 0; j < blkfac; ++j) 641 664 { … … 648 671 _("sh_forward_receive_intern: blockDecrypt")); 649 672 memcpy(q, outBlock, B_SIZ); 650 p += 16;651 q += 16;673 p += B_SIZ; 674 q += B_SIZ; 652 675 } 653 676 } … … 1047 1070 timeout_val *= 2; 1048 1071 sh_error_handle((-1), FIL__, __LINE__, 0, MSG_TCP_NOAUTH); 1049 memset(answer, 0, sizeof(answer));1072 memset(answer, 0, 512); 1050 1073 MUNLOCK(answer, 512); 1051 1074 SH_FREE(answer); … … 1238 1261 timeout_val *= 2; 1239 1262 sh_error_handle((-1), FIL__, __LINE__, 0, MSG_TCP_NOAUTH); 1240 memset(answer, '\0', sizeof(answer));1263 memset(answer, '\0', 512); 1241 1264 MUNLOCK(answer, 512); 1242 1265 SH_FREE(answer); … … 1257 1280 { 1258 1281 timeout_val = 1; 1259 memset(answer, 0, sizeof(answer));1282 memset(answer, 0, 512); 1260 1283 MUNLOCK(answer, 512); 1261 1284 SH_FREE(answer); … … 1626 1649 head_u, 1627 1650 answer, 1628 TRANS_BYTES + 25 6);1651 TRANS_BYTES + 255); 1629 1652 1630 1653 TPT(( 0, FIL__, __LINE__, … … 2004 2027 } 2005 2028 2006 if ( sepnum == 2 && sep[0] > 0)2029 if ((sepnum == 2) && (sep[0] > 0) && (sep[1] > sep[0])) 2007 2030 { 2008 2031 newclt = SH_ALLOC (sizeof(client_t)); … … 2222 2245 int docrypt) 2223 2246 { 2224 register unsigned long i;2247 /* register unsigned long i; */ 2225 2248 unsigned long length2; 2226 2249 … … 2251 2274 blkfac = length/B_SIZ; 2252 2275 rem = length - (B_SIZ * blkfac); 2253 length2 = (B_SIZ * blkfac) + ((rem == 0) ? 0 : B_SIZ); 2276 length2 = (B_SIZ * blkfac); 2277 if (rem > 0 && (length2 + B_SIZ) > length2) 2278 length2 += B_SIZ; 2279 else 2280 rem = 0; 2254 2281 } 2255 2282 else … … 2289 2316 &(conn->client_entry->keyInstE)); 2290 2317 } 2291 else if ((S_TRUE == docrypt) && ((protocol & SH_PROTO_ENC) != 0)) 2318 else if ((S_TRUE == docrypt) && ((protocol & SH_PROTO_ENC) != 0) && 2319 ((length2 + 1) > length2)) 2292 2320 { 2293 2321 conn->buf = SH_ALLOC(length2 + 1); … … 2337 2365 else 2338 2366 { 2367 if ((length2 + 1) < length2) --length2; 2339 2368 conn->buf = SH_ALLOC(length2 + 1); 2340 2369 2370 memcpy(conn->buf, msg, length2); 2371 /* 2341 2372 for (i = 0; i < length2; ++i) 2342 2373 conn->buf[i] = msg[i]; 2374 */ 2343 2375 conn->buf[length2] = '\0'; 2344 2376 TPT((0, FIL__, __LINE__, _("msg=<no encryption done>\n") )); 2345 2377 } 2346 2378 #else 2379 if ((length2 + 1) < length2) --length2; 2347 2380 conn->buf = SH_ALLOC(length2 + 1); 2348 2381 2382 memcpy(conn->buf, msg, length2); 2383 /* 2349 2384 for (i = 0; i < length; ++i) 2350 2385 conn->buf[i] = msg[i]; 2386 */ 2351 2387 conn->buf[length2] = '\0'; 2352 2388 TPT((0, FIL__, __LINE__, _("msg=<no encryption done>\n") )); … … 2856 2892 conn->K = NULL; 2857 2893 } 2858 len = sl_strlen(&(conn->buf[KEY_LEN])) + KEY_LEN + 1; 2859 conn->K = SH_ALLOC(len); 2894 2895 /* FIXME 2896 len = sl_strlen(&(conn->buf[KEY_LEN])) + 1; 2897 if (sl_ok_adds(len, KEY_LEN)) 2898 len += KEY_LEN; 2899 len = (len < (KEY_LEN+1)) ? (KEY_LEN+1) : len; 2900 */ 2901 conn->K = SH_ALLOC(KEY_LEN+1); 2860 2902 2861 2903 sl_strlcpy (conn->K, … … 3316 3358 conn->K = NULL; 3317 3359 } 3318 len = sl_strlen(&(conn->buf[KEY_LEN])) + KEY_LEN + 1;3319 conn->K = SH_ALLOC( len);3360 /* FIXME len = sl_strlen(&(conn->buf[KEY_LEN])) + KEY_LEN + 1; */ 3361 conn->K = SH_ALLOC(KEY_LEN + 1); 3320 3362 3321 3363 sl_strlcpy (conn->K, … … 4327 4369 if (conn->buf != NULL) 4328 4370 SH_FREE (conn->buf); 4329 conn->buf = SH_ALLOC (conn->bytes_to_get + 1);4371 conn->buf = SH_ALLOC(conn->bytes_to_get + 1); /* <= TRANS_BYTES+1 */ 4330 4372 conn->bytecount = 0; 4331 4373 } … … 4863 4905 maxconn = (((int)FD_SETSIZE) < maxconn) ? FD_SETSIZE : maxconn; 4864 4906 4907 if (maxconn < 0 || !sl_ok_muls(maxconn, sizeof(sh_conn_t))) 4908 { 4909 sh_error_handle((-1), FIL__, __LINE__, 0, MSG_START_SRV, 4910 0, sock); 4911 aud_exit (FIL__, __LINE__, EXIT_FAILURE); 4912 } 4865 4913 conns = SH_ALLOC (sizeof(sh_conn_t) * maxconn); 4866 4914 -
trunk/src/sh_gpg.c
r22 r34 690 690 errno = 0; 691 691 692 while (NULL != fgets(line, 255, source.pipe))692 while (NULL != fgets(line, sizeof(line), source.pipe)) 693 693 { 694 694 … … 805 805 errno = 0; 806 806 807 while (NULL != fgets(line, 255, source.pipe))807 while (NULL != fgets(line, sizeof(line), source.pipe)) 808 808 { 809 809 if (line[strlen(line)-1] == '\n') -
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 -
trunk/src/sh_html.c
r25 r34 108 108 if (!SL_ISERROR(fd)) 109 109 { 110 while (!SL_ISERROR(status) && sh_unix_getline (fd, line, 511) > 0)110 while (!SL_ISERROR(status) && sh_unix_getline (fd, line, sizeof(line)) > 0) 111 111 { 112 112 formatted = replace_stat (line); … … 121 121 else 122 122 { 123 qstr = sh_util_ filename(DEFAULT_HTML_FILE);123 qstr = sh_util_basename(DEFAULT_HTML_FILE); 124 124 if (qstr != NULL) 125 125 { … … 217 217 if (!SL_ISERROR(fd)) 218 218 { 219 while (!SL_ISERROR(status) && sh_unix_getline (fd, line, 511) > 0)219 while (!SL_ISERROR(status) && sh_unix_getline (fd, line, sizeof(line)) > 0) 220 220 { 221 221 status = sl_write_line (ticket, line, sl_strlen(line)); … … 289 289 if (!SL_ISERROR(fd)) 290 290 { 291 while (!SL_ISERROR(retval) && sh_unix_getline (fd, line, 511) > 0)291 while (!SL_ISERROR(retval) && sh_unix_getline (fd, line, sizeof(line)) > 0) 292 292 { 293 293 line_size = sl_strlen(line); -
trunk/src/sh_kern.c
r22 r34 257 257 } 258 258 259 extern int sh_util_hextobinary (char * binary, c har * hex, int bytes);259 extern int sh_util_hextobinary (char * binary, const char * hex, int bytes); 260 260 261 261 static char * sh_kern_db2pop (char * name, unsigned long * addr, -
trunk/src/sh_mail.c
r22 r34 173 173 /* get signature and number 174 174 */ 175 (void) sh_unix_getline (fd, key, (int) ( sizeof(key)-1));175 (void) sh_unix_getline (fd, key, (int)sizeof(key)); 176 176 key[KEY_LEN] = '\0'; 177 177 178 (void) sh_unix_getline (fd, number, (int) (sizeof(number)-1));178 (void) sh_unix_getline (fd, number, (int)sizeof(number)); 179 179 number[(2*SH_MINIBUF) - 2] = '\0'; 180 180 numsig = atol (number); … … 742 742 static char * sh_mail_realloc (char * inbuf, size_t * insize, size_t increase) 743 743 { 744 size_t newsize = (*insize) + increase + 1;745 char * outbuf ;744 size_t newsize; 745 char * outbuf = inbuf; 746 746 747 747 SL_ENTER(_("sh_mail_realloc")); 748 748 749 outbuf = SH_ALLOC(newsize); 750 MLOCK(outbuf, newsize); 751 (void) sl_strlcpy(outbuf, inbuf, newsize); 752 753 memset (inbuf, 0, (*insize)); 754 MUNLOCK(inbuf, (*insize)); 755 SH_FREE(inbuf); 756 757 *insize = newsize; 749 if (sl_ok_adds((*insize), 1)) 750 { 751 newsize = (*insize) + 1; 752 753 if (sl_ok_adds(newsize, increase)) 754 { 755 newsize += increase; 756 757 outbuf = SH_ALLOC(newsize); 758 MLOCK(outbuf, newsize); 759 (void) sl_strlcpy(outbuf, inbuf, newsize); 760 761 memset (inbuf, 0, (*insize)); 762 MUNLOCK(inbuf, (*insize)); 763 SH_FREE(inbuf); 764 765 *insize = newsize; 766 } 767 } 758 768 759 769 SL_RETURN( (outbuf), _("sh_mail_realloc")); … … 1227 1237 int sh_mail_set_relay (const char * str_s) 1228 1238 { 1229 size_t i = 0;1230 1231 1239 SL_ENTER(_("sh_mail_set_relay")); 1232 1240 … … 1235 1243 1236 1244 if (relay_host != NULL) 1237 SH_FREE (relay_host); 1245 { 1246 SH_FREE (relay_host); 1247 relay_host = NULL; 1248 } 1238 1249 1239 1250 if (0 == sl_strncmp(str_s, _("NULL"), 4)) 1240 1251 { 1241 relay_host = NULL;1242 1252 SL_RETURN( 0, _("sh_mail_set_relay")); 1243 1253 } 1244 1254 1245 i = sl_strlen(str_s) + 1; 1246 relay_host = SH_ALLOC (i); 1247 if (relay_host != NULL) 1248 (void) sl_strlcpy(relay_host, str_s, i); 1249 else 1250 fprintf(stderr, _("ERROR: sh_mail_set_relay: Out of memory")); 1255 relay_host = sh_util_strdup(str_s); 1256 1251 1257 SL_RETURN( 0, _("sh_mail_set_relay")); 1252 1258 } … … 1802 1808 return NULL; 1803 1809 1804 size = strlen(str); 1805 /* fprintf(stderr, "orig = %d\n", size); */ 1810 size = strlen(str) + 1; 1806 1811 blocks = 1 + (size / SPLIT_AT); 1807 1812 1808 size = size + (2*blocks) + 1; 1813 if (sl_ok_muls(2, blocks) && sl_ok_adds(size, (2*blocks))) 1814 { 1815 size = size + (2*blocks); 1816 } 1817 else 1818 { 1819 /* integer overflow, do not split */ 1820 p = sh_util_strdup(str); 1821 return p; 1822 } 1823 1809 1824 p = SH_ALLOC(size); 1810 1825 memset(p, 0, size); 1811 /* fprintf(stderr, "alloc = %d\n", size); */ 1826 1812 1827 p0 = p; 1813 1828 … … 1897 1912 unsigned char * comp_dn, * eom; 1898 1913 HEADER * header; 1899 int count, index, type, rdlength, pref; 1914 int type, rdlength, pref; 1915 unsigned int count, index; 1900 1916 dnsrep * retval; 1901 1917 … … 1978 1994 /* allocate space for the results */ 1979 1995 1996 if (!sl_ok_muls(count, sizeof (mx))) 1997 { 1998 SH_FREE (retval); 1999 SL_RETURN (NULL, _("get_mx")); 2000 } 2001 1980 2002 result = SH_ALLOC (count * sizeof (mx)); 2003 1981 2004 if (!result) 1982 2005 { -
trunk/src/sh_mounts.c
r1 r34 450 450 451 451 while ((c = getc (fd)) == '*') { 452 while (((c = getc (fd)) != '\n') && (c != EOF)) { 453 } 452 while (((c = getc (fd)) != '\n') && (c != EOF)) {} /* do nothing */ 454 453 } 455 454 } -
trunk/src/sh_prelink.c
r22 r34 40 40 int sh_prelink_set_path (const char * str) 41 41 { 42 size_t len;43 42 SL_ENTER(_("sh_prelink_set_path")); 44 43 if (prelink_path != NULL) … … 49 48 SL_RETURN((-1), _("sh_prelink_set_path")); 50 49 } 51 len = sl_strlen (str); 52 prelink_path = SH_ALLOC(len+1);53 (void) sl_strlcpy(prelink_path, str, len+1); 50 51 prelink_path = sh_util_strdup(str); 52 54 53 SL_RETURN(0, _("sh_prelink_set_path")); 55 54 } -
trunk/src/sh_schedule.c
r22 r34 347 347 } 348 348 349 /*350 for (i = 0; i < 5; ++i)351 printf("%2d MIN %3d MAX %3d STEP %3d\n",352 i, isched->min[i], isched->max[i], isched->step[i]);353 */354 355 349 isched->last_exec = (time_t)-1; 356 350 isched->first = 0; -
trunk/src/sh_socket.c
r22 r34 352 352 { 353 353 size = sl_strlen(DEFAULT_PIDDIR) + 1 + sl_strlen(SH_INSTALL_NAME) + 6; 354 sh_sockname = SH_ALLOC(size); 354 sh_sockname = SH_ALLOC(size); /* compile-time constant */ 355 355 sl_strlcpy(sh_sockname, DEFAULT_PIDDIR, size); 356 356 sl_strlcat(sh_sockname, "/", size); -
trunk/src/sh_srp.c
r27 r34 197 197 198 198 char *combi; 199 size_t len ;199 size_t len, l2; 200 200 register int i; 201 201 unsigned char * dez = NULL; … … 221 221 skey->vernam[KEY_LEN] = '\0'; 222 222 223 len = sl_strlen(salt) + sl_strlen(skey->vernam) + 1; 223 len = sl_strlen(salt) + 1; 224 l2 = sl_strlen(skey->vernam); 225 if (sl_ok_adds(len, l2)) 226 len += l2; 224 227 225 228 /* H(s,P) … … 240 243 { 241 244 char *combi; 242 size_t len ;245 size_t len, l2, l3; 243 246 static char hash[KEY_LEN+1]; 244 247 … … 248 251 _("x1 != NULL && x2 != NULL && x3 !=NULL"), NULL); 249 252 250 len = sl_strlen(x1) + sl_strlen(x2) + sl_strlen(x3) + 1; 253 len = sl_strlen(x1) + 1; 254 l2 = sl_strlen(x2); 255 l3 = sl_strlen(x3); 256 257 if (sl_ok_adds(len, l2)) 258 len += l2; 259 if (sl_ok_adds(len, l3)) 260 len += l3; 251 261 252 262 /* H(x1,x2,x3) … … 392 402 char *str; 393 403 char *combi; 394 size_t len;395 404 bigerr_t res; 396 405 … … 408 417 409 418 if (str != NULL) 410 { 411 len = sl_strlen(str) + 1; 412 combi = SH_ALLOC(len); 413 (void) sl_strlcpy (combi, str, len); 414 } 419 combi = sh_util_strdup(str); 415 420 else 416 421 combi = NULL; … … 430 435 char *str; 431 436 char *combi; 432 long len;433 437 bigerr_t res; 434 438 … … 469 473 470 474 if (str != NULL) 471 { 472 len = sl_strlen(str) + 1; 473 combi = SH_ALLOC(len); 474 sl_strlcpy (combi, str, len); 475 /* fprintf(stderr, "OK2a %ld %s\n", len, combi); */ 476 } 475 combi = sh_util_strdup(str); 477 476 else 478 477 combi = NULL; … … 496 495 char *str; 497 496 char *combi; 498 size_t len;499 497 bigerr_t res; 500 498 … … 571 569 572 570 if (str != NULL) 573 { 574 len = sl_strlen(str) + 1; 575 combi = SH_ALLOC(len); 576 (void) sl_strlcpy (combi, str, len); 577 } 571 combi = sh_util_strdup(str); 578 572 else 579 573 combi = NULL; … … 601 595 char *str; 602 596 char *combi; 603 size_t len;604 597 bigerr_t res; 605 598 … … 651 644 652 645 if (str != NULL) 653 { 654 len = sl_strlen(str) + 1; 655 combi = SH_ALLOC(len); 656 (void) sl_strlcpy (combi, str, len); 657 } 646 combi = sh_util_strdup(str); 658 647 else 659 648 combi = NULL; … … 679 668 char *combi; 680 669 char *str; 681 size_t len;682 670 bigerr_t res; 683 671 … … 700 688 701 689 if (str != NULL) 702 { 703 len = sl_strlen(str) + 1; 704 combi = SH_ALLOC(len); 705 (void) sl_strlcpy (combi, str, len); 706 } 690 combi = sh_util_strdup(str); 707 691 else 708 692 combi = NULL; -
trunk/src/sh_suidchk.c
r30 r34 854 854 else 855 855 { 856 basetmp = SH_ALLOC(1 + sl_strlen(theFile.fullpath)); 857 (void) sl_strlcpy(basetmp, theFile.fullpath, 858 1 + sl_strlen(theFile.fullpath)); 856 basetmp = sh_util_strdup(theFile.fullpath); 859 857 filetmp = SH_ALLOC(PATH_MAX+1); 860 858 (void) sl_snprintf(filetmp, PATH_MAX+1, "%s/%s", -
trunk/src/sh_tiger0.c
r30 r34 1665 1665 } 1666 1666 1667 if (what == TIGER_FILE )1667 if (what == TIGER_FILE && sl_ok_adds(sl_strlen (filename), (2 + 48 + 6))) 1668 1668 len = sl_strlen (filename) + 2 + 48 + 6; 1669 1669 else -
trunk/src/sh_tools.c
r30 r34 129 129 char tmp[4]; 130 130 char * outstr; 131 intlen = 1;131 size_t len = 1; 132 132 int i = 0; 133 133 unsigned char val_octal = '\0'; … … 138 138 139 139 if (instr) 140 len = (3 * strlen(instr)) + 4; 140 { 141 len = strlen(instr); 142 if (sl_ok_muls (3, len) && sl_ok_adds ((3*len), 4)) 143 { 144 len = (3 * len) + 4; 145 p = instr; 146 } 147 else 148 { 149 len = 1; 150 p = NULL; 151 } 152 } 153 else 154 { 155 p = NULL; 156 } 141 157 142 158 outstr = SH_ALLOC(len); … … 144 160 outstr[0] = '\0'; 145 161 tmp[3] = '\0'; 146 147 p = instr;148 162 149 163 #if !defined(SH_USE_XML) … … 460 474 461 475 int retval; 462 size_t len;463 476 464 477 sin_cache * check_cache = conn_cache; … … 534 547 else 535 548 { 536 len = sl_strlen(host_entry->h_name) + 1; 537 host_name = SH_ALLOC(len); 538 if (len > 1) 539 sl_strlcpy(host_name, host_entry->h_name, len); 540 else 541 host_name[0] = '\0'; 549 host_name = sh_util_strdup(host_entry->h_name); 542 550 } 543 551 … … 1096 1104 */ 1097 1105 char * sh_tools_makePack (unsigned char * header, 1098 char * payload, intpayload_size,1106 char * payload, unsigned long payload_size, 1099 1107 keyInstance * keyInstE) 1100 1108 { … … 1102 1110 unsigned char head[16]; 1103 1111 double epad; 1104 inti_epad = 0;1105 inti_blk = payload_size / 16;1106 inti_blkmax = SH_V2_FULLSIZE / 16;1107 intpads = 0;1108 intfull_size;1112 unsigned long i_epad = 0; 1113 unsigned long i_blk = payload_size / 16; 1114 unsigned long i_blkmax = SH_V2_FULLSIZE / 16; 1115 unsigned long pads = 0; 1116 size_t full_size; 1109 1117 char * full_ret; 1110 1118 … … 1116 1124 int err_num; 1117 1125 int blkfac; 1126 int oflow = 0; 1118 1127 1119 1128 /* … … 1152 1161 fprintf(stderr, "PAD1 <%d> <%f>\n", pads, epad); 1153 1162 #endif 1154 i_epad = ( int) (pads * epad);1163 i_epad = (unsigned long) (pads * epad); 1155 1164 #ifdef DEBUG_EN2 1156 1165 fprintf(stderr, "PAD2 <%d> <%d>\n", i_epad, (i_epad*16)); … … 1158 1167 } 1159 1168 1160 full_size = 1161 /* head */ 16 + 1162 /* payload */ (i_blk*16) + /* payload_size + */ 1163 /* pad */ (i_epad * 16); 1169 full_size = 16; /* head */ 1170 if (sl_ok_muls(i_blk, 16) && sl_ok_adds(full_size, (i_blk*16))) 1171 full_size = full_size + (i_blk*16); /* payload */ 1172 else 1173 oflow = 1; 1174 if (sl_ok_adds(full_size, (i_epad*16))) 1175 full_size = full_size + (i_epad*16); /* pad */ 1176 else 1177 i_epad = 0; 1178 1179 if (oflow) 1180 { 1181 sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN, 1182 _("integer overflow"), 1183 _("sh_tools_makePack")); 1184 } 1164 1185 1165 1186 full_ret = SH_ALLOC(full_size); 1166 1187 memcpy(full_ret, head, 16); 1167 if (payload != NULL )1188 if (payload != NULL && !oflow) 1168 1189 { 1169 1190 memcpy(&full_ret[16], payload, payload_size); 1170 1191 } 1171 if ((i_blk*16) > payload_size )1192 if ((i_blk*16) > payload_size && !oflow) 1172 1193 { 1173 1194 #ifdef DEBUG_EN2 … … 1354 1375 { 1355 1376 char hash[KEY_LEN+1]; 1356 char * temp ;1377 char * temp = NULL; 1357 1378 register int i; 1358 1379 int total = 0; … … 1374 1395 sl_strlcpy(hash, theSig, KEY_LEN+1); 1375 1396 1376 1377 total = KEY_LEN + buflen; 1378 temp = SH_ALLOC (total); 1379 1380 for (i = 0; i < KEY_LEN; ++i) 1381 temp[i] = hash[i]; 1382 1383 for (i = 0; i < buflen; ++i) 1384 temp[i+KEY_LEN] = buf[i]; 1385 1397 if (sl_ok_adds(buflen, KEY_LEN)) 1398 { 1399 total = KEY_LEN + buflen; 1400 temp = SH_ALLOC (total); 1401 1402 for (i = 0; i < KEY_LEN; ++i) 1403 temp[i] = hash[i]; 1404 1405 for (i = 0; i < buflen; ++i) 1406 temp[i+KEY_LEN] = buf[i]; 1407 } 1408 else 1409 { 1410 sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN, 1411 _("integer overflow"), 1412 _("hash_me")); 1413 temp = sh_util_strdup(buf); 1414 } 1386 1415 SL_RETURN(temp, _("hash_me")); 1387 1416 } … … 1423 1452 { 1424 1453 char * ret; 1425 int s ize, status;1454 int status; 1426 1455 struct stat buf; 1427 1456 char * base; 1457 size_t size; 1428 1458 1429 1459 SL_ENTER(_("get_client_conf_file")); 1430 1460 1431 size = sl_strlen(DEFAULT_DATAROOT); 1432 base = SH_ALLOC(size + 1); 1433 sl_strlcpy(base, DEFAULT_DATAROOT, size + 1); 1434 1435 size = sl_strlen(base) + sl_strlen(peer) + 5; 1436 ++size; 1461 base = sh_util_strdup(DEFAULT_DATAROOT); 1462 1463 size = sl_strlen(base); 1464 if (sl_ok_adds(size, sl_strlen(peer))) 1465 size += sl_strlen(peer); 1466 if (sl_ok_adds(size, 6)) 1467 size += 6; 1437 1468 1438 1469 ret = SH_ALLOC(size); … … 1461 1492 1462 1493 SH_FREE(base); 1494 SH_FREE(ret); 1463 1495 *length=0; 1464 1496 SL_RETURN(NULL, _("get_client_conf_file")); … … 1480 1512 { 1481 1513 char * ret; 1482 int s ize, status;1514 int status; 1483 1515 struct stat buf; 1484 1516 1485 1517 char * base; 1518 size_t size; 1486 1519 1487 1520 SL_ENTER(_("get_client_data_file")); 1488 1521 1489 size = sl_strlen(DEFAULT_DATAROOT);1490 base = SH_ALLOC(size + 1); 1491 s l_strlcpy(base, DEFAULT_DATAROOT, size + 1);1492 1493 size = sl_strlen(base) + sl_strlen(peer) + 7;1494 1495 ++size;1522 base = sh_util_strdup(DEFAULT_DATAROOT); 1523 1524 size = sl_strlen(base); 1525 if (sl_ok_adds(size, sl_strlen(peer))) 1526 size += sl_strlen(peer); 1527 if (sl_ok_adds(size, 8)) 1528 size += 8; 1496 1529 1497 1530 ret = SH_ALLOC(size); … … 1523 1556 *length = 0; 1524 1557 SH_FREE(base); 1558 SH_FREE(ret); 1525 1559 SL_RETURN(NULL, _("get_client_data_file")); 1526 1560 … … 1553 1587 int status = BAD; 1554 1588 char * my_tmp_dir; 1555 int len;1556 1589 1557 1590 SL_ENTER(_("open_tmp")); 1558 1591 1559 1592 #if defined(SH_TMPDIR) 1560 len = sl_strlen(SH_TMPDIR) + 1; 1561 my_tmp_dir = SH_ALLOC(len); 1562 sl_strlcpy(my_tmp_dir, SH_TMPDIR, len); 1593 my_tmp_dir = sh_util_strdup(SH_TMPDIR); 1563 1594 #else 1564 1595 #if defined(SH_WITH_SERVER) 1565 len = sl_strlen(DEFAULT_LOGDIR) + 1; 1566 my_tmp_dir = SH_ALLOC(len); 1567 sl_strlcpy(my_tmp_dir, DEFAULT_LOGDIR, len); 1596 my_tmp_dir = sh_util_strdup(DEFAULT_LOGDIR); 1568 1597 #else 1569 len = sl_strlen(sh.effective.home) + 1; 1570 my_tmp_dir = SH_ALLOC(len); 1571 sl_strlcpy(my_tmp_dir, sh.effective.home, len); 1598 my_tmp_dir = sh_util_strdup(sh.effective.home); 1572 1599 #endif 1573 1600 #endif -
trunk/src/sh_unix.c
r30 r34 331 331 int safe_logger (int signal, int method, char * details) 332 332 { 333 int i = 0;333 unsigned int i = 0; 334 334 int status = -1; 335 335 struct stat buf; … … 429 429 } 430 430 431 void safe_fatal ( int signal, int method,char * details,432 char * file, int line)431 void safe_fatal (char * details, 432 char * file, int line) 433 433 { 434 434 char msg[128]; 435 435 char str[128]; 436 436 char * p; 437 int signal = 0; 438 int method = 0; 439 437 440 p = safe_itoa((int) line, str, 128); 438 441 sl_strlcpy(msg, _("FATAL: "), 128); … … 2374 2377 2375 2378 if (sizeofline < 2) { 2376 line[ n] = '\0';2379 line[0] = '\0'; 2377 2380 SL_RETURN((0), _("sh_unix_getline")); 2378 2381 } 2382 2383 --sizeofline; 2379 2384 2380 2385 while (n < sizeofline) { … … 2872 2877 2873 2878 path = theFile->fullpath; 2874 2875 #if 02876 {2877 char pwd[256];2878 printf("%d %s %s %s (%s)\n", flagrel, theFile->fullpath, filename, path,2879 getcwd (pwd, 256));2880 }2881 #endif2882 2879 2883 2880 SL_ENTER(_("sh_unix_getinfo")); … … 3231 3228 else 3232 3229 { 3233 tmp = sh_util_ basename(theFile->fullpath);3230 tmp = sh_util_dirname(theFile->fullpath); 3234 3231 sl_strlcpy (theFile->linkpath, 3235 3232 tmp, … … 3392 3389 /* read the PID in the lock file 3393 3390 */ 3394 status = sh_unix_getline (fd, line_in, sizeof(line_in) -1);3391 status = sh_unix_getline (fd, line_in, sizeof(line_in)); 3395 3392 3396 3393 /* convert to numeric … … 3487 3484 int sh_unix_write_lock_file(char * filename) 3488 3485 { 3489 int i; 3486 size_t len; 3487 int res; 3490 3488 char * lockfile; 3491 3489 … … 3493 3491 return (-1); 3494 3492 3495 i = 6 + sl_strlen(filename); 3496 lockfile = SH_ALLOC(i); 3497 sl_strlcpy(lockfile, filename, i); 3498 sl_strlcat(lockfile, _(".lock"), i); 3499 i = sh_unix_test_and_lock(filename, lockfile); 3493 len = sl_strlen(filename); 3494 if (sl_ok_adds(len, 6)) 3495 len += 6; 3496 lockfile = SH_ALLOC(len); 3497 sl_strlcpy(lockfile, filename, len); 3498 sl_strlcat(lockfile, _(".lock"), len); 3499 res = sh_unix_test_and_lock(filename, lockfile); 3500 3500 SH_FREE(lockfile); 3501 return i;3501 return res; 3502 3502 } 3503 3503 … … 3541 3541 int sh_unix_rm_lock_file(char * filename) 3542 3542 { 3543 int i; 3543 size_t len; 3544 int res; 3544 3545 char * lockfile; 3545 3546 … … 3547 3548 return (-1); 3548 3549 3549 i = 6 + sl_strlen(filename); 3550 lockfile = SH_ALLOC(i); 3551 sl_strlcpy(lockfile, filename, i); 3552 sl_strlcat(lockfile, _(".lock"), i); 3553 i = sh_unix_unlock(lockfile, filename); 3550 len = sl_strlen(filename); 3551 if (sl_ok_adds(len, 6)) 3552 len += 6; 3553 lockfile = SH_ALLOC(len); 3554 sl_strlcpy(lockfile, filename, len); 3555 sl_strlcat(lockfile, _(".lock"), len); 3556 3557 res = sh_unix_unlock(lockfile, filename); 3554 3558 SH_FREE(lockfile); 3555 return i;3559 return res; 3556 3560 } 3557 3561 … … 4075 4079 #if !defined(SH_STEALTH_MICRO) 4076 4080 4077 static unsigned long off_data = 0;4078 static unsigned long max_data = 0;4079 static int stealth_init = BAD;4080 4081 4081 4082 int hideout_hex_block(SL_TICKET fd, unsigned char * str, int len); … … 4087 4088 int sh_unix_getline_stealth (SL_TICKET fd, char * str, int len) 4088 4089 { 4089 int add_off, llen; 4090 int add_off, llen; 4091 unsigned long off_data = 0; 4092 unsigned long max_data = 0; 4093 static int stealth_init = BAD; 4090 4094 4091 4095 SL_ENTER(_("sh_unix_getline_stealth")); 4096 4092 4097 4093 4098 /* --- Initialize. --- … … 4132 4137 4133 4138 SL_ENTER(_("hideout_hex_block")); 4139 4140 ASSERT_RET((len > 1), _("len > 1"), (0)); 4141 4142 --len; 4134 4143 4135 4144 i = 0; … … 4151 4160 } while (num == 0 && errno == EINTR); 4152 4161 if (num == 0) 4153 SL_RETURN(( -1), _("hideout_hex_block"));4162 SL_RETURN((0), _("hideout_hex_block")); 4154 4163 ++here; 4155 4164 } while (c == '\n' || c == '\t' || c == '\r' || … … 4174 4183 str[i] = '\0'; 4175 4184 else 4176 str[i+1] = '\0'; 4185 str[i+1] = '\0'; /* keep newline and terminate */ 4177 4186 retval += here; 4178 4187 … … 4184 4193 unsigned long first_hex_block(SL_TICKET fd, unsigned long * max) 4185 4194 { 4186 int i; 4187 register int num = 1; 4195 unsigned int i; 4196 long num = 1; 4197 unsigned long lnum; 4188 4198 char c; 4189 4199 int nothex = 0; 4190 4200 unsigned long retval = 0; 4191 intthis_line = 0;4201 unsigned int this_line = 0; 4192 4202 char theline[SH_BUFSIZE]; 4193 4203 … … 4201 4211 this_line = 0; 4202 4212 c = '\0'; 4203 while (c != '\n' && num > 0 )4213 while (c != '\n' && num > 0 && this_line < (sizeof(theline)-1)) 4204 4214 { 4205 4215 do { … … 4210 4220 else 4211 4221 SL_RETURN((0), _("first_hex_block")); 4212 this_line += num;4222 ++this_line; 4213 4223 } 4214 4224 theline[this_line] = '\0'; … … 4239 4249 num = sl_read (fd, theline, SH_BUFSIZE); 4240 4250 } while (num == 0 && errno == EINTR); 4241 for (i = 0; i < num; ++i) 4242 { 4243 c = theline[i]; 4244 if (c == '\n' || c == '\t' || c == '\r' || c == ' ') 4245 ; 4246 else if (!isxdigit((int)c)) 4247 break; 4248 else 4249 *max += 1; 4251 if (num > 0) 4252 { 4253 lnum = (unsigned long) num; 4254 for (i = 0; i < lnum; ++i) 4255 { 4256 c = theline[i]; 4257 if (c == '\n' || c == '\t' || c == '\r' || c == ' ') 4258 ; 4259 else if (!isxdigit((int)c)) 4260 break; 4261 else 4262 *max += 1; 4263 } 4250 4264 } 4251 4265 } while (num > 0); -
trunk/src/sh_utils.c
r29 r34 270 270 size = sl_strlen(formatt); 271 271 272 fmt = (char *) SH_ALLOC(size + 1); 273 (void) sl_strlcpy(fmt, formatt, size + 1); 272 if (!sl_ok_adds(size, 1)) 273 SL_RETURN(NULL, _("sh_util_formatted")); 274 275 ++size; 276 fmt = SH_ALLOC(size); 277 (void) sl_strlcpy(fmt, formatt, size); 274 278 275 279 p = fmt; … … 319 323 { 320 324 isiz = sl_strlen(ftab[j].data_str); 321 if (isiz > 0 )325 if (isiz > 0 && sl_ok_adds(size, isiz)) 322 326 { 323 327 size += isiz; … … 339 343 /*@+bufferoverflowhigh@*/ 340 344 isiz = sl_strlen(ftab[j].data_str); 341 if (isiz > 0 )345 if (isiz > 0 && sl_ok_adds(size, isiz)) 342 346 { 343 347 size += isiz; … … 359 363 /*@+bufferoverflowhigh@*/ 360 364 isiz = sl_strlen(ftab[j].data_str); 361 if (isiz > 0 )365 if (isiz > 0 && sl_ok_adds(size, isiz)) 362 366 { 363 367 size += isiz; … … 391 395 } 392 396 isiz = sl_strlen(ftab[j].data_str); 393 if (isiz > 0 )397 if (isiz > 0 && sl_ok_adds(size, isiz)) 394 398 { 395 399 size += isiz; … … 431 435 /* -- closing '\0' -- 432 436 */ 433 size++; 437 if (sl_ok_adds(size, 1)) 438 size++; 434 439 outstr = (char *) SH_ALLOC(size); 435 440 … … 441 446 clist[8], clist[9], clist[10], clist[11], 442 447 clist[12], clist[13], clist[14], clist[15]); 443 448 outstr[size-1] = '\0'; 449 444 450 /* -- cleanup -- 445 451 */ … … 491 497 SL_ENTER(_("sh_util_hextobinary")); 492 498 493 while (i < bytes) 499 if (bytes < 2) 500 SL_RETURN((-1), _("sh_util_hextobinary")); 501 502 while (i < (bytes-1)) 494 503 { 495 504 SH_HEXCHAR(hex[i], k); … … 498 507 binary[l] = (char)(k * 16 + j); 499 508 ++l; i+= 2; 500 501 /* k = sh_util_hexchar(hex[i]); j = sh_util_hexchar(hex[i+1]);502 if (k != -1 && j != -1)503 {504 binary[l] = (char)(k * 16 + j);505 ++l; i+= 2;506 }507 else508 {509 SL_RETURN((-1), _("sh_util_hextobinary"));510 }511 */512 509 } 513 510 … … 581 578 } 582 579 583 inner = (char *) SH_ALLOC (textlen + KEY_BLOCK); 584 585 for (i = 0; i < KEY_BLOCK; ++i) 586 { 587 outer[i] = K[i] ^ opad[i]; 588 inner[i] = K[i] ^ ipad[i]; 589 } 590 for (i = KEY_BLOCK; i < (KEY_BLOCK+textlen); ++i) 591 { 592 inner[i] = text[i - KEY_BLOCK]; 580 if (sl_ok_adds(textlen, KEY_BLOCK)) 581 { 582 inner = (char *) SH_ALLOC (textlen + KEY_BLOCK); 583 584 for (i = 0; i < KEY_BLOCK; ++i) 585 { 586 outer[i] = K[i] ^ opad[i]; 587 inner[i] = K[i] ^ ipad[i]; 588 } 589 for (i = KEY_BLOCK; i < (KEY_BLOCK+textlen); ++i) 590 { 591 inner[i] = text[i - KEY_BLOCK]; 592 } 593 } 594 else 595 { 596 sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN, 597 _("integer overflow"), 598 _("sh_util_hmac_tiger")); 599 res = sh_tiger_hash (NULL, TIGER_DATA, 0); 600 SL_RETURN(res, _("sh_util_hmac_tiger")); 593 601 } 594 602 … … 1421 1429 /* returns freshly allocated memory, return value should be free'd 1422 1430 */ 1423 char * sh_util_ basename(char * fullpath)1431 char * sh_util_dirname(const char * fullpath) 1424 1432 { 1425 1433 char * retval; 1426 size_t i; 1434 size_t len; 1435 1436 SL_ENTER(_("sh_util_dirname")); 1437 1438 ASSERT_RET ((fullpath != NULL), _("fullpath != NULL"), (NULL)) 1439 1440 len = sl_strlen (fullpath); /* fullpath[i] is terminating '\0' */ 1441 1442 if (len > 1 && fullpath[len-1] == '/') /* skip trailing '/' */ 1443 --len; 1444 1445 while (len > 0) { 1446 --len; 1447 if (fullpath[len] == '/') 1448 { 1449 if (len == 0) ++len; /* copy the '/' to output */ 1450 break; 1451 } 1452 } 1453 1454 /* -- Not an absolute path. -- 1455 */ 1456 if ((len == 0) && (fullpath[len] != '/')) 1457 { 1458 SL_RETURN(NULL, _("sh_util_dirname")); 1459 } 1460 1461 retval = SH_ALLOC(len + 1); 1462 (void) sl_strlcpy (retval, fullpath, len+1); 1463 1464 SL_RETURN(retval, _("sh_util_dirname")); 1465 } 1466 1467 /* returns freshly allocated memory, return value should be free'd 1468 */ 1469 char * sh_util_basename(const char * fullpath) 1470 { 1471 char * retval = NULL; 1472 char * tmp; 1473 char * c; 1474 size_t len; 1427 1475 1428 1476 SL_ENTER(_("sh_util_basename")); … … 1430 1478 ASSERT_RET ((fullpath != NULL), _("fullpath != NULL"), (NULL)) 1431 1479 1432 i = sl_strlen (fullpath); /* fullpath[i] is terminating '\0' */ 1433 1434 while (i > 0) { 1435 --i; 1436 if (fullpath[i] == '/') break; 1437 } 1438 1439 /* -- Not a valid path. -- 1440 */ 1441 if ((fullpath[i] != '/') && (i == 0) ) 1442 SL_RETURN(NULL, _("sh_util_basename")); 1443 1444 retval = SH_ALLOC(i + 1); 1445 1446 (void) sl_strlcpy (retval, fullpath, i+1); 1480 c = strrchr(fullpath, '/'); 1481 len = sl_strlen (c); 1482 1483 if (c == fullpath) 1484 { 1485 if (len <= 1) 1486 retval = sh_util_strdup(c); 1487 else 1488 retval = sh_util_strdup(++c); 1489 } 1490 else 1491 { 1492 if (len > 1) 1493 { 1494 retval = sh_util_strdup(++c); 1495 } 1496 else 1497 { 1498 /* input ends in '/' */ 1499 tmp = sh_util_strdup(fullpath); 1500 tmp[strlen(tmp)-1] = '\0'; 1501 retval = sh_util_basename(tmp); 1502 SH_FREE(tmp); 1503 } 1504 } 1447 1505 1448 1506 SL_RETURN(retval, _("sh_util_basename")); 1449 }1450 1451 /* returns freshly allocated memory, return value should be free'd1452 */1453 char * sh_util_filename(char * fullpath)1454 {1455 char * retval;1456 char * c;1457 size_t i;1458 1459 SL_ENTER(_("sh_util_filename"));1460 1461 ASSERT_RET ((fullpath != NULL), _("fullpath != NULL"), (NULL))1462 1463 c = strrchr(fullpath, '/');1464 i = sl_strlen (c);1465 if (i <= 1) SL_RETURN(NULL, _("sh_util_filename")); /* ends in '/' */1466 ++c;1467 --i;1468 1469 retval = SH_ALLOC(i + 1);1470 1471 (void) sl_strlcpy (retval, c, i+1);1472 1473 SL_RETURN(retval, _("sh_util_filename"));1474 1507 } 1475 1508 … … 1484 1517 char oct[32]; 1485 1518 char format[16]; 1519 size_t len; 1486 1520 1487 1521 SL_ENTER(_("sh_util_safe_name")); … … 1500 1534 */ 1501 1535 1536 len = sl_strlen(name); 1537 p = name; 1538 1502 1539 #ifdef SH_USE_XML 1503 retval = SH_ALLOC(6 * sl_strlen(name) + 2); 1540 if (sl_ok_muls (6, len) && sl_ok_adds ((6*len), 2)) 1541 { retval = SH_ALLOC(6 * len + 2); } 1542 else 1543 { 1544 /* return an allocated array 1545 */ 1546 retval = SH_ALLOC(11); 1547 (void) sl_strlcpy(retval, _("(overflow)"), 11); 1548 SL_RETURN(retval, _("sh_util_safe_name")); 1549 } 1504 1550 #else 1505 retval = SH_ALLOC(4 * sl_strlen(name) + 2); 1551 if (sl_ok_muls (4, len) && sl_ok_adds ((4*len), 2)) 1552 { retval = SH_ALLOC(4 * len + 2); } 1553 else 1554 { 1555 /* return an allocated array 1556 */ 1557 retval = SH_ALLOC(11); 1558 (void) sl_strlcpy(retval, _("(overflow)"), 11); 1559 SL_RETURN(retval, _("sh_util_safe_name")); 1560 } 1506 1561 #endif 1507 1562 1508 1563 (void) sl_strncpy(format, _("%c%03o"), 16); 1509 1510 p = name;1511 1564 1512 1565 while (*p != '\0') { … … 1613 1666 char * sh_util_strconcat (const char * arg1, ...) 1614 1667 { 1615 size_t length ;1668 size_t length, l2; 1616 1669 char * s; 1617 1670 char * strnew; … … 1628 1681 while (s != NULL) 1629 1682 { 1630 length = length + sl_strlen (s); 1683 l2 = sl_strlen (s); 1684 if (sl_ok_adds(length, l2)) 1685 length += l2; 1686 else 1687 SL_RETURN(NULL, _("sh_util_strconcat")); 1631 1688 s = va_arg (vl, char * ); 1632 1689 } 1633 1690 va_end (vl); 1634 1691 1635 strnew = SH_ALLOC( length + 2 ); 1692 if (sl_ok_adds(length, 2)) 1693 strnew = SH_ALLOC( length + 2 ); 1694 else 1695 SL_RETURN(NULL, _("sh_util_strconcat")); 1696 1636 1697 strnew[0] = '\0'; 1637 1698 … … 1680 1741 if (status != 0 && status != REG_NOMATCH) 1681 1742 { 1682 errbuf = SH_ALLOC(BUFSIZ +2);1743 errbuf = SH_ALLOC(BUFSIZ); 1683 1744 (void) regerror(status, &preg, errbuf, BUFSIZ); 1684 errbuf[BUFSIZ ] = '\0';1745 errbuf[BUFSIZ-1] = '\0'; 1685 1746 sh_error_handle ((-1), FIL__, __LINE__, status, MSG_E_REGEX, 1686 1747 errbuf, regex_str); -
trunk/src/sh_utmp.c
r30 r34 440 440 memcpy (&c, &bar[2], 1); 441 441 memcpy (&d, &bar[3], 1); 442 sprintf(foo, "%d.%d.%d.%d",/* known to fit */442 sprintf(foo, _("%d.%d.%d.%d"), /* known to fit */ 443 443 (int) a, (int) b, (int) c, (int) d); 444 444 return foo; … … 1064 1064 )) 1065 1065 sh_utmp_addlogin (ut); 1066 /*************************************************1067 printf("%8s | %10s | %10s | %3d %5d | %16s | %ld\n",1068 ut->ut_name, ut->ut_id, ut->ut_line,1069 (int) ut->ut_type, (int) ut->ut_pid,1070 ut->ut_host, ut->ut_time);1071 ***************************************************/1072 1066 ++this_read; 1073 1067 } -
trunk/src/slib.c
r29 r34 7 7 #include <string.h> 8 8 #include <limits.h> 9 #ifdef HAVE_STDINT_H 10 /* for SIZE_MAX */ 11 #include <stdint.h> 12 #endif 9 13 10 14 #include <unistd.h> … … 2506 2510 * ---------------------------------------------------------------- */ 2507 2511 2512 #ifndef SIZE_MAX 2513 #define SIZE_MAX (4294967295U) 2514 #endif 2515 2508 2516 int sl_ok_muli (int a, int b) /* a*b */ 2509 2517 { 2510 if (a >= (INT_MIN / b) && a <= (INT_MAX / b)) 2518 if ((b == 0) || (a >= (INT_MIN / b) && a <= (INT_MAX / b))) 2519 return SL_TRUE; /* no overflow */ 2520 return SL_FALSE; 2521 } 2522 2523 int sl_ok_muls (size_t a, size_t b) /* a*b */ 2524 { 2525 if ((b == 0) || (a <= (SIZE_MAX / b))) 2511 2526 return SL_TRUE; /* no overflow */ 2512 2527 return SL_FALSE; … … 2540 2555 } 2541 2556 2557 int sl_ok_adds (size_t a, size_t b) /* a+b */ 2558 { 2559 if (a <= (SIZE_MAX - b)) 2560 return SL_TRUE; /* no overflow */ 2561 else 2562 return SL_FALSE; 2563 } 2564 2542 2565 int sl_ok_subi (int a, int b) /* a-b */ 2543 2566 { -
trunk/src/yulectl.c
r22 r34 392 392 return; 393 393 } 394 if (NULL == fgets(message2, SH_MAXMSG, fp))394 if (NULL == fgets(message2, sizeof(message2), fp)) 395 395 { 396 396 fprintf (stderr, … … 545 545 else 546 546 { 547 fprintf(stderr, "ERROR: this command requires a hostname\n");547 fprintf(stderr, _("ERROR: this command requires a hostname\n")); 548 548 usage(argv[0]); 549 549 return (EXIT_FAILURE); … … 567 567 return (EXIT_FAILURE); 568 568 } 569 #ifdef HAVE_VSNPRINTF 570 snprintf(sockname, size, _("%s/%s.sock"), clientcd, CLIENT); 571 #else 569 572 sprintf(sockname, _("%s/%s.sock"), clientcd, CLIENT); 570 573 #endif 571 574 572 575 /* Make the socket. -
trunk/test/testrc_2.in
r22 r34 40 40 file = /tmp 41 41 file = /etc 42 43 dir=1/usr 42 44 43 45 [EventSeverity] -
trunk/test/testrun_2.sh
r30 r34 239 239 ORIGINAL_4="# SetClientTimeLimit=1800" 240 240 REPLACEMENT_4="SetClientTimeLimit=20" 241 # takes too much time if we leave that in 242 ORIGINAL_5="dir=1" 243 REPLACEMENT_5="#dir=1" 241 244 ex $RCFILE <<EOF 242 245 %s/${ORIGINAL_1}/${REPLACEMENT_1}/g … … 244 247 %s/${ORIGINAL_3}/${REPLACEMENT_3}/g 245 248 %s/${ORIGINAL_4}/${REPLACEMENT_4}/g 249 %s/${ORIGINAL_5}/${REPLACEMENT_5}/g 246 250 wq 247 251 EOF
Note:
See TracChangeset
for help on using the changeset viewer.