Text  |   XML   |   Visible Warnings:

pvm3.4.6 : pvm3.4.6 analysis 2 : Buffer Underrun  at pvmlog.c:444

Categories: LANG.MEM.BU CWE:124 CWE:127
Warning ID: 22091.28938
Procedure: vpvmlogprintf
Trace: view
Modified: Thu Nov 26 11:28:58 2009   show details
 
Priority: None
State: None
Finding: None
Owner: None
  edit properties

Legend [ X ]
Warning Location
Contributes
Parse Error
Other Warning
Two or More Loop Iterations
On Execution Path
Comment
Macro
Preprocessor
Include
Keyword
Preprocessed Away

Source  |  Language: C Hide Legend     
ProblemLineSource
   /kat0/fletcher/SATE/2010/pvm3/src/pvmd.c
   Enter main
 947 main(argc, argv) 
 948         int argc;
 949         char **argv;
 950 {
 951         int i, j;
 952         char *name = "";
 953         struct passwd *pe;
 954         int testmode = 0;
 955         struct timeval tnow;
 956         char buf[128];
 957  
 958 #ifndef WIN32 
 959         /* check for extension config options */ 
 960         check_ext_input();
 961  
 962         /* make sure 0, 1, 2 are in use */ 
 963         (void)open("/dev/null", O_RDONLY, 0);
 964         (void)open("/dev/null", O_RDONLY, 0);   /* File System Race Condition (ID: 272.28943) */
 965         (void)open("/dev/null", O_RDONLY, 0);   /* File System Race Condition (ID: 272.28942) */
 966 #else 
 967         /* WSAStartup has to be called before any socket command */ 
 968         /* can be executed. Why ? Ask Bill   */ 
 969  
 970         if (WSAStartup(0x0101, &WSAData) != 0) {
 971               printf("\nWSAStartup() failed\n");
 972               ExitProcess(1);
 973         }
 974         setsockopt(INVALID_SOCKET,SOL_SOCKET,SO_OPENTYPE,
 975                         (char *)&nAlert,sizeof(int));
 976         osinfo=malloc(sizeof(OSVERSIONINFO));
 977         osinfo->dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
 978         GetVersionEx(osinfo);
 979         os_is_NT= ( osinfo->dwPlatformId == VER_PLATFORM_WIN32_NT); 
 980 #endif 
 981  
 982         {
 983                 char *p;
 984                 if (p = getenv("PVMDDEBUG"))
 985                         pvmdebmask = pvmstrtoi(p);
 986         }
 987  
 988 #ifndef WIN32 
 989         if ((pvm_useruid = getuid()) == -1) {
 990                 pvmlogerror("main() can't getuid()\n");
 991                 pvmbailout(0);
 992         }
 993         pvmchkuid( pvm_useruid );
 994 #else 
 995         username = MyGetUserName(); 
 996 #endif 
 997  
 998         pvmsetlog(3);
 999  
 1000 #ifndef WIN32 
 1001         if (pe = getpwuid(pvm_useruid))
 1002                 username = STRALLOC(pe->pw_name);   /* Null Pointer Dereference (ID: 271.28941) */
 1003         else 
 1004                 pvmlogerror("main() can't getpwuid\n");
 1005         endpwent();
 1006 #endif 
 1007  
 1008 #ifdef WIN32 
 1009         if ((pvmmyupid = getpid()) == -1) {
 1010                 pvmlogerror("main() can't getpid() %d \n",GetLastError());
 1011                 pvmbailout(0);
 1012         } 
 1013 #else 
 1014         if ((pvmmyupid = getpid()) == -1) {
 1015                 pvmlogerror("main() can't getpid()\n");
 1016                 pvmbailout(0);
 1017         }
 1018 #endif 
 1019  
 1020         (void)pvmgetroot();             /* fail here if we can't */ 
 1021  
 1022         sprintf(buf, "PVM_ARCH=%s", myarchname);
 1023         pvmputenv(STRALLOC(buf));   /* Null Pointer Dereference (ID: 270.28940) */
 1024  
 1025         pvmmydsig = pvmgetdsig();
 1026  
 1027         ppi_config(argc, argv);
 1028  
 1029 #if defined(IMA_PGON) || defined(IMA_SP2MPI) || defined(IMA_AIX4SP2) \
 1030                 || defined(IMA_AIX5SP2) || defined(IMA_BEOLIN) 
 1031         mpp_init(&argc, argv); 
 1032 #endif 
 1033  
 1034         for (i = j = 1; i < argc; i++) {
 1035                 if (argv[i][0] == '-') {
 1036                         switch (argv[i][1]) {
 1037  
 1038                         case 'd': 
 1039                                 pvmdebmask = pvmstrtoi(argv[i] + 2);
 1040                                 break;
 1041  
 1042                         case 'n': 
 1043                                 name = argv[i] + 2;
 1044                                 break;
 1045  
 1046                         case 'S': 
 1047                                 argv[j++] = argv[i];
 1048                         case 's': 
 1049                                 slavemode = 1;
 1050                                 break;
 1051  
 1052                         case 't': 
 1053                                 testmode = 1;
 1054                                 break;
 1055  
 1056 #ifdef WIN32 
 1057                         case 'u':
 1058                                 if (os_is_NT==FALSE) {
 1059                                         /* someone is on win95 ... */ 
 1060                                         argv[i]++;argv[i]++;
 1061                                         strcpy(username,argv[i]);
 1062                                 }
 1063                                 else 
 1064                                         if (strcmp(strcat("-u",username),argv[i])) {
   ...
 1066                                                                 "Provided Username(%s) does not match ",
 1067                                                                 username);
 1068                                                 fprintf(stderr,"with OS (%s).\n",
 1069                                                                 argv[i]);
 1070                                                 fprintf(stderr,"Wrong rshd ?!\n");
 1071                                                 exit(1);
 1072                                 }
 1073                                 break; 
 1074 #endif 
 1075  
 1076                         default: 
 1077                                 argv[j++] = argv[i];
 1078                         }
 1079  
 1080                 } else {
 1081                         argv[j++] = argv[i];
 1082                 }
 1083         }
 1084         argc = j;
 1085  
 1086         if (pvmdebmask) {
 1087                 pvmlogprintf("version %s\n", PVM_VER);
 1088                 pvmlogprintf("ddpro %d tdpro %d\n", DDPROTOCOL, TDPROTOCOL);
 1089                 pvmlogprintf("main() debug mask is 0x%x (%s)\n",
 1090                                 pvmdebmask, debug_flags(pvmdebmask));
 1091         }
 1092  
 1093         if (!*name) {
 1094                 if (gethostname(buf, sizeof(buf)-1) == -1) {
 1095                         pvmlogerror("main() can't gethostname()\n");
 1096                         pvmbailout(0);
 1097                 }
 1098                 name = buf;
 1099         }
 1100         if (testmode) {
 1101                 PVM_TIMET time_temp;
 1102                 gettimeofday(&tnow, (struct timezone*)0);
 1103                 pvmlogprintf("version %s ddpro %d tdpro %d sdpro %d\n",
 1104                                 PVM_VER, DDPROTOCOL, TDPROTOCOL, SDPROTOCOL);
 1105                 time_temp = (PVM_TIMET) tnow.tv_sec;
$input_12 < 11106                 pvmlogprintf(ctime(&time_temp));   /* Format String (ID: 22202.29377) */
     /kat0/fletcher/SATE/2010/pvm3/src/pvmlog.c
     Enter main / pvmlogprintf
 458   pvmlogprintf(const char *fmt, ...) 
 459   #else 
 460   pvmlogprintf(va_alist)
 461           va_dcl 
 462   #endif 
 463   {
 464           va_list ap;
 465           int cc;
 466    
 467   #if defined (__STDC__) || defined(IMA_WIN32_WATCOM)
 468    
 469           va_start(ap, fmt);
 470   #else 
 471           char    *fmt;
 472    
 473           va_start(ap);
 474           fmt = va_arg(ap, char *); 
 475   #endif 
strlen(fmt) < -1 * bytes_before(fmt) + 1476           cc = vpvmlogprintf(fmt, ap);
       Enter main / pvmlogprintf / vpvmlogprintf
 368     vpvmlogprintf(fmt, ap) 
 369             char *fmt;
 370             va_list ap;
 371     {
 372             char vtmp[1024];
 373             char *truncated;
 374             int cnt = 0;
 375             int cc;
 376      
 377     #ifdef  TIMESTAMPLOG 
 378             time_t now;
 379             struct tm *tmp;
 380      
 381             time(&now);
 382             tmp = localtime(&now);
 383     #endif  /*TIMESTAMPLOG*/ 
 384      
 385             /* snag var arg string, in case re-use whacks it... */ 
 386             /* (thank you very much x86_64...  :-Q */ 
 387             /* damn, also need to prevent buffer overflows... */ 
 388             /* (thanks to Lasse Makholm <lasse.makholm@nokia.com> */ 
 389             /* for this patch...) */ 
 390             cc = vsnprintf(vtmp, sizeof(vtmp), fmt, ap);   /* Null Pointer Dereference (ID: 22037.28696) */  /* Null Pointer Dereference (ID: 22092.28939) */
 391             truncated = ( cc >= 0 && cc < sizeof(vtmp) )   /* Redundant Condition (ID: 20.28602) */
 392                             ? "" : "[...]\n";
 393      
 394             if (log_how & 1) {
 395                     if (atnewline) {
 396                             if (pvmmytid)
 397                                     fprintf(stderr, "[t%x] ", pvmmytid);
 398                             else 
 399                                     fprintf(stderr, "[pvmd pid%d] ", pvmmyupid);
 400      
 401     #ifdef  TIMESTAMPLOG 
 402                             fprintf(stderr, "%02d/%02d %02d:%02d:%02d ",
 403                                                     tmp->tm_mon + 1,
 404                                                     tmp->tm_mday,
       ...
 406                                                     tmp->tm_min,
 407                                                     tmp->tm_sec);
 408     #endif  /*TIMESTAMPLOG*/ 
 409                     }
 410                     /* cc = vfprintf(stderr, fmt, ap); */ 
 411                     cc = fprintf(stderr, "%s%s", vtmp, truncated);
 412                     cnt = ( cc >= 0 ) ? cnt + cc : cc;
 413                     fflush(stderr);
 414             }
 415      
 416             if (log_how & 2) {
 417                     if (log_alrdy < pvmdlogmax) {
 418                             if (atnewline) {
 419                                     if (pvmmytid)
 420                                             fprintf(log_ff, "[t%x] ", pvmmytid);
 421                                     else 
 422                                             fprintf(log_ff, "[pvmd pid%d] ", pvmmyupid);
 423      
 424     #ifdef  TIMESTAMPLOG 
 425                                     fprintf(log_ff, "%02d/%02d %02d:%02d:%02d ",
 426                                                     tmp->tm_mon + 1,
       ...
 434                             /* cc = vfprintf(log_ff, fmt, ap); */ 
 435                             cc = fprintf(log_ff, "%s%s", vtmp, truncated);
 436                             cnt = ( cnt >= 0 ) ? ( ( cc >= 0 ) ? cnt + cc : cc ) : cnt;
 437                             fflush(log_ff);
 438      
 439                             if ((log_alrdy += cnt) >= pvmdlogmax)
 440                                     (void)write(log_fd, toomuch, strlen(toomuch));
 441                     }
 442             }
 443      
strlen(fmt) < -1 * bytes_before(fmt) + 1444             atnewline = (fmt[strlen(fmt) - 1] == '\n') ? 1 : 0;     /* Buffer Underrun */  /* Buffer Underrun (ID: 22036.28695) */
       Exit main / pvmlogprintf / vpvmlogprintf
     Exit main / pvmlogprintf
Preconditions
fmt >= 3
&$unknown_799840 != 0
&$unknown_799845 != 0
strlen(myarchname) > -9
buf[0] != 0
buf[0] != 61
myfmt != -1
rd != 0
$input_12 <= 25
$input_12 >= 0
$input_191148 <= 1023
$input_191148 >= 0
Postconditions
*stdin' is allocated by fopen
bytes_before(stdin)' = 0
PASSWD_COUNTER' = 0
ap' = &__builtin_va_alist
ap' = &__builtin_va_alist
atnewline' = 1
buf[0]' = 0
strlen(&buf[0])' = 0
cc' >= 1
cc' <= 1023
cnt' = 0
ctime_buf[0]' = $input_444
strlen(&ctime_buf[0])' = $input_12
fmt' = &ctime_buf[0]
fmt' = &ctime_buf[0]
$heap_308733' is allocated by open
$heap_308733' is allocated
$heap_308734' is allocated by open
$heap_308734' is allocated
$heap_308735' is allocated by malloc
$heap_308735' is allocated
bytes_before(&$heap_308735)' = 0
strlen(&$heap_308735)' = strlen(stored_passwd)'
tocttou($heap_308735)' = tocttou(*stored_passwd.pw_name)
$heap_308736' = buf[0]
bytes_after(&$heap_308736)' = strlen(myarchname) + 10
$heap_308736' is allocated by malloc
$heap_308736' is allocated
bytes_before(&$heap_308736)' = 0
strlen(&$heap_308736)' = strlen(myarchname) + 9
tocttou($heap_308736)' = tocttou(buf)
i' = argc
log_fd' = -1
name' = &buf[0]
p' = 0
pe' = &stored_passwd.pw_name
pvm_useruid' != -1
pvmdebmask' = &$unknown_799840
pvmmydsig' = myfmt
pvmmyupid' != -1
slavemode' = 1
testmode' = &$unknown_799845
time_temp' = &$unknown_799846
tmbuf.tm_sec' = &$unknown_799849
tmp' = &tmbuf.tm_sec
tnow.tv_sec' = &$unknown_799846
truncated' = &#string5[0]
username' = &$heap_308735
strlen(&vtmp[0])' = $input_191148




Change Warning 22091.28938 : Buffer Underrun

Priority:
State:
Finding:
Owner:
Note: