소스 검색

[pixbuf] Check for unsigned integer overflow on multiplication

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 8 년 전
부모
커밋
11396473f5
1개의 변경된 파일5개의 추가작업 그리고 0개의 파일을 삭제
  1. 5
    0
      src/core/pixbuf.c

+ 5
- 0
src/core/pixbuf.c 파일 보기

@@ -65,6 +65,10 @@ struct pixel_buffer * alloc_pixbuf ( unsigned int width, unsigned int height ) {
65 65
 	pixbuf->height = height;
66 66
 	pixbuf->len = ( width * height * sizeof ( uint32_t ) );
67 67
 
68
+	/* Check for multiplication overflow */
69
+	if ( ( ( pixbuf->len / sizeof ( uint32_t ) ) / width ) != height )
70
+		goto err_overflow;
71
+
68 72
 	/* Allocate pixel data buffer */
69 73
 	pixbuf->data = umalloc ( pixbuf->len );
70 74
 	if ( ! pixbuf->data )
@@ -73,6 +77,7 @@ struct pixel_buffer * alloc_pixbuf ( unsigned int width, unsigned int height ) {
73 77
 	return pixbuf;
74 78
 
75 79
  err_alloc_data:
80
+ err_overflow:
76 81
 	pixbuf_put ( pixbuf );
77 82
  err_alloc_pixbuf:
78 83
 	return NULL;

Loading…
취소
저장