0002-file_enhancements.patch 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. Create better temporary files.
  2. Probably-Signed-off-by: Dave Bender <bender@benegon.com>
  3. [yann.morin.1998@free.fr: patch was made by Dave, but he
  4. forgot his SoB line, so I added it; split the patch in two
  5. independent fixes]
  6. Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
  7. diff -rupN cgic206/cgic.c cgic206_tempfile/cgic.c
  8. --- cgic206/cgic.c 2014-03-16 18:17:11.000000000 -0400
  9. +++ cgic206_tempfile/cgic.c 2015-01-21 11:58:45.436384908 -0500
  10. @@ -22,6 +22,8 @@
  11. #define CGICDEBUGEND
  12. #endif /* CGICDEBUG */
  13. +#define _GNU_SOURCE
  14. +
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <ctype.h>
  18. @@ -34,11 +36,11 @@
  19. #include <io.h>
  20. /* cgic 2.01 */
  21. -#include <fcntl.h>
  22. #else
  23. #include <unistd.h>
  24. #endif /* WIN32 */
  25. +#include <fcntl.h>
  26. #include "cgic.h"
  27. #define cgiStrEq(a, b) (!strcmp((a), (b)))
  28. @@ -636,16 +638,17 @@ static cgiParseResultType getTempFileNam
  29. window between the file's creation and the
  30. chmod call (glibc 2.0.6 and lower might
  31. otherwise have allowed this). */
  32. + mode_t umode;
  33. int outfd;
  34. + umode = umask(0600);
  35. strcpy(tfileName, cgicTempDir "/cgicXXXXXX");
  36. - outfd = mkstemp(tfileName);
  37. + outfd = mkostemp(tfileName, O_CLOEXEC | O_NOATIME);
  38. + umask(umode);
  39. if (outfd == -1) {
  40. return cgiParseIO;
  41. }
  42. - close(outfd);
  43. - /* Fix the permissions */
  44. - if (chmod(tfileName, 0600) != 0) {
  45. - unlink(tfileName);
  46. +
  47. + if (close(outfd)) {
  48. return cgiParseIO;
  49. }
  50. #else