Changeset 34 for trunk/src/sh_forward.c
- Timestamp:
- May 19, 2006, 8:09:51 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.