diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-08-21 11:18:25 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-08-21 11:18:25 +0000 |
commit | 72b6a65b2fab7325767ce72fc71b9cf45514764a (patch) | |
tree | 32b07c774b100d09c02a3e74445aeb37a33cab79 | |
parent | d6e81c7762e20e3df4d12c5515354e4da3a451a8 (diff) | |
download | busybox-w32-72b6a65b2fab7325767ce72fc71b9cf45514764a.tar.gz busybox-w32-72b6a65b2fab7325767ce72fc71b9cf45514764a.tar.bz2 busybox-w32-72b6a65b2fab7325767ce72fc71b9cf45514764a.zip |
httpd: fix buglet in hex conversion. Remove alloca NULL checks
(never happens, app just crashes if stack overflows)
svlogd: cosmetic messages and style fixes
-rw-r--r-- | networking/httpd.c | 36 | ||||
-rw-r--r-- | runit/svlogd.c | 24 |
2 files changed, 30 insertions, 30 deletions
diff --git a/networking/httpd.c b/networking/httpd.c index 7e60fc252..a888c2424 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -163,7 +163,7 @@ enum { | |||
163 | #endif | 163 | #endif |
164 | }; | 164 | }; |
165 | 165 | ||
166 | static const uint16_t http_response_type[] = { | 166 | static const uint16_t http_response_type[] ALIGN2 = { |
167 | HTTP_OK, | 167 | HTTP_OK, |
168 | HTTP_MOVED_TEMPORARILY, | 168 | HTTP_MOVED_TEMPORARILY, |
169 | HTTP_REQUEST_TIMEOUT, | 169 | HTTP_REQUEST_TIMEOUT, |
@@ -287,8 +287,6 @@ struct globals { | |||
287 | } while (0) | 287 | } while (0) |
288 | 288 | ||
289 | 289 | ||
290 | |||
291 | |||
292 | #define STRNCASECMP(a, str) strncasecmp((a), (str), sizeof(str)-1) | 290 | #define STRNCASECMP(a, str) strncasecmp((a), (str), sizeof(str)-1) |
293 | 291 | ||
294 | /* Prototypes */ | 292 | /* Prototypes */ |
@@ -467,11 +465,6 @@ static void parse_conf(const char *path, int flag) | |||
467 | 465 | ||
468 | if (flag == SUBDIR_PARSE || cf == NULL) { | 466 | if (flag == SUBDIR_PARSE || cf == NULL) { |
469 | cf = alloca(strlen(path) + sizeof(httpd_conf) + 2); | 467 | cf = alloca(strlen(path) + sizeof(httpd_conf) + 2); |
470 | if (cf == NULL) { | ||
471 | if (flag == FIRST_PARSE) | ||
472 | bb_error_msg_and_die(bb_msg_memory_exhausted); | ||
473 | return; | ||
474 | } | ||
475 | sprintf((char *)cf, "%s/%s", path, httpd_conf); | 468 | sprintf((char *)cf, "%s/%s", path, httpd_conf); |
476 | } | 469 | } |
477 | 470 | ||
@@ -554,7 +547,7 @@ static void parse_conf(const char *path, int flag) | |||
554 | /* error status code */ | 547 | /* error status code */ |
555 | int status = atoi(++p0); | 548 | int status = atoi(++p0); |
556 | /* c already points at the character following ':' in parse loop */ | 549 | /* c already points at the character following ':' in parse loop */ |
557 | // c = strchr(p0, ':'); c++; | 550 | /* c = strchr(p0, ':'); c++; */ |
558 | if (status < HTTP_CONTINUE) { | 551 | if (status < HTTP_CONTINUE) { |
559 | bb_error_msg("config error '%s' in '%s'", buf, cf); | 552 | bb_error_msg("config error '%s' in '%s'", buf, cf); |
560 | continue; | 553 | continue; |
@@ -575,9 +568,7 @@ static void parse_conf(const char *path, int flag) | |||
575 | if (*p0 == '/') { | 568 | if (*p0 == '/') { |
576 | /* make full path from httpd root / current_path / config_line_path */ | 569 | /* make full path from httpd root / current_path / config_line_path */ |
577 | cf = (flag == SUBDIR_PARSE ? path : ""); | 570 | cf = (flag == SUBDIR_PARSE ? path : ""); |
578 | p0 = malloc(strlen(cf) + (c - buf) + 2 + strlen(c)); | 571 | p0 = xmalloc(strlen(cf) + (c - buf) + 2 + strlen(c)); |
579 | if (p0 == NULL) | ||
580 | continue; | ||
581 | c[-1] = '\0'; | 572 | c[-1] = '\0'; |
582 | sprintf(p0, "/%s%s", cf, buf); | 573 | sprintf(p0, "/%s%s", cf, buf); |
583 | 574 | ||
@@ -694,9 +685,11 @@ static char *encodeString(const char *string) | |||
694 | char ch; | 685 | char ch; |
695 | 686 | ||
696 | while ((ch = *string++)) { | 687 | while ((ch = *string++)) { |
697 | // very simple check for what to encode | 688 | /* very simple check for what to encode */ |
698 | if (isalnum(ch)) *p++ = ch; | 689 | if (isalnum(ch)) |
699 | else p += sprintf(p, "&#%d;", (unsigned char) ch); | 690 | *p++ = ch; |
691 | else | ||
692 | p += sprintf(p, "&#%d;", (unsigned char) ch); | ||
700 | } | 693 | } |
701 | *p = '\0'; | 694 | *p = '\0'; |
702 | return out; | 695 | return out; |
@@ -717,18 +710,21 @@ static char *encodeString(const char *string) | |||
717 | */ | 710 | */ |
718 | static unsigned hex_to_bin(unsigned char c) | 711 | static unsigned hex_to_bin(unsigned char c) |
719 | { | 712 | { |
720 | unsigned v = c | 0x20; /* lowercase */ | 713 | unsigned v; |
721 | v = v - '0'; | 714 | |
715 | v = c - '0'; | ||
722 | if (v <= 9) | 716 | if (v <= 9) |
723 | return v; | 717 | return v; |
724 | v = v + ('0' - 'a'); | 718 | /* c | 0x20: letters to lower case, non-letters |
719 | * to (potentially different) non-letters */ | ||
720 | v = (unsigned)(c | 0x20) - 'a'; | ||
725 | if (v <= 5) | 721 | if (v <= 5) |
726 | return v + 10; | 722 | return v + 10; |
727 | return ~0; | 723 | return ~0; |
728 | } | 724 | } |
729 | /* For testing: | 725 | /* For testing: |
730 | void t(char c) { printf("'%c' %u\n", c, hex_to_bin(c)); } | 726 | void t(char c) { printf("'%c'(%u) %u\n", c, c, hex_to_bin(c)); } |
731 | int main() { t('0'); t('9'); t('A'); t('F'); t('a'); t('f'); | 727 | int main() { t(0x10); t(0x20); t('0'); t('9'); t('A'); t('F'); t('a'); t('f'); |
732 | t('0'-1); t('9'+1); t('A'-1); t('F'+1); t('a'-1); t('f'+1); return 0; } | 728 | t('0'-1); t('9'+1); t('A'-1); t('F'+1); t('a'-1); t('f'+1); return 0; } |
733 | */ | 729 | */ |
734 | static char *decodeString(char *orig, int option_d) | 730 | static char *decodeString(char *orig, int option_d) |
diff --git a/runit/svlogd.c b/runit/svlogd.c index b8fa5645b..6c8747e96 100644 --- a/runit/svlogd.c +++ b/runit/svlogd.c | |||
@@ -513,22 +513,25 @@ static unsigned logdir_open(struct logdir *ld, const char *fn) | |||
513 | /* read config */ | 513 | /* read config */ |
514 | i = open_read_close("config", buf, sizeof(buf)); | 514 | i = open_read_close("config", buf, sizeof(buf)); |
515 | if (i < 0 && errno != ENOENT) | 515 | if (i < 0 && errno != ENOENT) |
516 | bb_perror_msg(WARNING": %s/config", ld->name); | 516 | bb_perror_msg(WARNING"%s/config", ld->name); |
517 | if (i > 0) { | 517 | if (i > 0) { |
518 | if (verbose) | 518 | if (verbose) |
519 | bb_error_msg(INFO"read: %s/config", ld->name); | 519 | bb_error_msg(INFO"read: %s/config", ld->name); |
520 | s = buf; | 520 | s = buf; |
521 | while (s) { | 521 | while (s) { |
522 | np = strchr(s, '\n'); | 522 | np = strchr(s, '\n'); |
523 | if (np) *np++ = '\0'; | 523 | if (np) |
524 | *np++ = '\0'; | ||
524 | switch (s[0]) { | 525 | switch (s[0]) { |
525 | case '+': | 526 | case '+': |
526 | case '-': | 527 | case '-': |
527 | case 'e': | 528 | case 'e': |
528 | case 'E': | 529 | case 'E': |
530 | /* Add '\n'-terminated line to ld->inst */ | ||
529 | while (1) { | 531 | while (1) { |
530 | int l = asprintf(&new, "%s%s\n", ld->inst?:"", s); | 532 | int l = asprintf(&new, "%s%s\n", ld->inst ? : "", s); |
531 | if (l >= 0 && new) break; | 533 | if (l >= 0 && new) |
534 | break; | ||
532 | pause_nomem(); | 535 | pause_nomem(); |
533 | } | 536 | } |
534 | free(ld->inst); | 537 | free(ld->inst); |
@@ -578,7 +581,8 @@ static unsigned logdir_open(struct logdir *ld, const char *fn) | |||
578 | s = ld->inst; | 581 | s = ld->inst; |
579 | while (s) { | 582 | while (s) { |
580 | np = strchr(s, '\n'); | 583 | np = strchr(s, '\n'); |
581 | if (np) *np++ = '\0'; | 584 | if (np) |
585 | *np++ = '\0'; | ||
582 | s = np; | 586 | s = np; |
583 | } | 587 | } |
584 | } | 588 | } |
@@ -586,7 +590,7 @@ static unsigned logdir_open(struct logdir *ld, const char *fn) | |||
586 | /* open current */ | 590 | /* open current */ |
587 | i = stat("current", &st); | 591 | i = stat("current", &st); |
588 | if (i != -1) { | 592 | if (i != -1) { |
589 | if (st.st_size && ! (st.st_mode & S_IXUSR)) { | 593 | if (st.st_size && !(st.st_mode & S_IXUSR)) { |
590 | ld->fnsave[25] = '.'; | 594 | ld->fnsave[25] = '.'; |
591 | ld->fnsave[26] = 'u'; | 595 | ld->fnsave[26] = 'u'; |
592 | ld->fnsave[27] = '\0'; | 596 | ld->fnsave[27] = '\0'; |
@@ -600,8 +604,9 @@ static unsigned logdir_open(struct logdir *ld, const char *fn) | |||
600 | rmoldest(ld); | 604 | rmoldest(ld); |
601 | i = -1; | 605 | i = -1; |
602 | } else { | 606 | } else { |
603 | /* Be paranoid: st.st_size can be not just bigger, but WIDER! */ | 607 | /* st.st_size can be not just bigger, but WIDER! |
604 | /* (bug in original svlogd. remove this comment when fixed there) */ | 608 | * This code is safe: if st.st_size > 4GB, we select |
609 | * ld->sizemax (because it's "unsigned") */ | ||
605 | ld->size = (st.st_size > ld->sizemax) ? ld->sizemax : st.st_size; | 610 | ld->size = (st.st_size > ld->sizemax) ? ld->sizemax : st.st_size; |
606 | } | 611 | } |
607 | } else { | 612 | } else { |
@@ -667,7 +672,7 @@ static int buffer_pread(int fd, char *s, unsigned len) | |||
667 | int i; | 672 | int i; |
668 | 673 | ||
669 | input.fd = 0; | 674 | input.fd = 0; |
670 | input.events = POLLIN|POLLHUP|POLLERR; | 675 | input.events = POLLIN; |
671 | 676 | ||
672 | do { | 677 | do { |
673 | if (rotateasap) { | 678 | if (rotateasap) { |
@@ -744,7 +749,6 @@ static int buffer_pread(int fd, char *s, unsigned len) | |||
744 | return i; | 749 | return i; |
745 | } | 750 | } |
746 | 751 | ||
747 | |||
748 | static void sig_term_handler(int sig_no) | 752 | static void sig_term_handler(int sig_no) |
749 | { | 753 | { |
750 | if (verbose) | 754 | if (verbose) |