Re: [PATCH] libblkid: Fix crash while parsing config with libeconf

Karel Zak <[email protected]>
Newsgroups org.kernel.vger.util-linux
Message-ID <3p3ennukohxmst4qpalg6t43udyyyijwj6ddbmrpb72yeehxw4@qvj3bdyj3h7h>
On Tue, May 20, 2025 at 04:24:07PM +0200, Stanislav Brabec wrote:
> Stanislav Brabec wrote:
> > As the whhole econf_file structure is freed by econf_free(file) at the end
> 
> > of blkid_read_config, econf_file structure cannot be defined as static and
> > initialized only once. The econf_free() is not robust enough and keeps a
> > pointer to the garbage after the first call. And if /etc/blkid.conf does
> > not exist, it is called second time.
> 
> However the patch is correct and fixes the crash, there are still open questions:
> 
> - Why blkid_read_config() and econf_readConfig() are called twice with the same parameters? Is it intended behavior?

This code pattern (e.g., libblkid/src/evaluate.c):

     conf = blkid_read_config(NULL);
     ...

     cachefile = blkid_get_cache_filename(conf);
     rc = blkid_get_cache(&c, cachefile);

If blkid_get_cache_filename() returns NULL, then blkid_get_cache()
reads the configuration again. Additionally, blkid_get_cache_filename() can read the
configuration if 'conf' is NULL.

Yes, it's not elegant.

> - And finally, is a similar code in logindefs.c vulnerable to a similar type of crash?

The `logindefs` uses a global `list` variable, which should be filled only once.

    Karel

-- 
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.