Changeset 124a071 in code
- Timestamp:
- Aug 30, 2017, 12:11:44 AM (8 years ago)
- Branches:
- master
- Children:
- 614260f
- Parents:
- d8c3967
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
icb.c
rd8c3967 r124a071 401 401 va_list ap; 402 402 char buf[ICB_MSGSIZE]; 403 int res, buflen = 1;403 int res, buflen; 404 404 static const struct { 405 405 int type; … … 429 429 return; 430 430 } 431 buflen += MIN((size_t)res, sizeof buf - 1); 432 if ((size_t)buflen >= sizeof buf) { 431 if ((size_t)res >= sizeof buf) { 433 432 icbd_log(NULL, LOG_ERR, "Status buffer too small"); 434 433 return; 435 434 } 435 buflen = MIN((size_t)res + 1, sizeof buf - 1); 436 436 va_start(ap, fmt); 437 res = vsnprintf(&buf[buflen], sizeof buf - buflen , fmt, ap);437 res = vsnprintf(&buf[buflen], sizeof buf - buflen - 1, fmt, ap); 438 438 va_end(ap); 439 buflen--; /* buf[buflen] was overwritten */ 439 440 if (res < 0) { 440 icbd_log(NULL, LOG_ERR, "Format error in %s", __func__); 441 return; 442 } 443 buflen += MIN((size_t)res, sizeof buf - buflen); 441 icbd_log(NULL, LOG_ERR, "Message format error in %s", __func__); 442 return; 443 } 444 if ((size_t)res + buflen >= sizeof buf) { 445 icbd_log(NULL, LOG_ERR, "Status message too long"); 446 return; 447 } 448 buflen += MIN((size_t)res + 1, sizeof buf - buflen - 1); 444 449 buf[0] = buflen; 445 450 icbd_send(is, buf, buflen + 1); … … 478 483 char buf[ICB_MSGSIZE]; 479 484 va_list ap; 480 int res, buflen = 1;485 int res, buflen; 481 486 482 487 va_start(ap, fmt); … … 487 492 return; 488 493 } 489 buflen += MIN((size_t)res, sizeof buf - 2);494 buflen = MIN((size_t)res + 1, sizeof buf - 2); 490 495 buf[0] = ++buflen; /* account for ICB_M_ERROR */ 491 496 buf[1] = ICB_M_ERROR;
Note:
See TracChangeset
for help on using the changeset viewer.