patch-cddb_c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. $OpenBSD: patch-cddb_c,v 1.1.1.1 2001/02/06 11:50:22 wilfried Exp $
  2. --- cddb.c.orig Thu May 27 08:37:10 1999
  3. +++ cddb.c Mon Feb 5 08:54:06 2001
  4. @@ -73,10 +73,10 @@ void
  5. cddb_cur2struct(void)
  6. {
  7. cddb.protocol = cur_cddb_protocol;
  8. - strcpy(cddb.cddb_server, cur_cddb_server);
  9. - strcpy(cddb.mail_adress, cur_cddb_mail_adress);
  10. - strcpy(cddb.path_to_cgi, cur_cddb_path_to_cgi);
  11. - strcpy(cddb.proxy_server, cur_cddb_proxy_server);
  12. + strlcpy(cddb.cddb_server, cur_cddb_server, sizeof(cddb.cddb_server));
  13. + strlcpy(cddb.mail_adress, cur_cddb_mail_adress, sizeof(cddb.mail_adress));
  14. + strlcpy(cddb.path_to_cgi, cur_cddb_path_to_cgi, sizeof(cddb.path_to_cgi));
  15. + strlcpy(cddb.proxy_server, cur_cddb_proxy_server, sizeof(cddb.proxy_server));
  16. } /* cddb_cur2struct() */
  17. /*
  18. @@ -104,7 +104,7 @@ cddb_sum(int n)
  19. int ret = 0;
  20. /* For backward compatibility this algorithm must not change */
  21. - sprintf(buf, "%lu", (unsigned long)n);
  22. + snprintf(buf, sizeof(buf), "%lu", (unsigned long)n);
  23. for (p = buf; *p != '\0'; p++)
  24. ret += (*p - '0');
  25. @@ -175,10 +175,10 @@ string_makehello(char *line,char delim)
  26. {
  27. char mail[84],*host;
  28. - strcpy(mail,cddb.mail_adress);
  29. + strlcpy(mail,cddb.mail_adress,sizeof(mail));
  30. host=string_split(mail,'@');
  31. - sprintf(line,"%shello%c%s%c%s%c%s%c%s",
  32. + snprintf(line, sizeof(line), "%shello%c%s%c%s%c%s%c%s",
  33. delim == ' ' ? "cddb " : "&",
  34. delim == ' ' ? ' ' : '=',
  35. mail,delim,
  36. @@ -226,7 +226,7 @@ connect_open(void)
  37. printf("unknown host: %s\n", host);
  38. return (-1);
  39. }
  40. - strcpy(namebuf, host);
  41. + strlcpy(namebuf, host, sizeof(namebuf));
  42. def.h_name = namebuf;
  43. def.h_addr_list = alist, def.h_addr = (char *)&defaddr;
  44. def.h_length = sizeof (struct in_addr);
  45. @@ -317,14 +317,14 @@ connect_read_entry(void)
  46. t2 = t;
  47. if(*t2 == ' ')
  48. t2++;
  49. - strcpy(cd->cdname,t2);
  50. + strlcpy(cd->cdname,t2,sizeof(cd->cdname));
  51. for(t2=t;*t2;t2++)
  52. {
  53. if((*t2 == ' ') && (*(t2+1) == 0))
  54. *t2=0;
  55. }
  56. - strcpy(cd->artist,t);
  57. + strlcpy(cd->artist,t,sizeof(cd->artist));
  58. }
  59. if('T' == type)
  60. @@ -359,7 +359,7 @@ void
  61. cddbp_read(char *category, unsigned int id)
  62. {
  63. char tempbuf[84];
  64. - sprintf(tempbuf, "cddb read %s %08x", category, id);
  65. + snprintf(tempbuf, sizeof(tempbuf), "cddb read %s %08x", category, id);
  66. cddbp_send(tempbuf);
  67. } /* cddbp_read() */
  68. @@ -400,7 +400,7 @@ void
  69. http_read(char *category, unsigned int id)
  70. {
  71. char tempbuf[84];
  72. - sprintf(tempbuf, "cddb+read+%s+%08x", category, id);
  73. + snprintf(tempbuf, sizeof(tempbuf), "cddb+read+%s+%08x", category, id);
  74. http_send(tempbuf);
  75. } /* http_read() */
  76. @@ -411,7 +411,7 @@ void
  77. cddb_request(void)
  78. {
  79. int i;
  80. - char tempbuf[2000];
  81. + char tempbuf[2000], tmp2buf[12];
  82. extern int cur_ntracks;
  83. int status;
  84. @@ -447,12 +447,14 @@ cddb_request(void)
  85. printf("[%s]\n",tempbuf);
  86. printf("query\n");
  87. - sprintf(tempbuf, "cddb query %08x %d",thiscd.cddbid,thiscd.ntracks);
  88. + snprintf(tempbuf, sizeof(tempbuf), "cddb query %08x %d",thiscd.cddbid,thiscd.ntracks);
  89. for (i = 0; i < cur_ntracks; i++)
  90. - if (thiscd.trk[i].section < 2)
  91. - sprintf(tempbuf + strlen(tempbuf), " %d",
  92. - thiscd.trk[i].start);
  93. - sprintf(tempbuf + strlen(tempbuf), " %d\n", thiscd.length);
  94. + if (thiscd.trk[i].section < 2) {
  95. + snprintf(tmp2buf, sizeof(tmp2buf), " %d", thiscd.trk[i].start);
  96. + strlcat(tempbuf, tmp2buf, sizeof(tempbuf));
  97. + }
  98. + snprintf(tmp2buf, sizeof(tmp2buf), " %d\n", thiscd.length);
  99. + strlcat(tempbuf, tmp2buf, sizeof(tempbuf));
  100. printf(">%s<\n",tempbuf);
  101. cddbp_send(tempbuf);
  102. connect_getline(tempbuf);
  103. @@ -491,12 +493,14 @@ cddb_request(void)
  104. printf("USING HTTP%s\n",
  105. (cddb.protocol == 3) ? " WITH PROXY" : "");
  106. printf("query\n");
  107. - sprintf(tempbuf, "cddb+query+%08x+%d",thiscd.cddbid,thiscd.ntracks);
  108. + snprintf(tempbuf, sizeof(tempbuf), "cddb+query+%08x+%d",thiscd.cddbid,thiscd.ntracks);
  109. for (i = 0; i < cur_ntracks; i++)
  110. - if (thiscd.trk[i].section < 2)
  111. - sprintf(tempbuf + strlen(tempbuf), "+%d",
  112. - thiscd.trk[i].start);
  113. - sprintf(tempbuf + strlen(tempbuf), "+%d", thiscd.length);
  114. + if (thiscd.trk[i].section < 2) {
  115. + snprintf(tmp2buf, sizeof(tmp2buf), "+%d", thiscd.trk[i].start);
  116. + strlcat(tempbuf, tmp2buf, sizeof(tempbuf));
  117. + }
  118. + snprintf(tmp2buf, sizeof(tmp2buf), "+%d", thiscd.length);
  119. + strlcat(tempbuf, tmp2buf, sizeof(tempbuf));
  120. printf(">%s<\n",tempbuf);
  121. connect_open();
  122. http_send(tempbuf);