[PATCH 3/3] move shared code to get_mimetype_from_file()

Christian Hesse list at eworm.de
Sat Aug 15 22:12:43 CEST 2015


John Keeping <john at keeping.me.uk> on Sat, 2015/08/15 12:29:
> > +			/* loop over all lines in the file */
> > +			while (!*mimetype && fgets(line, sizeof(line),
> > fd)) {
> > +				iterate = strtok(line, delimiters);
> > +
> > +				/* skip empty lines and comment lines */
> > +				if (!iterate || (iterate[0] == '#'))
> > +					continue;
> > +
> > +				/* loop over all extensions of mimetype
> > */
> > +				while ((token = strtok(NULL,
> > delimiters))) {
> > +					if (!strcasecmp(ext, token)) {
> > +						*mimetype = iterate;  
> 
> Doesn't this result in us reading stale memory in the caller?
> "iterate" derives from "line" which is on the stack.

This used to work, probably just as long as we do not call strtok() again. I
addressed that in my updated patches.
-- 
main(a){char*c=/*    Schoene Gruesse                         */"B?IJj;MEH"
"CX:;",b;for(a/*    Chris           get my mail address:    */=0;b=c[a++];)
putchar(b-1/(/*               gcc -o sig sig.c && ./sig    */b/42*2-3)*42);}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20150815/d43619c3/attachment-0001.asc>


More information about the CGit mailing list