patch-src_edit_c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. $OpenBSD: patch-src_edit_c,v 1.1.1.1 2013/05/04 15:13:47 jturner Exp $
  2. commit 7677b8ad51c5bbcae9dd08afb08d32e242d497ce
  3. Author: James Turner <james@calminferno.net>
  4. Date: Fri May 3 17:19:38 2013 -0400
  5. --- src/edit.c.orig Fri May 3 22:19:53 2013
  6. +++ src/edit.c Fri May 3 22:23:49 2013
  7. @@ -1222,23 +1222,30 @@ int settab (char str[])
  8. }
  9. -/* serc_safe --- check if the file permissions and ownership are safe */
  10. +/* serc_safe_open --- open and check if the file permissions and ownership are safe */
  11. /*
  12. * err on the side of caution and only exec ~/.serc and ./serc files
  13. * that we own and cannot be written by others.
  14. */
  15. -int serc_safe (char *path)
  16. +FILE *serc_safe_open (char *path)
  17. {
  18. + FILE *fp;
  19. int rc;
  20. uid_t our_euid;
  21. struct stat sbuf;
  22. - rc = stat (path, &sbuf);
  23. + if ((fp = fopen (path, "r")) == NULL)
  24. + {
  25. + return NULL;
  26. + }
  27. +
  28. + rc = fstat (fileno(fp), &sbuf);
  29. if (rc != 0)
  30. {
  31. - return NO;
  32. + fclose(fp);
  33. + return NULL;
  34. }
  35. our_euid = geteuid ();
  36. @@ -1246,16 +1253,18 @@ int serc_safe (char *path)
  37. /* don't exec .serc files that aren't ours */
  38. if (sbuf.st_uid != our_euid)
  39. {
  40. - return NO;
  41. + fclose(fp);
  42. + return NULL;
  43. }
  44. /* don't .serc files that others can write to */
  45. if ((sbuf.st_mode & S_IWGRP) || (sbuf.st_mode & S_IWOTH))
  46. {
  47. - return NO;
  48. + fclose(fp);
  49. + return NULL;
  50. }
  51. - return YES;
  52. + return fp;
  53. }
  54. @@ -1285,8 +1294,7 @@ void serc (void)
  55. for (i = 0; serc_files[i]; i++)
  56. {
  57. - if ((serc_safe (serc_files[i]) == YES) &&
  58. - ((fp = fopen (serc_files[i], "r")) != NULL))
  59. + if ((fp = serc_safe_open (serc_files[i])) != NULL)
  60. {
  61. break;
  62. }