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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YSjDH1y8AJIvCstV@alley>
Date:   Fri, 27 Aug 2021 12:49:03 +0200
From:   Petr Mladek <pmladek@...e.com>
To:     Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Cc:     Joe Perches <joe@...ches.com>,
        Steven Rostedt <rostedt@...dmis.org>,
        Sergey Senozhatsky <senozhatsky@...omium.org>,
        Rasmus Villemoes <linux@...musvillemoes.dk>,
        Matthew Wilcox <willy@...radead.org>,
        Jonathan Corbet <corbet@....net>, linux-doc@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/5] vsprintf/Documentation: Add X to %*ph extension to
 output upper case hex

On Fri 2021-08-27 11:49:07, Andy Shevchenko wrote:
> On Fri, Aug 27, 2021 at 01:08:10AM -0700, Joe Perches wrote:
> > On Fri, 2021-08-27 at 10:48 +0300, Andy Shevchenko wrote:
> > > On Thu, Aug 26, 2021 at 11:43:01AM -0700, Joe Perches wrote:
> > > > A few sysfs output uses of hex arrays are uppercase and are nominally ABI.
> > > > 
> > > > Add a mechanism to the existing vsprintf %*ph hex output extension to
> > > > support upper case hex output.
> > > 
> > > ...
> > > 
> > > > +	The preferred output is lowercase
> > > >  	%*ph	00 01 02  ...  3f
> > > >  	%*phC	00:01:02: ... :3f
> > > >  	%*phD	00-01-02- ... -3f
> > > >  	%*phN	000102 ... 3f
> > > > +	Formats with X are uppercase, used for backwards compatibility
> > > > +	%*phX	00 01 02  ...  3F
> > > > +	%*phCX	00:01:02: ... :3F
> > > > +	%*phDX	00-01-02- ... -3F
> > > > +	%*phNX	000102 ... 3F
> > > 
> > > Why not using %*pH...?

I though about this as well.

> > I find X more intelligible.

I would slightly prefer %pH. I always have problems to parse long
sequences of modifiers. So, the shorter format the better.

Of course, it means that 'H' won't be usable for another purpose.
But it will happen one day anyway. Well, this is why I do not
have strong opinion.

I am more and more convinced that we will need another approach.
Mathew Wilcox has had an idea to add support for custom callbacks
that would be able to format the string, something like:

   vsprintf("Date: %pX(%p)\n", format_date, time_stamp);

I think that it might even be possible to do something like:

   vsprintf("Date: %pX\n", format_date(time));

, where the format_date() would be a macro that would create
a struct at stack a pass it as a pointer:

#define format_date(time)			   \
({						   \
	struct vsprintf_callback c = {		   \
		.func = vsprintf_format_date,	   \
		.arg1 = time,			   \
	}					   \
						   \
	&c;					   \
})

and vsprintf would internally do something like:

char *custom_format(char *buf, char *end, vsprintf_callback *c,
			 struct printf_spec spec, const char *fmt)
{
	return c->func(buf, end, c->arg1, spec);
}

It would allow to replace all the magic %pXYZ modifiers with
self-explanatory callbacks. While still keeping it easy to use.

Best Regards,
Petr

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ