summaryrefslogtreecommitdiff
path: root/audio/mserv/patches/patch-ae
blob: 901d5664b025f30c843cc6328350d37f12fb3ae0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
$NetBSD: patch-ae,v 1.8 2004/02/20 00:41:16 abs Exp $

--- mserv/mp3info.c.orig	Thu Feb 19 17:46:03 2004
+++ mserv/mp3info.c
@@ -27,6 +27,7 @@
 #define h_thing(val)          ((val>>20)&0xfff)
 
 #define ID3V2HEADERLEN		10
+#define min(x,y)		((x)<(y)?(x):(y))
 
 /* mp3 bit rate and sampling frequency tables */
 
@@ -45,12 +46,14 @@ const int sampling_freq_table[2][3] =
 /* structure of id3 tag in mp3 file */
 
 typedef struct id3tag_disc_str
-{
-  char title[MP3ID3_TITLELEN];
-  char artist[MP3ID3_ARTISTLEN];
-  char album[MP3ID3_ALBUMLEN];
-  char year[MP3ID3_YEARLEN];
-  char comment[MP3ID3_COMMENTLEN];
+{	/* These are all fixed lengths.
+	 * Avoid #define'd lengths that get get redefined for other uses
+	 */
+  char title[30];
+  char artist[30];
+  char album[30];
+  char year[4];
+  char comment[28];
   unsigned char genre;
 } id3tag_disc;
 
@@ -312,38 +315,44 @@ int mserv_mp3info_readlen(const char *fn
     if (id3tag)
     {
       id3tag_disc tag_disc;
+      int	len;
 
       if (fread(&tag_disc, 1, 125, f) != 125)
  	goto error;
       
       id3tag->present = 1;
 
-      memcpy(id3tag->title, tag_disc.title, MP3ID3_TITLELEN);
-      id3tag->title[MP3ID3_TITLELEN] = '\0';
+      len = min(MP3ID3_TITLELEN, sizeof(tag_disc.title));
+      memcpy(id3tag->title, tag_disc.title, len);
+      id3tag->title[len] = '\0';
       e = id3tag->title + strlen(id3tag->title);
       while (e > id3tag->title && *(e-1) == ' ')
 	*--e = '\0';
       
-      memcpy(id3tag->artist, tag_disc.artist, MP3ID3_ARTISTLEN);
-      id3tag->artist[MP3ID3_ARTISTLEN] = '\0';
+      len = min(MP3ID3_ARTISTLEN, sizeof(tag_disc.artist));
+      memcpy(id3tag->artist, tag_disc.artist, len);
+      id3tag->artist[len] = '\0';
       e = id3tag->artist + strlen(id3tag->artist);
       while (e > id3tag->artist && *(e-1) == ' ')
 	*--e = '\0';
 
-      memcpy(id3tag->album, tag_disc.album, MP3ID3_ALBUMLEN);
-      id3tag->album[MP3ID3_ALBUMLEN] = '\0';
+      len = min(MP3ID3_ALBUMLEN, sizeof(tag_disc.album));
+      memcpy(id3tag->album, tag_disc.album, len);
+      id3tag->album[len] = '\0';
       e = id3tag->album + strlen(id3tag->album);
       while (e > id3tag->album && *(e-1) == ' ')
 	*--e = '\0';
 
-      memcpy(id3tag->year, tag_disc.year, MP3ID3_YEARLEN);
-      id3tag->year[MP3ID3_YEARLEN] = '\0';
+      len = min(MP3ID3_YEARLEN, sizeof(tag_disc.year));
+      memcpy(id3tag->year, tag_disc.year, len);
+      id3tag->year[len] = '\0';
       e = id3tag->year + strlen(id3tag->year);
       while (e > id3tag->year && *(e-1) == ' ')
 	*--e = '\0';
       
-      memcpy(id3tag->comment, tag_disc.comment, MP3ID3_COMMENTLEN);
-      id3tag->comment[MP3ID3_COMMENTLEN] = '\0';
+      len = min(MP3ID3_COMMENTLEN, sizeof(tag_disc.comment));
+      memcpy(id3tag->comment, tag_disc.comment, len);
+      id3tag->comment[len] = '\0';
       e = id3tag->comment + strlen(id3tag->comment);
       while (e > id3tag->comment && *(e-1) == ' ')
 	*--e = '\0';