patch-cda_d_cda_c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. $OpenBSD: patch-cda_d_cda_c,v 1.3 2007/04/12 12:28:02 millert Exp $
  2. --- cda_d/cda.c.orig Sat Feb 5 00:26:38 2000
  3. +++ cda_d/cda.c Tue May 6 12:36:11 2003
  4. @@ -349,23 +349,52 @@ cda_init(curstat_t *s)
  5. STATIC void
  6. cda_start(curstat_t *s)
  7. {
  8. + struct stat stbuf;
  9. +
  10. /* Start up libutil */
  11. util_start();
  12. /* Start up I/O interface */
  13. di_start(s);
  14. + /*
  15. + ** NO_FOLLOW isn't supported by all flavours of Unix,
  16. + ** but at least by linux and openbsd.
  17. + ** thomas@suse.de
  18. + */
  19. /* Open FIFOs - daemon side */
  20. - if ((cda_sfd[0] = open(spipe, O_RDONLY)) < 0) {
  21. + if ((cda_sfd[0] = open(spipe, O_RDONLY | O_NOFOLLOW)) < 0) {
  22. perror("CD audio daemon: cannot open send pipe");
  23. cda_quit(s);
  24. exit(4);
  25. }
  26. - if ((cda_rfd[0] = open(rpipe, O_WRONLY)) < 0) {
  27. + if ((cda_rfd[0] = open(rpipe, O_WRONLY | O_NOFOLLOW)) < 0) {
  28. perror("CD audio daemon: cannot open recv pipe");
  29. cda_quit(s);
  30. exit(5);
  31. }
  32. +
  33. + /* Check FIFOs */
  34. + if (stat(spipe, &stbuf) < 0 || !S_ISFIFO(stbuf.st_mode)) {
  35. + (void) fprintf(errfp,
  36. + "CD audio: Send pipe error (daemon): %s\n",
  37. + spipe);
  38. + di_halt(s);
  39. + /* Remove lock */
  40. + if (dlock[0] != '\0')
  41. + (void) UNLINK(dlock);
  42. + exit(6);
  43. + }
  44. + if (stat(rpipe, &stbuf) < 0 || !S_ISFIFO(stbuf.st_mode)) {
  45. + (void) fprintf(errfp,
  46. + "CD audio: Receive pipe error (daemon): %s\n",
  47. + rpipe);
  48. + di_halt(s);
  49. + /* Remove lock */
  50. + if (dlock[0] != '\0')
  51. + (void) UNLINK(dlock);
  52. + exit(6);
  53. + }
  54. }
  55. @@ -396,7 +425,7 @@ cda_daemonlock(void)
  56. fd = open(dlock, O_CREAT | O_EXCL | O_WRONLY);
  57. if (fd < 0) {
  58. if (errno == EEXIST) {
  59. - if ((fd = open(dlock, O_RDONLY)) < 0)
  60. + if ((fd = open(dlock, O_RDONLY | O_NOFOLLOW)) < 0)
  61. return FALSE;
  62. if (read(fd, buf, 12) > 0)
  63. @@ -430,7 +459,7 @@ cda_daemonlock(void)
  64. (void) write(fd, buf, strlen(buf));
  65. (void) close(fd);
  66. - (void) chmod(dlock, 0644);
  67. + (void) chmod(dlock, 0644); /* woudln't 0622 suffice ? */
  68. return TRUE;
  69. }
  70. @@ -3592,7 +3621,7 @@ cda_daemon_alive(void)
  71. (void) sprintf(dlock, "%s/cdad.%x", TEMP_DIR, (int) cd_rdev);
  72. - if ((fd = open(dlock, O_RDONLY)) < 0)
  73. + if ((fd = open(dlock, O_RDONLY | O_NOFOLLOW)) < 0)
  74. return FALSE;
  75. if (read(fd, buf, 12) < 0) {
  76. @@ -3644,7 +3673,7 @@ cda_daemon(curstat_t *s)
  77. /* Make temporary directory, if needed */
  78. (void) sprintf(emsgp, app_data.str_tmpdirerr, TEMP_DIR);
  79. if (LSTAT(TEMP_DIR, &stbuf) < 0) {
  80. - if (!util_mkdir(TEMP_DIR, 0777)) {
  81. + if (!util_mkdir(TEMP_DIR, 0700)) {
  82. (void) fprintf(errfp, "%s\n", emsgp);
  83. return 1;
  84. }
  85. @@ -3657,7 +3686,7 @@ cda_daemon(curstat_t *s)
  86. MEM_FREE(emsgp);
  87. #endif /* NOMKTMPDIR */
  88. - (void) signal(SIGCHLD, SIG_IGN);
  89. + (void) signal(SIGCHLD, SIG_DFL);
  90. /* Become a daemon process */
  91. switch (FORK()) {
  92. @@ -3817,12 +3846,14 @@ main(int argc, char **argv)
  93. errfp = stderr;
  94. s = &status;
  95. +
  96. /* Hack: Aside from stdin, stdout, stderr, there shouldn't
  97. * be any other files open, so force-close them. This is
  98. * necessary in case xmcd was inheriting any open file
  99. * descriptors from a parent process which is for the
  100. * CD-ROM device, and violating exclusive-open requirements
  101. * on some platforms.
  102. + * thomas@suse.de: not necessary anymore on modern systems
  103. */
  104. for (i = 3; i < 10; i++)
  105. (void) close(i);
  106. @@ -3941,7 +3972,7 @@ main(int argc, char **argv)
  107. if (remote > 0)
  108. app_data.cddb_rmtdsbl = (remote == 1) ? FALSE : TRUE;
  109. (void) strcpy(cddb_cldata.prog, PROGNAME);
  110. - (void) strcpy(cddb_cldata.user, util_loginname());
  111. + (void) strcpy(cddb_cldata.user, util_loginname()); /* bufferoverflow with orig. code here thomas@suse.de */
  112. cddb_cldata.isdemo = di_isdemo;
  113. cddb_cldata.curstat_addr = curstat_addr;
  114. cddb_cldata.fatal_msg = cda_fatal_msg;
  115. @@ -3981,24 +4012,30 @@ main(int argc, char **argv)
  116. cda_parse_devlist(s);
  117. /* Open FIFOs - command side */
  118. - if ((cda_sfd[1] = open(spipe, O_WRONLY)) < 0) {
  119. + if ((cda_sfd[1] = open(spipe, O_WRONLY | O_NOFOLLOW)) < 0) {
  120. perror("CD audio: cannot open send pipe");
  121. CDA_FATAL(
  122. "Run \"cda on\" first to initialize CD audio daemon."
  123. );
  124. }
  125. - if ((cda_rfd[1] = open(rpipe, O_RDONLY)) < 0) {
  126. + if ((cda_rfd[1] = open(rpipe, O_RDONLY | O_NOFOLLOW)) < 0) {
  127. perror("CD audio: cannot open recv pipe for reading");
  128. CDA_FATAL(
  129. "Run \"cda on\" first to initialize CD audio daemon."
  130. );
  131. }
  132. - if ((cda_rfd[0] = open(rpipe, O_WRONLY)) < 0) {
  133. + if ((cda_rfd[0] = open(rpipe, O_WRONLY | O_NOFOLLOW)) < 0) {
  134. perror("CD audio: cannot open recv pipe for writing");
  135. CDA_FATAL(
  136. "Run \"cda on\" first to initialize CD audio daemon."
  137. );
  138. }
  139. +
  140. + /* Check FIFOs */
  141. + if (stat(spipe, &stbuf) < 0 || !S_ISFIFO(stbuf.st_mode))
  142. + CDA_FATAL("Send pipe error");
  143. + if (stat(rpipe, &stbuf) < 0 || !S_ISFIFO(stbuf.st_mode))
  144. + CDA_FATAL("Receive pipe error");
  145. /* Handle some signals */
  146. (void) signal(SIGINT, onintr);