Messages in this thread | | | Subject | Re: [PATCH 2/2] vsprintf: don't dereference pointers to the first or last page | From | Andy Shevchenko <> | Date | Wed, 07 Mar 2018 15:22:21 +0200 |
| |
On Tue, 2018-03-06 at 19:11 +0100, Adam Borowski wrote: > As old code to avoid so is inconsistent, let's unify it within a > single > macro. > > > +#define IS_BAD_PTR(x) ((unsigned long)(x) >= (unsigned long)- > PAGE_SIZE \ > + || (unsigned long)(x) < PAGE_SIZE)
Oh, no.
First of all, why it's a macro?
Next, what prevents us to do it in place using IS_ERR() instead? (Btw, I have a patch for that, not published yet)
> #define BAD_PTR_STRING(x) (!(x) ? "(null)" : IS_ERR(x) ? "(err)" : > "(invalid)") > > /** > @@ -589,7 +591,7 @@ char *string(char *buf, char *end, const char *s, > struct printf_spec spec) > int len = 0; > size_t lim = spec.precision; > > - if ((unsigned long)s < PAGE_SIZE) > + if (IS_BAD_PTR(s)) > s = BAD_PTR_STRING(s);
I don't think it's a good idea to change current behaviour.
> @@ -1583,7 +1585,7 @@ char *device_node_string(char *buf, char *end, > struct device_node *dn, > if (!IS_ENABLED(CONFIG_OF)) > return string(buf, end, "(!OF)", spec); > > - if ((unsigned long)dn < PAGE_SIZE) > + if (IS_BAD_PTR(dn)) > return string(buf, end, BAD_PTR_STRING(dn), spec);
This makes no sense. Explained in comment against patch 1.
> > /* simple case without anything any more format specifiers */ > @@ -1851,7 +1853,7 @@ char *pointer(const char *fmt, char *buf, char > *end, void *ptr, > { > const int default_width = 2 * sizeof(void *); > > - if (!ptr && *fmt != 'K' && *fmt != 'x') { > + if (IS_BAD_PTR(ptr) && *fmt != 'K' && *fmt != 'x') { > /* > * Print (null)/etc with the same width as a pointer > so it > * makes tabular output look nice. >
-- Andy Shevchenko <andriy.shevchenko@linux.intel.com> Intel Finland Oy
| |