diff mbox

[2/2] e2p: Fix segfault in e2p_os2string.

Message ID 20170718192919.32406-3-abuchbinder@google.com
State Superseded, archived
Headers show

Commit Message

Adam Buchbinder July 18, 2017, 7:29 p.m. UTC
Passing in a negative integer would lead to a segfault, and
a crafted filesystem image could trigger that.

Signed-off-by: Adam Buchbinder <abuchbinder@google.com>
---
 lib/e2p/ostype.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andreas Dilger July 18, 2017, 8:04 p.m. UTC | #1
On Jul 18, 2017, at 1:29 PM, Adam Buchbinder <abuchbinder@google.com> wrote:
> 
> Passing in a negative integer would lead to a segfault, and
> a crafted filesystem image could trigger that.
> 
> Signed-off-by: Adam Buchbinder <abuchbinder@google.com>

Reviewed-by: Andreas Dilger <adilger@dilger.ca>

Note that it would be better to land this patch as 1/2, and the test which
causes the segfault as 2/2, otherwise it could break git bisect.

Cheers, Andreas
> ---
> lib/e2p/ostype.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/e2p/ostype.c b/lib/e2p/ostype.c
> index 7f088446..c5fd8ab3 100644
> --- a/lib/e2p/ostype.c
> +++ b/lib/e2p/ostype.c
> @@ -30,7 +30,7 @@ char *e2p_os2string(int os_type)
>         const char	*os;
> 	char 		*ret;
> 
> -	if (os_type <= EXT2_OS_LITES)
> +	if (os_type >= 0 && os_type <= EXT2_OS_LITES)
> 		os = os_tab[os_type];
> 	else
> 		os = "(unknown os)";




Cheers, Andreas
diff mbox

Patch

diff --git a/lib/e2p/ostype.c b/lib/e2p/ostype.c
index 7f088446..c5fd8ab3 100644
--- a/lib/e2p/ostype.c
+++ b/lib/e2p/ostype.c
@@ -30,7 +30,7 @@  char *e2p_os2string(int os_type)
         const char	*os;
 	char 		*ret;
 
-	if (os_type <= EXT2_OS_LITES)
+	if (os_type >= 0 && os_type <= EXT2_OS_LITES)
 		os = os_tab[os_type];
 	else
 		os = "(unknown os)";