- Timestamp:
- Jul 8, 2008, 11:16:14 AM (17 years ago)
- Location:
- trunk/src
- Files:
-
- 1 added
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/cutest_sh_unix.c
r30 r171 7 7 #include "sh_unix.h" 8 8 9 int malloc_count = 0; 10 11 void Test_dnmalloc (CuTest *tc) { 12 13 const int nalloc = 64 /* original dnmalloc 1.0-beta5 fails fo >= 45 */; 14 int j, i; 15 int sum; 16 int i_malloc = malloc_count; 17 18 char * buf; 19 char * area[256]; 20 21 /* test reuse of last freed chunk */ 22 buf = malloc(1024); 23 CuAssertPtrNotNull(tc, buf); 24 free(buf); 25 area[0] = malloc(1024); 26 CuAssertTrue(tc, buf == area[0]); 27 free(area[0]); 28 29 /* test realloc */ 30 buf = malloc(16); 31 CuAssertPtrNotNull(tc, buf); 32 strcpy(buf, "testing realloc"); 33 buf = realloc(buf, 32); 34 strcat(buf, "testing realloc"); 35 CuAssertStrEquals(tc, "testing realloctesting realloc", buf); 36 37 i_malloc = malloc_count; 38 39 for (j = 0; j < 64; ++j) 40 { 41 buf = malloc((j+1) * 1024); 42 CuAssertPtrNotNull(tc, buf); 43 #ifndef USE_SYSTEM_MALLOC 44 CuAssertIntEquals (tc, malloc_count, (i_malloc + 1)); 45 #endif 46 free(buf); 47 #ifndef USE_SYSTEM_MALLOC 48 CuAssertIntEquals (tc, malloc_count, i_malloc); 49 #endif 50 } 51 52 /* test realloc */ 53 buf = malloc(16); 54 CuAssertPtrNotNull(tc, buf); 55 strcpy(buf, "testing realloc"); 56 buf = realloc(buf, 32); 57 strcat(buf, "testing realloc"); 58 CuAssertStrEquals(tc, "testing realloctesting realloc", buf); 59 60 i_malloc = malloc_count; 61 62 for (j = 0; j < 64; ++j) 63 { 64 buf = calloc(1, (j+1) * 1024); 65 CuAssertPtrNotNull(tc, buf); 66 #ifndef USE_SYSTEM_MALLOC 67 CuAssertIntEquals (tc, malloc_count, (i_malloc + 1)); 68 #endif 69 sum = 0; 70 for (i = 0; i < ((j+1) * 1024); ++i) 71 sum += buf[i]; 72 CuAssertIntEquals (tc, 0, sum); 73 free(buf); 74 #ifndef USE_SYSTEM_MALLOC 75 CuAssertIntEquals (tc, malloc_count, i_malloc); 76 #endif 77 } 78 79 /* test realloc */ 80 buf = malloc(16); 81 CuAssertPtrNotNull(tc, buf); 82 strcpy(buf, "testing realloc"); 83 buf = realloc(buf, 32); 84 strcat(buf, "testing realloc"); 85 CuAssertStrEquals(tc, "testing realloctesting realloc", buf); 86 87 for (j = 0; j < nalloc; ++j) 88 { 89 area[j] = malloc((j+1) * 1024); 90 CuAssertPtrNotNull(tc, area[j]); 91 #ifndef USE_SYSTEM_MALLOC 92 // CuAssertIntEquals (tc, malloc_count, (i_malloc + (j+1))); 93 #endif 94 memset(area[j], (unsigned char) ('a'+1), (j+1) * 1024); 95 } 96 97 i_malloc = malloc_count; 98 99 for (j = 0; j < nalloc; ++j) 100 { 101 sum = 0; 102 for (i = 0; i < ((j+1) * 1024); ++i) 103 sum += area[j][i]; 104 CuAssertIntEquals (tc, sum, ((j+1) * 1024 * ((unsigned char) ('a'+1)))); 105 free(area[j]); 106 #ifndef USE_SYSTEM_MALLOC 107 CuAssertIntEquals (tc, malloc_count, i_malloc - (j+1)); 108 #endif 109 } 110 111 /* test realloc */ 112 buf = malloc(16); 113 CuAssertPtrNotNull(tc, buf); 114 strcpy(buf, "testing realloc"); 115 buf = realloc(buf, 32); 116 strcat(buf, "testing realloc"); 117 CuAssertStrEquals(tc, "testing realloctesting realloc", buf); 118 119 120 for (j = 0; j < 32; ++j) 121 { 122 i_malloc = malloc_count; 123 buf = malloc((j+1) * 1024 * 1024); 124 CuAssertPtrNotNull(tc, buf); 125 for (i = 0; i < 32; ++i) 126 { 127 area[i] = malloc((i+1) * 1024); 128 CuAssertPtrNotNull(tc, area[i]); 129 } 130 free(buf); 131 for (i = 0; i < 32; ++i) 132 { 133 free(area[i]); 134 } 135 #ifndef USE_SYSTEM_MALLOC 136 CuAssertIntEquals (tc, malloc_count, i_malloc); 137 #endif 138 } 139 140 /* test realloc */ 141 buf = malloc(16); 142 CuAssertPtrNotNull(tc, buf); 143 strcpy(buf, "testing realloc"); 144 buf = realloc(buf, 32); 145 strcat(buf, "testing realloc"); 146 CuAssertStrEquals(tc, "testing realloctesting realloc", buf); 147 } 148 149 9 150 void Test_sh_unix_lookup_page (CuTest *tc) { 10 151 -
trunk/src/make-tests.sh
r29 r171 57 57 int main(void) 58 58 { 59 #if !defined(USE_SYSTEM_MALLOC) && defined(USE_MALLOC_LOCK) 60 extern int dnmalloc_pthread_init(void); 61 dnmalloc_pthread_init(); 62 #endif 59 63 int retval; 60 64 retval = RunAllTests(); -
trunk/src/samhain.c
r170 r171 169 169 void sh_g_init(void) 170 170 { 171 #if !defined(USE_SYSTEM_MALLOC) && defined(USE_MALLOC_LOCK) 172 extern int dnmalloc_pthread_init(void); 173 dnmalloc_pthread_init(); 174 #endif 175 171 176 if (0 != pthread_key_create(&g_key, sh_g_destroy)) 172 177 { … … 2152 2157 #endif 2153 2158 2159 #if 0 2160 { 2161 char command[128]; 2162 sprintf(command, "/bin/cat /proc/%d/status", (int) getpid()); 2163 system(command); /* flawfinder: ignore *//* debug code */ 2164 malloc_stats(); 2165 } 2166 #endif 2167 2154 2168 aud_exit (FIL__, __LINE__, EXIT_SUCCESS); 2155 2169 SL_RETURN(0, _("main")); -
trunk/src/samhain_setpwd.c
r170 r171 8 8 #include <unistd.h> 9 9 #include <sys/types.h> 10 #include <signal.h> 10 11 #include <sys/wait.h> 11 12 #include <sys/stat.h> … … 70 71 } 71 72 72 while (nbytes){73 do { 73 74 count = read(fd, &buf[where], nbytes); 74 75 if (count == -1 && errno == EINTR) … … 76 77 where += count; 77 78 nbytes -= count; 78 } while ( count == -1 && errno == EINTR);79 } while (nbytes); 79 80 80 81 close(fd); -
trunk/src/sh_calls.c
r170 r171 183 183 val_retry = 184 184 /*@-unrecog@*/connect(sockfd, serv_addr, addrlen)/*@+unrecog@*/; 185 } while (val_retry < 0 && errno == EINTR);185 } while (val_retry < 0 && (errno == EINTR || errno == EINPROGRESS)); 186 186 } 187 187 -
trunk/src/sh_entropy.c
r170 r171 147 147 struct sockaddr_un addr; 148 148 int addr_len; 149 int retval; 149 150 150 151 #ifdef EGD_SOCKET_NAME … … 184 185 SL_RETURN( -1, _("sh_entropy") ); 185 186 } 186 if( connect( fd, (struct sockaddr*)&addr, addr_len) == -1 ) 187 do { 188 retval = connect(fd, (struct sockaddr *) &sinr, sizeof(sinr)); 189 } while (retval < 0 && (errno == EINTR || errno == EINPROGRESS)); 190 if( retval == -1 ) 187 191 { 188 192 myerror = errno; … … 682 686 status = -1; 683 687 } 688 #if !defined(USE_UNO) 684 689 else if (WIFSIGNALED(status)) 685 690 { … … 692 697 status = -1; 693 698 } 699 #endif 694 700 695 701 source->pipe = NULL; -
trunk/src/sh_files.c
r170 r171 2254 2254 int sh_files_test_double (zAVLTree * firstList, zAVLTree * secondList) 2255 2255 { 2256 int count;2257 2256 int retval = 0; 2258 2259 2257 zAVLCursor cursor; 2260 2261 2258 dirstack_t * first; 2262 2259 … … 2267 2264 if (NULL != zAVLSearch(secondList, first->name)) 2268 2265 { 2269 ++count;2270 2266 sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_FI_DOUBLE, 2271 2267 first->name); -
trunk/src/sh_forward.c
r170 r171 2644 2644 sizeof(addr_peer.sin_addr))) 2645 2645 break; 2646 ++i;2647 2646 } 2648 2647 } … … 4916 4915 struct sigaction new_act; 4917 4916 struct sigaction old_act; 4917 4918 int setsize_fd; 4918 4919 4919 4920 SL_ENTER(_("sh_receive")); … … 4946 4947 * The POSIX lower limit on open files seems to be eight. 4947 4948 */ 4948 maxconn = get_open_max() - 6; 4949 maxconn = (((int)FD_SETSIZE) < maxconn) ? FD_SETSIZE : maxconn; 4949 maxconn = get_open_max() - 6; 4950 /* ugly fix for FreeBSD compiler warning; casting FD_SETSIZE in the 4951 * conditional expression does not suppress the warning... */ 4952 setsize_fd = (int)FD_SETSIZE; 4953 maxconn = (setsize_fd < maxconn) ? setsize_fd : maxconn; 4950 4954 4951 4955 if (maxconn < 0 || !sl_ok_muls(maxconn, sizeof(sh_conn_t))) -
trunk/src/sh_getopt.c
r170 r171 315 315 static void sh_getopt_print_log_facilities (void) 316 316 { 317 fputs (_("Compiled-in log facilities:"), stdout); 317 int num = 0; 318 319 fputs (_("Compiled-in log facilities:\n"), stdout); 318 320 319 321 #ifndef DEFAULT_CONSOLE 320 printf (_(" console (/dev/console)")); 322 if (num > 0) fputc ('\n', stdout); 323 printf (_(" console (/dev/console)")); ++num; 321 324 #else 325 if (num > 0) fputc ('\n', stdout); 322 326 if (0 == strcmp (DEFAULT_CONSOLE, _("NULL"))) 323 printf (_(" console (/dev/console)"));327 { printf (_("console (/dev/console)")); ++num; } 324 328 else 325 printf (_(" console (%s)"), DEFAULT_CONSOLE); 326 #endif 327 fputs (_(", syslog"), stdout); 328 printf (_(", logfile (%s)"), DEFAULT_ERRFILE); 329 { printf (_("console (%s)"), DEFAULT_CONSOLE); ++num; } 330 #endif 331 if (num > 0) fputc ('\n', stdout); 332 fputs (_(" syslog"), stdout); ++num; 333 if (num > 0) fputc ('\n', stdout); 334 printf (_(" logfile (%s)"), DEFAULT_ERRFILE); ++num; 329 335 330 336 #if defined(WITH_EXTERNAL) 331 fputs (_(", external program"), stdout); 337 if (num > 0) fputc ('\n', stdout); 338 fputs (_(" external program"), stdout); ++num; 332 339 #endif 333 340 334 341 #if defined(WITH_MESSAGE_QUEUE) 335 fputs (_(", message queue"), stdout); 342 if (num > 0) fputc ('\n', stdout); 343 fputs (_(" message queue"), stdout); ++num; 336 344 #endif 337 345 338 346 #if defined(WITH_DATABASE) 339 fputs (_(", database"), stdout); 347 if (num > 0) fputc ('\n', stdout); 348 fputs (_(" database"), stdout); ++num; 340 349 #ifdef WITH_ODBC 341 350 fputs (_(" (odbc)"), stdout); … … 353 362 354 363 #if defined(SH_WITH_CLIENT) || defined(SH_WITH_SERVER) 355 fputs (_(", server"), stdout); 364 if (num > 0) fputc ('\n', stdout); 365 fputs (_(" server"), stdout); ++num; 356 366 #endif 357 367 358 368 #if defined(SH_WITH_MAIL) 359 fputs (_(", email"), stdout); 369 if (num > 0) fputc ('\n', stdout); 370 fputs (_(" email"), stdout); ++num; 360 371 #endif 361 372 362 373 #ifdef HAVE_LIBPRELUDE 374 if (num > 0) fputc ('\n', stdout); ++num; 363 375 #ifdef HAVE_LIBPRELUDE_8 364 fputs (_(" ,prelude (0.8)"), stdout);376 fputs (_(" prelude (0.8)"), stdout); 365 377 #else 366 fputs (_(", prelude (0.9+)"), stdout); 367 #endif 368 #endif 369 370 fputc ('\n', stdout); 371 return; 372 } 373 374 static void sh_getopt_print_options (void) 375 { 376 int num = 0; 377 378 379 #if defined(SH_STANDALONE) 380 if (num > 0) fputc ('\n', stdout); 381 fputs (_("Standalone executable"), stdout); ++num; 382 #endif 383 #if defined(SH_WITH_CLIENT) 384 if (num > 0) fputc ('\n', stdout); 385 printf (_("Client executable (port %d)"), SH_DEFAULT_PORT); ++num; 386 #endif 387 #if defined(SH_WITH_CLIENT) 388 if (num > 0) fputc ('\n', stdout); 389 printf (_("Server executable (port %d, user %s)"), 390 SH_DEFAULT_PORT, DEFAULT_IDENT); 391 ++num; 392 #endif 393 394 fputs (_(", compiled-in options:"), stdout); 395 396 #if defined(HAVE_EGD_RANDOM) 397 if (num > 0) fputc ('\n', stdout); 398 printf (_(" use entropy gathering daemon (%s)"), EGD_SOCKET_NAME); ++num; 399 #endif 400 #if defined(HAVE_UNIX_RANDOM) 401 if (num > 0) fputc ('\n', stdout); 402 fputs (_(" use unix entropy gatherer"), stdout); ++num; 403 #endif 404 #if defined(HAVE_URANDOM) 405 if (num > 0) fputc ('\n', stdout); 406 printf (_(" use entropy device (%s)"), NAME_OF_DEV_RANDOM); ++num; 407 #endif 408 409 #ifdef WITH_GPG 410 if (num > 0) fputc ('\n', stdout); 411 printf (_(" GnuPG signatures (%s)"), DEFAULT_GPG_PATH); ++num; 412 #ifdef HAVE_GPG_CHECKSUM 413 if (num > 0) fputc ('\n', stdout); 414 printf (_(" -- GnuPG checksum: %s"), GPG_HASH); ++num; 415 #endif 416 #ifdef USE_FINGERPRINT 417 if (num > 0) fputc ('\n', stdout); 418 printf (_(" -- Key fingerprint: %s"), SH_GPG_FP); ++num; 419 #endif 420 #endif 421 422 #if defined(SL_DEBUG) 423 if (num > 0) fputc ('\n', stdout); 424 fputs (_(" debug build (don't use for production)"), stdout); ++num; 425 #endif 426 #if defined(SCREW_IT_UP) 427 if (num > 0) fputc ('\n', stdout); 428 fputs (_(" anti-debugger"), stdout); ++num; 429 #endif 430 #if defined(SH_USE_XML) 431 if (num > 0) fputc ('\n', stdout); 432 fputs (_(" xml log format"), stdout); ++num; 433 #endif 434 #if defined(HAVE_NTIME) 435 if (num > 0) fputc ('\n', stdout); 436 fputs (_(" use time server"), stdout); ++num; 437 #endif 438 439 #if defined(SH_WITH_CLIENT) || defined(SH_STANDALONE) 440 #if defined(HAVE_LIBZ) 441 if (num > 0) fputc ('\n', stdout); 442 fputs (_(" optionally store full text for files"), stdout); ++num; 443 #endif 444 #if defined(USE_XATTR) 445 if (num > 0) fputc ('\n', stdout); 446 fputs (_(" check SELinux attributes"), stdout); ++num; 447 #endif 448 #if defined(USE_ACL) 449 if (num > 0) fputc ('\n', stdout); 450 fputs (_(" check Posix ACLs"), stdout); ++num; 451 #endif 452 #if defined(RELOAD_DATABASE) 453 if (num > 0) fputc ('\n', stdout); 454 fputs (_(" fetch database on reload"), stdout); ++num; 455 #endif 456 #endif 457 458 #if defined(SH_WITH_SERVER) 459 460 #if !defined(HAVE_GETPEEREID) && !defined(SO_PEERCRED) && !defined(HAVE_STRUCT_CMSGCRED) && !defined(HAVE_STRUCT_FCRED) && !(defined(HAVE_STRUCT_SOCKCRED) && defined(LOCAL_CREDS)) 461 if (num > 0) fputc ('\n', stdout); 462 fputs (_(" command socket authentication: use SetSocketPassword"), stdout); 463 ++num; 464 #else 465 if (num > 0) fputc ('\n', stdout); 466 fputs (_(" command socket authentication: use SetSocketAllowUID"), stdout); 467 ++num; 468 #endif 469 470 #if defined(SH_USE_LIBWRAP) 471 if (num > 0) fputc ('\n', stdout); 472 fputs (_(" support tcp wrapper"), stdout); ++num; 473 #endif 474 #if defined(INET_SYSLOG) 475 if (num > 0) fputc ('\n', stdout); 476 fputs (_(" support listening on 514/udp (syslog)"), stdout); ++num; 378 fputs (_(" prelude (0.9+)"), stdout); 477 379 #endif 478 380 #endif … … 484 386 } 485 387 388 static void sh_getopt_print_options (void) 389 { 390 int num = 0; 391 392 393 #if defined(SH_STANDALONE) 394 if (num > 0) fputc ('\n', stdout); 395 fputs (_("Standalone executable"), stdout); ++num; 396 #endif 397 #if defined(SH_WITH_CLIENT) 398 if (num > 0) fputc ('\n', stdout); 399 printf (_("Client executable (port %d)"), SH_DEFAULT_PORT); ++num; 400 #endif 401 #if defined(SH_WITH_CLIENT) 402 if (num > 0) fputc ('\n', stdout); 403 printf (_("Server executable (port %d, user %s)"), 404 SH_DEFAULT_PORT, DEFAULT_IDENT); 405 ++num; 406 #endif 407 408 fputs (_(", compiled-in options:"), stdout); 409 410 #if defined(USE_DL_PREFIX) 411 if (num > 0) fputc ('\n', stdout); 412 printf (_(" using system malloc")); ++num; 413 #else 414 if (num > 0) fputc ('\n', stdout); 415 printf (_(" using dnmalloc")); ++num; 416 #endif 417 418 #if defined(HAVE_EGD_RANDOM) 419 if (num > 0) fputc ('\n', stdout); 420 printf (_(" using entropy gathering daemon (%s)"), EGD_SOCKET_NAME); ++num; 421 #endif 422 #if defined(HAVE_UNIX_RANDOM) 423 if (num > 0) fputc ('\n', stdout); 424 fputs (_(" using unix entropy gatherer"), stdout); ++num; 425 #endif 426 #if defined(HAVE_URANDOM) 427 if (num > 0) fputc ('\n', stdout); 428 printf (_(" using entropy device (%s)"), NAME_OF_DEV_RANDOM); ++num; 429 #endif 430 431 #ifdef WITH_GPG 432 if (num > 0) fputc ('\n', stdout); 433 printf (_(" GnuPG signatures (%s)"), DEFAULT_GPG_PATH); ++num; 434 #ifdef HAVE_GPG_CHECKSUM 435 if (num > 0) fputc ('\n', stdout); 436 printf (_(" -- GnuPG checksum: %s"), GPG_HASH); ++num; 437 #endif 438 #ifdef USE_FINGERPRINT 439 if (num > 0) fputc ('\n', stdout); 440 printf (_(" -- Key fingerprint: %s"), SH_GPG_FP); ++num; 441 #endif 442 #endif 443 444 #if defined(SL_DEBUG) 445 if (num > 0) fputc ('\n', stdout); 446 fputs (_(" debug build (do not use for production)"), stdout); ++num; 447 #endif 448 #if defined(SCREW_IT_UP) 449 if (num > 0) fputc ('\n', stdout); 450 fputs (_(" anti-debugger"), stdout); ++num; 451 #endif 452 #if defined(SH_USE_XML) 453 if (num > 0) fputc ('\n', stdout); 454 fputs (_(" xml log format"), stdout); ++num; 455 #endif 456 #if defined(HAVE_NTIME) 457 if (num > 0) fputc ('\n', stdout); 458 fputs (_(" using time server"), stdout); ++num; 459 #endif 460 461 #if defined(SH_WITH_CLIENT) || defined(SH_STANDALONE) 462 #if defined(HAVE_LIBZ) 463 if (num > 0) fputc ('\n', stdout); 464 fputs (_(" optionally store full text for files"), stdout); ++num; 465 #endif 466 #if defined(USE_XATTR) 467 if (num > 0) fputc ('\n', stdout); 468 fputs (_(" check SELinux attributes"), stdout); ++num; 469 #endif 470 #if defined(USE_ACL) 471 if (num > 0) fputc ('\n', stdout); 472 fputs (_(" check Posix ACLs"), stdout); ++num; 473 #endif 474 #if defined(RELOAD_DATABASE) 475 if (num > 0) fputc ('\n', stdout); 476 fputs (_(" fetch database on reload"), stdout); ++num; 477 #endif 478 #endif 479 480 #if defined(SH_WITH_SERVER) 481 482 #if !defined(HAVE_GETPEEREID) && !defined(SO_PEERCRED) && !defined(HAVE_STRUCT_CMSGCRED) && !defined(HAVE_STRUCT_FCRED) && !(defined(HAVE_STRUCT_SOCKCRED) && defined(LOCAL_CREDS)) 483 if (num > 0) fputc ('\n', stdout); 484 fputs (_(" command socket authentication: use SetSocketPassword"), stdout); 485 ++num; 486 #else 487 if (num > 0) fputc ('\n', stdout); 488 fputs (_(" command socket authentication: use SetSocketAllowUID"), stdout); 489 ++num; 490 #endif 491 492 #if defined(SH_USE_LIBWRAP) 493 if (num > 0) fputc ('\n', stdout); 494 fputs (_(" support tcp wrapper"), stdout); ++num; 495 #endif 496 #if defined(INET_SYSLOG) 497 if (num > 0) fputc ('\n', stdout); 498 fputs (_(" support listening on 514/udp (syslog)"), stdout); ++num; 499 #endif 500 #endif 501 502 if (num == 0) 503 fputs (_(" none"), stdout); 504 fputc ('\n', stdout); 505 return; 506 } 507 486 508 static void sh_getopt_print_modules (void) 487 509 { … … 489 511 int num = 0; 490 512 491 fputs (_("Compiled-in modules: "), stdout);513 fputs (_("Compiled-in modules:\n"), stdout); 492 514 #ifdef SH_USE_UTMP 493 515 if (num > 0) fputc (',', stdout); -
trunk/src/sh_hash.c
r170 r171 1585 1585 { 1586 1586 sl_strlcpy(fullpath, buf->fullpath, MAX_PATH_STORE+1); 1587 /*1588 if (sl_strlen(buf->fullpath) < (MAX_PATH_STORE-3))1589 {1590 fullpath[MAX_PATH_STORE-2] = '\0';1591 fullpath[MAX_PATH_STORE-1] = '\n';1592 }1593 */1594 1587 } 1595 1588 else -
trunk/src/sh_mail.c
r170 r171 1883 1883 } querybuf; 1884 1884 1885 querybuf reply;1885 querybuf * reply; 1886 1886 char expanded[1024]; 1887 1887 unsigned char * comp_dn, * eom; … … 1896 1896 SL_RETURN (NULL, _("get_mx")); 1897 1897 1898 reply = SH_ALLOC(sizeof(querybuf)); 1899 1898 1900 errno = 0; 1899 1901 length = res_query (hostname, C_IN, T_MX, 1900 (unsigned char *) &reply, 4095);1902 (unsigned char *) reply, 4095); 1901 1903 if (length < 1) 1902 1904 { … … 1925 1927 #endif 1926 1928 } 1929 SH_FREE(reply); 1927 1930 SL_RETURN (NULL, _("get_mx")); 1928 1931 } 1929 1932 1930 1933 ret = 0; 1931 header = (HEADER *) &reply;1934 header = (HEADER *) reply; 1932 1935 1933 1936 /* start of data section 1934 1937 */ 1935 comp_dn = (unsigned char *) &reply + HFIXEDSZ;1938 comp_dn = (unsigned char *) reply + HFIXEDSZ; 1936 1939 1937 1940 /* end-of-message 1938 1941 */ 1939 eom = (unsigned char *) &reply + length;1942 eom = (unsigned char *) reply + length; 1940 1943 1941 1944 /* HEADER NAME -- must be skipped or decompressed … … 1958 1961 comp_dn += ret + QFIXEDSZ; 1959 1962 if (ret < 1 || comp_dn >= eom) 1960 SL_RETURN (NULL, _("get_mx")); 1963 { 1964 SH_FREE(reply); 1965 SL_RETURN (NULL, _("get_mx")); 1966 } 1961 1967 } 1962 1968 count = ntohs (header->ancount); 1963 1969 if (count < 1) 1964 SL_RETURN (NULL, _("get_mx")); 1970 { 1971 SH_FREE(reply); 1972 SL_RETURN (NULL, _("get_mx")); 1973 } 1965 1974 1966 1975 retval = SH_ALLOC (sizeof (dnsrep)); 1967 1976 if (!retval) 1968 SL_RETURN (NULL, _("get_mx")); 1977 { 1978 SH_FREE(reply); 1979 SL_RETURN (NULL, _("get_mx")); 1980 } 1981 1969 1982 retval->count = count; 1970 1983 … … 1973 1986 if (!sl_ok_muls(count, sizeof (mx))) 1974 1987 { 1988 SH_FREE(reply); 1975 1989 SH_FREE (retval); 1976 1990 SL_RETURN (NULL, _("get_mx")); … … 1981 1995 if (!result) 1982 1996 { 1997 SH_FREE(reply); 1983 1998 SH_FREE (retval); 1984 1999 SL_RETURN (NULL, _("get_mx")); … … 1995 2010 if (ret < 1 || comp_dn >= eom) 1996 2011 { 2012 SH_FREE(reply); 1997 2013 SH_FREE (result); 1998 2014 SH_FREE (retval); … … 2006 2022 if (type != T_MX || comp_dn >= eom) 2007 2023 { 2024 SH_FREE(reply); 2008 2025 SH_FREE (result); 2009 2026 SH_FREE (retval); … … 2017 2034 if (comp_dn >= eom) 2018 2035 { 2036 SH_FREE(reply); 2019 2037 SH_FREE (result); 2020 2038 SH_FREE (retval); … … 2027 2045 if (comp_dn >= eom) 2028 2046 { 2047 SH_FREE(reply); 2029 2048 SH_FREE (result); 2030 2049 SH_FREE (retval); … … 2038 2057 if (rdlength < 1 || comp_dn >= eom) 2039 2058 { 2059 SH_FREE(reply); 2040 2060 SH_FREE (result); 2041 2061 SH_FREE (retval); … … 2049 2069 if (comp_dn >= eom) 2050 2070 { 2071 SH_FREE(reply); 2051 2072 SH_FREE (result); 2052 2073 SH_FREE (retval); … … 2059 2080 if (ret < 1) 2060 2081 { 2082 SH_FREE(reply); 2061 2083 SH_FREE (result); 2062 2084 SH_FREE (retval); … … 2074 2096 while (ret > 0 && comp_dn < eom && count); 2075 2097 2098 SH_FREE(reply); 2076 2099 SL_RETURN (retval, _("get_mx")); 2077 2100 } -
trunk/src/sh_portcheck.c
r170 r171 687 687 do { 688 688 retval = connect(fd, (struct sockaddr *) &sinr, sizeof(sinr)); 689 } while (retval < 0 && errno == EINTR);689 } while (retval < 0 && (errno == EINTR || errno == EINPROGRESS)); 690 690 691 691 if (retval == -1) … … 775 775 do { 776 776 retval = connect(fd, (struct sockaddr *) &sinr, sizeof(sinr)); 777 } while (retval < 0 && errno == EINTR);777 } while (retval < 0 && (errno == EINTR || errno == EINPROGRESS)); 778 778 779 779 if (retval == -1 && errno == ECONNREFUSED) -
trunk/src/sh_string.c
r169 r171 4 4 #include <string.h> 5 5 #include <stdio.h> 6 #include <sys/types.h> 6 7 7 8 #include "sh_string.h" … … 40 41 /* skip leading WS 41 42 */ 42 for (s=e; *s && isspace( *s); ++s) /* nothing */;43 for (s=e; *s && isspace((int)*s); ++s) /* nothing */; 43 44 44 45 if (*s) … … 65 66 if (a != line) 66 67 { 67 /* chop off trailing WS 68 */ 69 for (a--; isspace(*a) && a > s; a--) /* do nothing */; 70 71 /* terminate string 72 */ 73 ++a; *a = '\0'; 74 } 68 if (i < (maxfields -1)) 69 { 70 71 /* chop off trailing WS 72 */ 73 for (a--; isspace((int)*a) && a > s; a--) /* do nothing */; 74 75 /* terminate string 76 */ 77 ++a; *a = '\0'; 78 } 79 else 80 { 81 /* If nfields < actual fields, last string 82 * will be remainder, therefore skip to end. 83 */ 84 if ( *a ) 85 { 86 do { 87 a++; 88 } while ( *a ); 89 } 90 } 91 } 75 92 else 76 93 { … … 127 144 /* skip leading WS 128 145 */ 129 if ( *s && isspace( *s) )146 if ( *s && isspace((int)*s) ) 130 147 { 131 148 do { 132 149 ++s; 133 } while ( *s && isspace( *s) );150 } while ( *s && isspace((int)*s) ); 134 151 } 135 152 … … 142 159 do { 143 160 a++; 144 } while ( *a && (!isspace( *a)) );161 } while ( *a && (!isspace((int)*a)) ); 145 162 146 163 /* next token, *a is either ws or '\0' … … 152 169 if (i < (maxfields-1)) 153 170 { 154 *a = '\0'; 171 *a = '\0'; 155 172 } 156 173 else … … 275 292 } 276 293 memcpy(s->str, str, (len+1)); 294 s->len = len; 277 295 return s; 278 296 } … … 397 415 sh_string * r = NULL; 398 416 char * p; 417 long tlen; 399 418 size_t len; 400 419 int end = 0; … … 403 422 size_t newlen = 0; 404 423 long diff; 405 int i ;424 int i, curr, last; 406 425 407 426 … … 443 462 } 444 463 445 if (r && ovecnum > 0) 464 465 curr = -1; 466 last = -1; 467 468 for (i = 0; i < ovecnum; ++i) 469 { 470 if (ovector[2*i] >= 0) 471 { 472 curr = i; 473 break; 474 } 475 } 476 477 if (r && ovecnum > 0 && ovector[curr] >= 0) 446 478 { 447 479 r->len = 0; r->str[0] = '\0'; p = r->str; … … 449 481 /* First part, until start of first replacement 450 482 */ 451 memcpy(p, s->str, ovector[0]); p += ovector[0]; 452 memcpy(p, replacement, rlen); p += rlen; 453 *p = '\0'; r->len += (ovector[0] + rlen); 483 memcpy(p, s->str, (size_t)ovector[curr]); p += ovector[curr]; 484 memcpy(p, replacement, rlen); p += rlen; 485 *p = '\0'; r->len += (ovector[curr] + rlen); 486 487 last = curr + 1; 454 488 455 489 for (i = 1; i < ovecnum; ++i) 456 490 { 491 if (ovector[2*i] < 0) 492 continue; 493 494 curr = 2*i; 495 457 496 /* From end of last replacement to start of this */ 458 len = ovector[2*i] - ovector[2*i -1]; 459 memcpy(p, &(s->str[ovector[2*i -1]]), len); 460 p += len; 461 462 /* The replacement */ 463 memcpy(p, replacement, rlen); 464 p += rlen; 465 466 /* null terminate */ 467 *p = '\0'; r->len += (len + rlen); 468 } 497 tlen = (long)(ovector[curr] - ovector[last]); 498 if (tlen >= 0) 499 { 500 len = (size_t) tlen; 501 502 if (tlen > 0) 503 { 504 memcpy(p, &(s->str[ovector[last]]), (size_t)len); 505 p += len; 506 } 507 508 /* The replacement */ 509 memcpy(p, replacement, rlen); 510 p += rlen; 511 512 /* null terminate */ 513 *p = '\0'; r->len += (len + rlen); 514 515 last = curr + 1; 516 } 517 } 469 518 470 519 /* Last part, after last replacement; includes terminating null 471 520 */ 472 len = (s->len + 1) - ovector[2*i -1]; 473 memcpy(p, &(s->str[ovector[2*i -1]]), len); 474 p += len; *p = '\0'; r->len += (len - 1); 475 } 521 if (last > 0) 522 { 523 /* If not, nothing has been replaced, and r is still a copy of s 524 */ 525 tlen = (long)((s->len + 1) - ovector[last]); 526 if (tlen > 0) 527 { 528 len = (size_t)tlen; 529 memcpy(p, &(s->str[ovector[2*i -1]]), (size_t)len); 530 p += len; *p = '\0'; r->len += (len - 1); 531 } 532 } 533 534 } 535 476 536 return r; 477 537 } … … 785 845 t = sh_string_replace(s, ovector, ovecnum, 786 846 "___", 3); 847 CuAssertPtrNotNull(tc, t); 787 848 CuAssertStrEquals(tc, "___c ___ ", t->str); 788 849 CuAssertIntEquals(tc, 9, (int)t->len); … … 792 853 t = sh_string_replace(s, ovector, ovecnum, 793 854 "___", 3); 855 CuAssertPtrNotNull(tc, t); 794 856 CuAssertStrEquals(tc, "___c ___", t->str); 795 857 CuAssertIntEquals(tc, 8, (int)t->len); … … 806 868 "___", 3); 807 869 870 CuAssertPtrNotNull(tc, t); 808 871 CuAssertStrEquals(tc, "______f ghi ", t->str); 809 872 CuAssertIntEquals(tc, 12, (int)t->len); … … 813 876 t = sh_string_replace(s, ovector, ovecnum, 814 877 "___", 3); 878 CuAssertPtrNotNull(tc, t); 815 879 CuAssertStrEquals(tc, "abc ___ef ghi___", t->str); 816 880 CuAssertIntEquals(tc, 16, (int)t->len); … … 818 882 t = sh_string_replace(s, ovector, 0, 819 883 "___", 3); 884 CuAssertPtrNotNull(tc, t); 820 885 CuAssertStrEquals(tc, s->str, t->str); 821 886 CuAssertIntEquals(tc, (int)s->len, (int)t->len); -
trunk/src/sh_tiger0.c
r170 r171 843 843 static const int BLOCKSIZE = 8192; 844 844 struct md5_ctx ctx; 845 char buffer[8264]; /* BLOCKSIZE + 72 AIX compiler chokes */845 char * buffer = SH_ALLOC(8264); /* BLOCKSIZE + 72 AIX compiler chokes */ 846 846 size_t sum; 847 847 … … 870 870 SH_FREE(tmp); 871 871 *Length = 0; 872 SH_FREE(buffer); 872 873 return -1; 873 874 } … … 878 879 879 880 /* Iterate over full file contents. */ 880 while (1 == 1) {881 while (1) { 881 882 /* We read the file in blocks of BLOCKSIZE bytes. One call of the 882 883 computation function processes the whole buffer so that with the … … 894 895 { 895 896 if (sig_termfast == 1) 896 return -1; 897 { 898 SH_FREE(buffer); 899 return -1; 900 } 897 901 TPT((0, FIL__ , __LINE__ , _("msg=<SL_ISERROR (%ld)>\n"), n)); 898 902 tmp = sh_util_safe_name (filename); … … 909 913 SH_FREE(tmp); 910 914 *Length = 0; 915 SH_FREE(buffer); 911 916 return -1; 912 917 } … … 953 958 { 954 959 *Length = 0; 960 SH_FREE(buffer); 955 961 return -1; 956 962 } … … 969 975 970 976 *Length = bcount; 977 SH_FREE(buffer); 971 978 return 0; 972 979 } … … 1367 1374 static const int BLOCKSIZE = 4096; 1368 1375 struct sha_ctx ctx; 1369 char buffer[4168]; /* BLOCKSIZE + 72 AIX compiler chokes */1376 char * buffer = SH_ALLOC(4168); /* BLOCKSIZE + 72 AIX compiler chokes */ 1370 1377 off_t sum = 0; 1371 1378 char * tmp; … … 1393 1400 SH_FREE(tmp); 1394 1401 *Length = 0; 1402 SH_FREE(buffer); 1395 1403 return -1; 1396 1404 } … … 1417 1425 { 1418 1426 if (sig_termfast == 1) 1419 return -1; 1427 { 1428 SH_FREE(buffer); 1429 return -1; 1430 } 1420 1431 1421 1432 TPT((0, FIL__ , __LINE__ , _("msg=<SL_ISERROR (%ld)>\n"), n)); … … 1435 1446 SH_FREE(tmp); 1436 1447 *Length = 0; 1448 SH_FREE(buffer); 1437 1449 return -1; 1438 1450 } … … 1479 1491 { 1480 1492 *Length = 0; 1493 SH_FREE(buffer); 1481 1494 return -1; 1482 1495 } … … 1497 1510 sha_digest (&ctx, resblock); 1498 1511 *Length = bcount; 1512 SH_FREE(buffer); 1499 1513 return 0; 1500 1514 } … … 1505 1519 char * out, size_t len) 1506 1520 { 1507 int cnt = (int) Length; /* fix compiler warning */1521 int cnt; 1508 1522 char outbuf[KEY_LEN+1]; 1509 1523 unsigned char sha1buffer[20]; -
trunk/src/sh_tiger1_64.c
r170 r171 371 371 } 372 372 373 void tiger_compress( word64 *str, word64 state[3])373 void tiger_compress(const word64 *str, word64 state[3]) 374 374 { 375 375 tiger_compress_macro(((word64*)str), ((word64*)state)); 376 376 } 377 377 378 void tiger_t( word64 *str, word64 length, word64 res[3])378 void tiger_t(const word64 *str, word64 length, word64 res[3]) 379 379 { 380 380 register word64 i; -
trunk/src/sh_tools.c
r170 r171 725 725 struct sigaction new_act; 726 726 struct sigaction old_act; 727 #if defined(WITH_TPT)728 727 char errbuf[SH_ERRBUF_SIZE]; 729 #endif730 728 731 729 SL_ENTER(_("sh_write_select")); … … 762 760 continue; 763 761 } 764 if ( errno == EINTR ) /* try again */762 if ( errno == EINTR || errno == EINPROGRESS ) /* try again */ 765 763 continue; 766 764 *w_error = errno; 767 TPT(( 0, FIL__, __LINE__, _("msg=<select: %s>\n"),768 sh_error_message(*w_error, errbuf, sizeof(errbuf))));769 765 sigaction (SIGPIPE, &old_act, NULL); 766 sh_error_message(*w_error, errbuf, sizeof(errbuf)); 767 sh_error_handle (SH_ERR_INFO, FIL__, __LINE__, errno, MSG_E_SUBGEN, 768 errbuf, 769 _("sh_write_select (ws)") ); 770 TPT(( 0, FIL__, __LINE__, _("msg=<select: %s>\n"), errbuf )); 770 771 SL_RETURN( countbytes, _("sh_write_select")); 771 772 } … … 780 781 continue; 781 782 } 782 if ( errno == EINTR ) /* try again */783 if ( errno == EINTR || errno == EINPROGRESS ) /* try again */ 783 784 continue; 784 785 *w_error = errno; 785 TPT(( 0, FIL__, __LINE__, _("msg=<select: %s>\n"),786 sh_error_message(*w_error, errbuf, sizeof(errbuf))));787 786 sigaction (SIGPIPE, &old_act, NULL); 787 sh_error_message(*w_error, errbuf, sizeof(errbuf)); 788 sh_error_handle (SH_ERR_INFO, FIL__, __LINE__, errno, MSG_E_SUBGEN, 789 errbuf, 790 _("sh_write_select (rs)") ); 791 TPT(( 0, FIL__, __LINE__, _("msg=<select: %s>\n"), errbuf )); 788 792 SL_RETURN( countbytes, _("sh_write_select")); 789 793 } … … 836 840 *w_error = errno; 837 841 sigaction (SIGPIPE, &old_act, NULL); 842 sh_error_message(*w_error, errbuf, sizeof(errbuf)); 843 sh_error_handle (SH_ERR_INFO, FIL__, __LINE__, errno, MSG_E_SUBGEN, 844 errbuf, 845 (type == SH_DO_WRITE) ? 846 _("sh_write_select (w)") : _("sh_write_select (r)")); 838 847 TPT(( 0, FIL__, __LINE__, _("msg=<count < 0>\n"))); 839 848 SL_RETURN( countbytes, _("sh_write_select")); -
trunk/src/sh_unix.c
r170 r171 3773 3773 { 3774 3774 #ifdef HAVE_LIBZ 3775 unsigned long clen = compressBound(sh_string_len(content)); 3776 unsigned char * compressed = SH_ALLOC(clen); 3775 unsigned long clen; 3776 unsigned char * compressed; 3777 #ifdef HAVE_COMPRESSBOUND 3778 clen = compressBound(sh_string_len(content)); 3779 #else 3780 if (sh_string_len(content) > 10*SH_TXT_MAX) 3781 clen = SH_TXT_MAX; 3782 else 3783 clen = 13 + (int)(1.0001*sh_string_len(content)); 3784 #endif 3785 compressed = SH_ALLOC(clen); 3777 3786 if (Z_OK == compress(compressed, &clen, 3778 3787 (unsigned char *) sh_string_str(content), -
trunk/src/trustfile.c
r170 r171 782 782 register int i; /* trustworthy or not? */ 783 783 const char * t_const; 784 char *end; 784 785 785 786 /* … … 810 811 if (csym[0] != '/') 811 812 { 813 /* pointer to one above last element 814 */ 815 end = &full[MAXFILENAME-1]; ++end; 816 812 817 /* initialize pointers 813 818 */ … … 817 822 */ 818 823 t = fexp; 819 while(*t && b < &full[MAXFILENAME])824 while(*t && b < end) 820 825 *b++ = *t++; 821 826 … … 823 828 */ 824 829 t_const = "/../"; 825 while(*t && b < &full[MAXFILENAME])830 while(*t && b < end) 826 831 *b++ = *t_const++; 827 832 … … 829 834 */ 830 835 t = csym; 831 while(*t && b < &full[MAXFILENAME])836 while(*t && b < end) 832 837 *b++ = *t++; 833 838 834 839 /* see if we're too big 835 840 */ 836 if (*t || b == &full[MAXFILENAME])841 if (*t || b == end) 837 842 { 838 843 /* yes -- error
Note:
See TracChangeset
for help on using the changeset viewer.