patch-database_c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. $OpenBSD: patch-database_c,v 1.1.1.1 2001/02/06 11:50:24 wilfried Exp $
  2. --- database.c.orig Fri May 28 05:35:54 1999
  3. +++ database.c Mon Feb 5 08:58:29 2001
  4. @@ -121,8 +121,8 @@ nomem:
  5. exit(1);
  6. }
  7. - strcpy(rcfile, home);
  8. - strcat(rcfile, RCFILE);
  9. + strlcpy(rcfile, home, sizeof(rcfile));
  10. + strlcat(rcfile, RCFILE, sizeof(rcfile));
  11. }
  12. else
  13. no_rc = 1;
  14. @@ -141,8 +141,8 @@ nomem:
  15. if (databases == NULL)
  16. goto nomem;
  17. - strcpy(wmdb, home);
  18. - strcat(wmdb, DBFILE);
  19. + strlcpy(wmdb, home, sizeof(wmdb));
  20. + strlcat(wmdb, DBFILE, sizeof(wmdb));
  21. databases[0] = wmdb;
  22. databases[1] = NULL;
  23. }
  24. @@ -214,27 +214,31 @@ print_cdinfo(struct wm_cdinfo *cd, int p
  25. {
  26. int i;
  27. char tempbuf[2000]; /* XXX - is this always big enough? */
  28. + char tmp2buf[12];
  29. static char *cdibuf = NULL;
  30. struct wm_playlist *l;
  31. - sprintf(tempbuf, "\ntracks %d", cd->ntracks);
  32. + snprintf(tempbuf, sizeof(tempbuf), "\ntracks %d", cd->ntracks);
  33. for (i = 0; i < cur_ntracks; i++)
  34. - if (cd->trk[i].section < 2)
  35. - sprintf(tempbuf + strlen(tempbuf), " %d",
  36. - cd->trk[i].start);
  37. - sprintf(tempbuf + strlen(tempbuf), " %d\n", cd->length);
  38. + if (cd->trk[i].section < 2) {
  39. + snprintf(tmp2buf, sizeof(tmp2buf), " %d", cd->trk[i].start);
  40. + strlcat(tempbuf, tmp2buf, sizeof(tempbuf));
  41. + }
  42. + snprintf(tmp2buf, sizeof(tmp2buf), " %d\n", cd->length);
  43. + strlcat(tempbuf, tmp2buf, sizeof(tempbuf));
  44. wm_strmcpy(&cdibuf, tempbuf);
  45. if (cur_nsections)
  46. {
  47. - sprintf(tempbuf, "sections %d", cur_nsections);
  48. + snprintf(tempbuf, sizeof(tempbuf), "sections %d", cur_nsections);
  49. /* fixed a bug here */
  50. for (i = 0; i < cur_ntracks; i++)
  51. - if (cd->trk[i].section > 1)
  52. - sprintf(tempbuf + strlen(tempbuf), " %d",
  53. - cd->trk[i].start);
  54. - sprintf(tempbuf + strlen(tempbuf), "\n");
  55. + if (cd->trk[i].section > 1) {
  56. + snprintf(tmp2buf, sizeof(tmp2buf), " %d", cd->trk[i].start);
  57. + strlcat(tempbuf, tmp2buf, sizeof(tempbuf));
  58. + }
  59. + strlcat(tempbuf, "\n", sizeof(tempbuf));
  60. wm_strmcat(&cdibuf, tempbuf);
  61. }
  62. @@ -257,11 +261,11 @@ print_cdinfo(struct wm_cdinfo *cd, int p
  63. {
  64. for (i = 0; l->list[i]; i++)
  65. ;
  66. - sprintf(tempbuf, " %d", i);
  67. + snprintf(tempbuf, sizeof(tempbuf), " %d", i);
  68. wm_strmcat(&cdibuf, tempbuf);
  69. for (i = 0; l->list[i]; i++)
  70. {
  71. - sprintf(tempbuf, " %d", l->list[i]);
  72. + snprintf(tempbuf, sizeof(tempbuf), " %d", l->list[i]);
  73. wm_strmcat(&cdibuf, tempbuf);
  74. }
  75. wm_strmcat(&cdibuf, "\n");
  76. @@ -276,24 +280,24 @@ print_cdinfo(struct wm_cdinfo *cd, int p
  77. * Have to maintain compatibility with old versions,
  78. * where volume was 0-32.
  79. */
  80. - sprintf(tempbuf, "cdvolume %d\n", (cd->volume * 32) / 100);
  81. + snprintf(tempbuf, sizeof(tempbuf), "cdvolume %d\n", (cd->volume * 32) / 100);
  82. wm_strmcat(&cdibuf, tempbuf);
  83. }
  84. if (cd->playmode)
  85. {
  86. - sprintf(tempbuf, "playmode %d\n", cd->playmode);
  87. + snprintf(tempbuf, sizeof(tempbuf), "playmode %d\n", cd->playmode);
  88. wm_strmcat(&cdibuf, tempbuf);
  89. }
  90. if (mark_a)
  91. {
  92. - sprintf(tempbuf, "mark %d START\n", mark_a);
  93. + snprintf(tempbuf, sizeof(tempbuf), "mark %d START\n", mark_a);
  94. wm_strmcat(&cdibuf, tempbuf);
  95. }
  96. if (mark_b)
  97. {
  98. - sprintf(tempbuf, "mark %d END\n", mark_b);
  99. + snprintf(tempbuf, sizeof(tempbuf), "mark %d END\n", mark_b);
  100. wm_strmcat(&cdibuf, tempbuf);
  101. }
  102. @@ -304,12 +308,12 @@ print_cdinfo(struct wm_cdinfo *cd, int p
  103. {
  104. if (cd->trk[i].avoid)
  105. {
  106. - sprintf(tempbuf, "dontplay %d\n", i + 1);
  107. + snprintf(tempbuf, sizeof(tempbuf), "dontplay %d\n", i + 1);
  108. wm_strmcat(&cdibuf, tempbuf);
  109. }
  110. if (cd->trk[i].volume)
  111. {
  112. - sprintf(tempbuf, "volume %d %d\n", i + 1,
  113. + snprintf(tempbuf, sizeof(tempbuf), "volume %d %d\n", i + 1,
  114. (cd->trk[i].volume * 32) / 100);
  115. wm_strmcat(&cdibuf, tempbuf);
  116. }
  117. @@ -852,7 +856,7 @@ chomp:
  118. if (searching > 1)
  119. {
  120. strcpy(cd->cdname, "Probably://");
  121. - fgets(cd->cdname + strlen(cd->cdname), sizeof(cd->cdname), fp);
  122. + fgets(cd->cdname + strlen(cd->cdname), sizeof(cd->cdname)-strlen(cd->cdname), fp);
  123. }
  124. else
  125. {
  126. @@ -1226,17 +1230,17 @@ save_globals(FILE *fp)
  127. if (cddb.protocol)
  128. {
  129. - sprintf(temp, "cddbprotocol ");
  130. + snprintf(temp, sizeof(temp), "cddbprotocol ");
  131. switch(cddb.protocol)
  132. {
  133. case 1: /* cddbp */
  134. - sprintf(temp + strlen(temp), "cddbp\n");
  135. + strlcat(temp, "cddbp\n", sizeof(temp));
  136. break;
  137. case 2: /* http */
  138. - sprintf(temp + strlen(temp), "http\n");
  139. + strlcat(temp, "http\n", sizeof(temp));
  140. break;
  141. case 3: /* proxy */
  142. - sprintf(temp + strlen(temp), "proxy\n");
  143. + strlcat(temp, "proxy\n", sizeof(temp));
  144. break;
  145. default:
  146. break;
  147. @@ -1245,28 +1249,28 @@ save_globals(FILE *fp)
  148. if(cddb.mail_adress[0])
  149. {
  150. - sprintf(temp,"cddbmailadress %s\n",
  151. + snprintf(temp,sizeof(temp),"cddbmailadress %s\n",
  152. cddb.mail_adress);
  153. wm_strmcat(&globes, temp);
  154. }
  155. if(cddb.cddb_server[0])
  156. {
  157. - sprintf(temp,"cddbserver %s\n",
  158. + snprintf(temp,sizeof(temp),"cddbserver %s\n",
  159. cddb.cddb_server);
  160. wm_strmcat(&globes, temp);
  161. }
  162. if(cddb.path_to_cgi[0])
  163. {
  164. - sprintf(temp,"cddbpathtocgi %s\n",
  165. + snprintf(temp,sizeof(temp),"cddbpathtocgi %s\n",
  166. cddb.mail_adress);
  167. wm_strmcat(&globes, temp);
  168. }
  169. if(cddb.proxy_server[0])
  170. {
  171. - sprintf(temp,"cddbproxy %s\n",
  172. + snprintf(temp,sizeof(temp),"cddbproxy %s\n",
  173. cddb.mail_adress);
  174. wm_strmcat(&globes, temp);
  175. }
  176. @@ -1274,7 +1278,7 @@ save_globals(FILE *fp)
  177. if (cur_stopmode == 1 || cur_stopmode == 2)
  178. {
  179. - sprintf(temp, "whendone %s\n", cur_stopmode == 1 ? "repeat" :
  180. + snprintf(temp, sizeof(temp), "whendone %s\n", cur_stopmode == 1 ? "repeat" :
  181. "eject");
  182. wm_strmcat(&globes, temp);
  183. }