[xiph-cvs] cvs commit: vorbis-tools/ogg123 oggvorbis_format.c

Segher Boessenkool segher at xiph.org
Thu May 2 18:20:54 PDT 2002



segher      02/05/02 18:20:54

  Modified:    ogg123   oggvorbis_format.c
  Log:
  Fix several "tag prettyprinting" bugs:
  
  - Duplicate TRACKNUMBER removed.
  - Tags starting with = display correctly now, instead of
    displaying a random piece of memory.
  - UTF8 decoding wasn't performed for unrecognized tags.
  - We almost would have had our first security problem.
    Never get printf format strings from anything other than
    const strings; certainly not from tag names!

Revision  Changes    Path
1.8       +25 -23    vorbis-tools/ogg123/oggvorbis_format.c

Index: oggvorbis_format.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/oggvorbis_format.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- oggvorbis_format.c	2002/04/10 02:40:42	1.7
+++ oggvorbis_format.c	2002/05/03 01:20:53	1.8
@@ -11,12 +11,13 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: oggvorbis_format.c,v 1.7 2002/04/10 02:40:42 volsung Exp $
+ last mod: $Id: oggvorbis_format.c,v 1.8 2002/05/03 01:20:53 segher Exp $
 
  ********************************************************************/
 
 #include <stdlib.h>
 #include <string.h>
+#include <ctype.h>
 #include <ogg/ogg.h>
 #include <vorbis/codec.h>
 #include <vorbis/vorbisfile.h>
@@ -47,18 +48,18 @@
   char *key;         /* includes the '=' for programming convenience */
   char *formatstr;   /* formatted output */
 } vorbis_comment_keys[] = {
-  {"TRACKNUMBER=", N_("Track number: %s")},
-  {"RG_RADIO=", N_("ReplayGain (Track): %s")},
-  {"RG_AUDIOPHILE=", N_("ReplayGain (Album): %s")},
-  {"RG_PEAK=", N_("ReplayGain Peak: %s")},
-  {"TRACKNUMBER=", N_("Track number: %s")},  
-  {"COPYRIGHT=", N_("Copyright %s")},
-  {NULL, N_("Comment: %s")}
+  {"TRACKNUMBER=", N_("Track number:")},
+  {"RG_RADIO=", N_("ReplayGain (Track):")},
+  {"RG_AUDIOPHILE=", N_("ReplayGain (Album):")},
+  {"RG_PEAK=", N_("ReplayGain Peak:")},
+  {"COPYRIGHT=", N_("Copyright")},
+  {"=", N_("Comment:")},
+  {NULL, N_("Comment:")}
 };
 
 
 /* Private functions declarations */
-char *lookup_comment_formatstr (char *comment, int *offset);
+char *lookup_comment_prettyprint (char *comment, int *offset);
 void print_stream_comments (decoder_t *decoder);
 void print_stream_info (decoder_t *decoder);
 
@@ -302,7 +303,7 @@
 /* ------------------- Private functions -------------------- */
 
 
-char *lookup_comment_formatstr (char *comment, int *offset)
+char *lookup_comment_prettyprint (char *comment, int *offset)
 {
   int i, j;
   char *s;
@@ -326,26 +327,27 @@
   }
 
   /* Use default formatting */
-  *offset = 0;
-  if (i = strcspn(comment, "=")) {
-    s = malloc(strlen(comment) + 2);
+  j = strcspn(comment, "=");
+  if (j) {
+    *offset = j + 1;
+    s = malloc(j + 2);
     if (s == NULL) {
       fprintf(stderr, _("Error: Out of memory.\n"));
       exit(1);
     };
-    strncpy(s, comment, i);
-    strncpy(s + i, ": ", 2);
-    strcpy(s+i+2, comment+i+1);
+    strncpy(s, comment, j);
+    strcpy(s + j, ":");
 
     /* Capitalize */
     s[0] = toupper(s[0]);
-    for (j = 1; j < i; j++) {
-      s[j] = tolower(s[j]);
+    for (i = 1; i < j; i++) {
+      s[i] = tolower(s[i]);
     };
     return s;
   }
 
   /* Unrecognized comment, use last format string */
+  *offset = 0;
   s = malloc(strlen(vorbis_comment_keys[i].formatstr) + 1);
   if (s == NULL) {
     fprintf(stderr, _("Error: Out of memory.\n"));
@@ -360,7 +362,7 @@
 {
   ovf_private_t *priv = decoder->private;
   decoder_callbacks_t *cb = decoder->callbacks;
-  char *comment, *comment_formatstr;
+  char *comment, *comment_prettyprint;
   int offset;
   int i;
 
@@ -372,16 +374,16 @@
     char *decoded_value;
 
     comment = priv->vc->user_comments[i];
-    comment_formatstr = lookup_comment_formatstr(comment, &offset);
+    comment_prettyprint = lookup_comment_prettyprint(comment, &offset);
 
     if (utf8_decode(comment + offset, &decoded_value) >= 0) {
       cb->printf_metadata(decoder->callback_arg, 1,
-			       comment_formatstr, decoded_value);
+			       "%s %s", comment_prettyprint, decoded_value);
       free(decoded_value);
     } else
       cb->printf_metadata(decoder->callback_arg, 1,
-			       comment_formatstr, comment + offset);
-    free(comment_formatstr);
+			       "%s %s", comment_prettyprint, comment + offset);
+    free(comment_prettyprint);
   }
 }
 

<p><p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list