git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] convert: fail gracefully upon missing clean cmd on required filter

From
MÅMartin Ågren <martin.agren@gmail.com>
Date
Feb 26, 2021, 06:27 UTC
Message-ID
<CAN0heSptkHY3A0MHEDwfaMQ0cqhhGwg7hTy70NOsMcp-otROSg@mail.gmail.com>
In-Reply-To
<b33d0dc82f5ff1fac6772e533bbf21eecfae44ed.1614277014.git.matheus.bernardino@usp.br>
On Thu, 25 Feb 2021 at 19:18, Matheus Tavares <matheus.bernardino@usp.br> wrote:
> This assertion and the one above it are not really necessary, as the
> apply_filter() call bellow them already performs the same checks. And
s/bellow/below/
> when these conditions are not met, the function returns 0, making the
> caller die() with a much nicer message. (Also note that die()-ing here
Makes sense. I noticed one thing:
> -       assert(ca.drv);
If ca.drv is NULL ....
> -       assert(ca.drv->clean || ca.drv->process);
> -
>         if (!apply_filter(path, NULL, 0, fd, dst, ca.drv, CAP_CLEAN, NULL, NULL))
... the return value will be 0, so this will trigger ...
>                 die(_("%s: clean filter '%s' failed"), path, ca.drv->name);
... and we'll dereference NULL to grab the name.

It seems like you could leave that first assertion and your new tests would still pass. Hitting an assertion is arguably better than wandering off into undefined behavior. (What will probably happen is ca.drv->name will effectively also be NULL, because it's at the top of the struct. Some implementations will format this as "(null)", others will crash.)

As you note, and my reading agrees, you can't really have ca.drv be NULL here. So this is like, if and when we grow a bug somewhere and actually do have NULL, maybe we would rather hit that "assert" than go dereferencing NULL.

Martin
Previous: Junio C HamanoNext: Matheus Tavares
Message 3 of 5 in “convert: fail gracefully upon missing clean cmd on required filter”
  1. convert: fail gracefully upon missing clean cmd on required filterMatheus Tavares, Feb 25, 2021
  2. Junio C HamanoFeb 25, 2021
  3. Martin ÅgrenFeb 26, 2021
  4. convert: fail gracefully upon missing clean cmd on required filterMatheus Tavares, Feb 26, 2021
  5. Martin ÅgrenFeb 28, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.