Browse code

fuzz - 12311 - correcting types and placing checks to fix int storage size issues with HTML normalizer

Mickey Sola authored on 2019/01/17 05:52:53
Showing 1 changed files
... ...
@@ -647,7 +647,7 @@ static void js_process(struct parser_state *js_state, const unsigned char *js_be
647 647
 static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag_arguments_t *hrefs,const struct cli_dconf* dconf)
648 648
 {
649 649
 	int fd_tmp, tag_length = 0, tag_arg_length = 0, binary;
650
-	int retval=FALSE, escape=FALSE, value = 0, hex=FALSE, tag_val_length=0;
650
+    int64_t retval = FALSE, escape = FALSE, value = 0, hex = FALSE, tag_val_length = 0;
651 651
 	int look_for_screnc=FALSE, in_screnc=FALSE,in_script=FALSE, text_space_written=FALSE;
652 652
 	FILE *stream_in = NULL;
653 653
 	html_state state=HTML_NORM, next_state=HTML_BAD_STATE, saved_next_state=HTML_BAD_STATE;
... ...
@@ -1459,10 +1459,16 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
1459 1459
 					next_state = HTML_BAD_STATE;
1460 1460
 					ptr++;
1461 1461
 				} else if (isdigit(*ptr) || (hex && isxdigit(*ptr))) {
1462
-					if (hex) {
1462
+                        if (hex && (value >> 32) * 16 < INT32_MAX) {
1463 1463
 						value *= 16;
1464
-					} else {
1464
+                        } else if ((value >> 32) * 10 < INT32_MAX) {
1465 1465
 						value *= 10;
1466
+                        } else {
1467
+                            html_output_c(file_buff_o2, value);
1468
+                            state      = next_state;
1469
+                            next_state = HTML_BAD_STATE;
1470
+                            ptr++;
1471
+                            break;
1466 1472
 					}
1467 1473
 					if (isdigit(*ptr)) {
1468 1474
 						value += (*ptr - '0');
... ...
@@ -1709,7 +1715,14 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
1709 1709
 				state = HTML_RFC2397_DATA;
1710 1710
 				break;
1711 1711
 			case HTML_ESCAPE_CHAR:
1712
+                    if ((value >> 32) * 16 < INT32_MAX) {
1712 1713
 				value *= 16;
1714
+                    } else {
1715
+                        state = next_state;
1716
+                        next_state = HTML_BAD_STATE;
1717
+                        ptr++;
1718
+                        break;
1719
+                    }
1713 1720
 				length++;
1714 1721
 				if (isxdigit(*ptr)) {
1715 1722
 					if (isdigit(*ptr)) {