From mboxrd@z Thu Jan 1 00:00:00 1970 From: list at eworm.de (Christian Hesse) Date: Sat, 15 Aug 2015 22:12:43 +0200 Subject: [PATCH 3/3] move shared code to get_mimetype_from_file() In-Reply-To: <20150815112935.GC1412@serenity.lan> References: <20150814151335.GB1412@serenity.lan> <1439586997-25333-1-git-send-email-list@eworm.de> <1439586997-25333-2-git-send-email-list@eworm.de> <20150815112935.GC1412@serenity.lan> Message-ID: <20150815221243.4b8fe2c2@leda.localdomain> John Keeping 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: