[Date Index][Thread Index]
[Date Prev][Date Next][Thread Prev][Thread Next]
gfont SEGV, patch
- From: Dave Plonka <nospam@thanx>
- Date: Mon, 2 Aug 1999 17:46:44 -0500
Denis & WML users,
gfont gets SEGV if the directory in which the output file would be
written does not exist. This is most likely to happen when gfont is used
with wml where it is common to write the images to a directory specified
by a variable as in "-DIMG~./images".
[Just FYI, I submitted this as a bug on the gfont web page as well.]
Attached is a fairly trivial patch to "gfont_main.c". It fixes gfont
so that it checks to be sure that fopen(3) of the output file works
before trying to write to the resultant file pointer. While seemingly
trivial, this bug caused me a nasty problem when my output image directory
didn't exist... gfont ignored and did not report the failure of open(2)
with ENOENT, then got SEGV when it used a bad FILE pointer. wml reported
the SEGV error from gfont, but it was less than obvious as to what was the
root cause.
Additionally, to better conform with ANSI/ISO C, the patched version uses
strchr(3) rather than the unprototyped index(3) (this also eliminated a
compiler warning under Solaris) and uses exit(3) rather than "return" from
main(). I used my "headers" utility
("http://net.doit.wisc.edu/~plonka/headers/") to generate the set of
include directives.
Dave
--
plonka@doit.wisc.edu http://net.doit.wisc.edu/~plonka ARS:N9HZF Madison, WI
*** gfont_main.c_djp Tue Sep 16 03:09:22 1997
--- gfont_main.c Mon Aug 2 17:02:06 1999
***************
*** 35,44 ****
** gfont_main.c -- main program
*/
! #include <stdio.h>
! #include <stdlib.h>
! #include <string.h>
! #include <stdarg.h>
#include "gfont_gd.h"
#include "gfont_gdfontl.h"
--- 35,46 ----
** gfont_main.c -- main program
*/
! #include <errno.h> /* errno */
! #include <stdarg.h> /* va_list, va_start, va_end */
! #include <stddef.h> /* NULL */
! #include <stdio.h> /* vsprintf, fprintf, stderr, stdout, FILE, sprintf, fopen, fclose */
! #include <stdlib.h> /* atoi, exit, getenv, system, abs */
! #include <string.h> /* strcpy, strchr, strlen, strerror */
#include "gfont_gd.h"
#include "gfont_gdfontl.h"
***************
*** 95,101 ****
char *cp;
strcpy(spec, str);
! if ((cp = index(spec, 'x')) == NULL)
return 1;
*cp++ = '\0';
xspec = spec;
--- 97,103 ----
char *cp;
strcpy(spec, str);
! if ((cp = strchr(spec, 'x')) == NULL)
return 1;
*cp++ = '\0';
xspec = spec;
***************
*** 503,508 ****
--- 505,515 ----
Verbose("Exporting image to GIF file: ");
fp = fopen(outputfile, "w");
+ if ((FILE *)0 == fp) {
+ fprintf(stderr,
+ "fopen \"%s\", \"w\": %s\n", outputfile, strerror(errno));
+ exit(1);
+ }
gdImageGif(ip, fp);
fclose(fp);
Verbose("Done\n");
***************
*** 511,517 ****
gdImageDestroy(ip);
Verbose("Done\n");
! return 0;
}
/*EOF*/
--- 518,524 ----
gdImageDestroy(ip);
Verbose("Done\n");
! exit(0);
}
/*EOF*/