From: Tilman Sauerbeck Date: Fri, 11 Aug 2006 13:34:19 +0000 (+0200) Subject: Made sure that all comments are well-formed before they are parsed. X-Git-Url: http://git.code-monkey.de/?p=ruby-vorbistagger.git;a=commitdiff_plain;h=3a85c62f63ed1f727432ccab1dd46bfd7fd78404 Made sure that all comments are well-formed before they are parsed. ie, check that every comment has a '=' sign somewhere, but not at position 0. --- diff --git a/ext/ext.c b/ext/ext.c index d8bcc12..4794d28 100644 --- a/ext/ext.c +++ b/ext/ext.c @@ -130,7 +130,7 @@ c_init (VALUE self, VALUE io) { RbVorbisTagger *o; vorbis_comment *vc; - int s; + int s, i; Data_Get_Struct (self, RbVorbisTagger, o); @@ -165,6 +165,15 @@ c_init (VALUE self, VALUE io) rb_raise (eVTError, "vcedit_comments() failed - %s", vcedit_error (o->state)); + /* check whether all comments are well-formed */ + for (i = 0; i < vc->comments; i++) { + char *ptr, *content = vc->user_comments[i]; + + ptr = strchr (content, '='); + if (!ptr || ptr == content) + rb_raise (eVTError, "malformed comment - %s", content); + } + o->comments = rb_class_new_instance (0, NULL, cComments); comments_init (o->comments, o->state);