On Wed, Feb 04, 2026 at 08:47:41AM -0800, Josh Poimboeuf wrote:
> On Tue, Feb 03, 2026 at 09:51:36PM -0500, Joe Lawrence wrote:
> > @@ -1219,13 +1221,17 @@ struct elf *elf_create_file(GElf_Ehdr *ehdr, const 
> > char *name)
> >  
> >     base = basename(base);
> >  
> > -   tmp_name = malloc(256);
> > +   tmp_name = malloc(PATH_MAX);
> 
> The allocation size can be more precise with something like
> 
>       tmp_name = malloc(strlen(name) + 8);
> 
> Also, I'm scratching my head at the existing code and wondering why we
> are splitting out the dirname() and the basename() just to paste them
> back together again??  Can you simplify that while you're at it?
> 
> >     if (!tmp_name) {
> >             ERROR_GLIBC("malloc");
> >             return NULL;
> >     }
> >  
> > -   snprintf(tmp_name, 256, "%s/%s.XXXXXX", dir, base);
> > +   path_len = snprintf(tmp_name, PATH_MAX, "%s/%s.XXXXXX", dir, base);
> > +   if (path_len >= PATH_MAX) {
> > +           ERROR_GLIBC("snprintf");
> > +           return NULL;
> > +   }
> 
> Checking for all the snprintf() cases can be a pain so we have a
> snprintf_check() for a streamlined error checking experience.
> 

Ah, completely missed that, thanks for pointing out.  I'll incorporate
both suggestions into v3.

--
Joe


Reply via email to