[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: libpst: FTBFS on hurd-i386 (for review)



Svante Signell, le Sat 25 Aug 2012 19:19:02 +0200, a écrit :
>      if (png_open) {
>          png_open = false;
> -        char fn[PATH_MAX];
> -        snprintf(fn, sizeof(fn), "page%d.png", ++page_sequence);
> +        int len = 4 + 11 + 4;
> +        char *fn = (char*)pst_malloc(len + 1);
> +        snprintf(fn, len, "page%d.png", ++page_sequence);

len+1 for snprintf too, otherwise the last allocated character will not
be used, see man snprintf:

The  functions  snprintf() and vsnprintf() write at most size bytes
(including the terminating null byte ('\0')) to str.

Or you might as well put the +1 in len itself.

> -    snprintf(pdf_name, sizeof(pdf_name), "dii%06d", ++email_sequence);
> +    /* Note; allocating the largest string length to pdf_name */
> +    int len = strlen(output_directory) + 4 + 6 + 4;

why 4 before 6 ?

> +    pdf_name = (char*)pst_malloc(len + 1);
> +    snprintf(pdf_name, 3 + 6 + 1, "dii%06d", ++email_sequence);

it's a 3 here, for "dii".

>      fprintf(dii_file, "\n@T %s\n", pdf_name);
> -    snprintf(pdf_name, sizeof(pdf_name), "%s/dii%06d.pdf", output_directory, email_sequence);
> +    snprintf(pdf_name, len, "%s/dii%06d.pdf", output_directory, email_sequence);

Same as above, snprintf should get the total allocated size, otherwise
it'll get truncated.

Samuel


Reply to: