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] [day] [month] [year] [list]
Message-ID: <e1259039a99d4f23958c4380e5c0b11f@AcuMS.aculab.com>
Date: Sun, 8 Sep 2024 20:08:23 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Andy Shevchenko' <andy.shevchenko@...il.com>, zhangjiao2
	<zhangjiao2@...s.chinamobile.com>
CC: "wbg@...nel.org" <wbg@...nel.org>, "linux-iio@...r.kernel.org"
	<linux-iio@...r.kernel.org>, "linux-kernel@...r.kernel.org"
	<linux-kernel@...r.kernel.org>
Subject: RE: [PATCH] tools/counter: close fd when exit

From: Andy Shevchenko
> Sent: 04 September 2024 00:20
> 
> Tue, Sep 03, 2024 at 04:01:21PM +0800, zhangjiao2 kirjoitti:
> > From: zhang jiao <zhangjiao2@...s.chinamobile.com>
> >
> > close fd when exit the program
> 
> Please, mind English grammar and punctuation.
> Also this doesn't state what the problem is.

After all, when the program exits the kernel closes all the files.

> >  		if (ret == -1) {
> >  			fprintf(stderr, "Error adding watches[%d]: %s\n", i,
> >  				strerror(errno));
> > +			close(fd);
> 
> Since fd is not used in the messaging it's better to close it before printing
> anything. Ditto for other cases.

Unless close() decides to change errno...

> 
> ...
> 
> >  		if (ret != sizeof(event_data)) {
> >  			fprintf(stderr, "Failed to read event data\n");
> > +			close(fd);
> 
> >  			return -EIO;
> 
> Side note: This will return garbage to the userspace. Should be
> 
> 			return EIO;

If that is the return value from main() it is equally invalid.
Valid return values are 0..255 but 128..255 are likely to be
interpreted as 'killed by a signal'.
So really you only get 0..127.
Mostly used as 0 => success and 1 => failure.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ