[coreboot] lar directory handling patch
Peter Stuge
peter at stuge.se
Tue Feb 26 00:34:01 CET 2008
On Mon, Feb 25, 2008 at 01:47:59PM -0700, Myles Watson wrote:
> strncpy(fullname, name, MAX_PATH);
> + strncpy(fullpathname, pathname, MAX_PATH);
--8<-- strcpy(3)
The strncpy() function is similar, except that at most n bytes of src
are copied. Warning: If there is no null byte among the first n bytes
of src, the string placed in dest will not be null terminated.
-->8--
One fix is to simply memset() fullname and fullpathname at the start
of the function - I don't like assuming that heap variables are
zero initialized.
> if (name[(strlen(name)) - 1] != '/') {
> strncat(fullname, "/", MAX_PATH);
> }
>
> + if (name[(strlen(pathname)) - 1] != '/') {
> + strncat(fullpathname, "/", MAX_PATH);
> + }
> +
> strncat(fullname, namelist[n]->d_name,
> MAX_PATH);
>
> - add_files(fullname);
> + strncat(fullpathname, namelist[n]->d_name,
> + MAX_PATH);
> +
> + add_files(fullname,fullpathname,thisalgo);
This algorithm protects against overflow, but I would like if it also
raised an error when MAX_PATH isn't big enough.
> +int add_files(const char *name, const char * pathname_in,
> + const enum compalgo algo_in)
..
> + ret = lar_process_name((char*)name, &filename, &pathname, &thisalgo);
Why is this cast needed? Does lar_process_name() modify name? If not
please fix it's prototype so no cast is needed.
> + /*printf("%s: %s (%s:%s)\n",__FUNCTION__,name,filename,pathname);*/
Is there some debug functionality in lar for these?
> if (elfparse() && iself(ptr)) {
> - output_elf_segments(lar, pathname, ptr, size, thisalgo);
> + output_elf_segments(lar, file->pathname, ptr, size, file->algo);
How does this work with file->algo vs. zeroes compression?
//Peter
More information about the coreboot
mailing list