lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZKqc5Uj14C7ST21K@casper.infradead.org>
Date:   Sun, 9 Jul 2023 12:41:25 +0100
From:   Matthew Wilcox <willy@...radead.org>
To:     Linke Li <lilinke99@...mail.com>
Cc:     linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org,
        Jan Kara <jack@...e.cz>, Linke Li <lilinke99@...il.com>
Subject: Re: [PATCH] isofs: fix undefined behavior in iso_date()

On Sun, Jul 09, 2023 at 02:42:55PM +0800, Linke Li wrote:
> From: Linke Li <lilinke99@...il.com>
> 
> Fix undefined behavior in the code by properly handling the left shift operaion.
> Instead of left-shifting a negative value, explicitly cast -1 to an unsigned int
> before the shift. This ensures well defined behavior and resolves any potential
> issues.

This certainly fixes the problem, but wouldn't it be easier to get the
compiler to do the work for us?

#include <stdio.h>

int f(unsigned char *p)
{
	return (signed char)p[0];
}

int main(void)
{
	unsigned char x = 0xa5;

	printf("%d\n", f(&x));

	return 0;
}

prints -91.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ