Commit 536d2a56 authored by conrad's avatar conrad

port comment_decode out of memory checks from libfishsound r3851

git-svn-id: http://svn.annodex.net/liboggz/trunk@3898 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent 86a08b8b
...@@ -173,12 +173,23 @@ oggz_comment_new (const char * name, const char * value) ...@@ -173,12 +173,23 @@ oggz_comment_new (const char * name, const char * value)
OggzComment * comment; OggzComment * comment;
if (!oggz_comment_validate_byname (name, value)) return NULL; if (!oggz_comment_validate_byname (name, value)) return NULL;
/* Ensures that name != NULL, value != NULL, and validates strings */
comment = oggz_malloc (sizeof (OggzComment)); comment = oggz_malloc (sizeof (OggzComment));
if (comment == NULL) return NULL; if (comment == NULL) return NULL;
comment->name = oggz_strdup (name); comment->name = oggz_strdup (name);
if (comment->name == NULL) {
oggz_free (comment);
return NULL;
}
comment->value = oggz_strdup (value); comment->value = oggz_strdup (value);
if (comment->value == NULL) {
oggz_free (comment->name);
oggz_free (comment);
return NULL;
}
return comment; return comment;
} }
...@@ -217,7 +228,8 @@ _oggz_comment_set_vendor (OGGZ * oggz, long serialno, ...@@ -217,7 +228,8 @@ _oggz_comment_set_vendor (OGGZ * oggz, long serialno,
if (stream->vendor) oggz_free (stream->vendor); if (stream->vendor) oggz_free (stream->vendor);
stream->vendor = oggz_strdup (vendor_string); if ((stream->vendor = oggz_strdup (vendor_string)) == NULL)
return OGGZ_ERR_OUT_OF_MEMORY;
return 0; return 0;
} }
...@@ -364,9 +376,11 @@ oggz_comment_add (OGGZ * oggz, long serialno, const OggzComment * comment) ...@@ -364,9 +376,11 @@ oggz_comment_add (OGGZ * oggz, long serialno, const OggzComment * comment)
if (!oggz_comment_validate_byname (comment->name, comment->value)) if (!oggz_comment_validate_byname (comment->name, comment->value))
return OGGZ_ERR_COMMENT_INVALID; return OGGZ_ERR_COMMENT_INVALID;
new_comment = oggz_comment_new (comment->name, comment->value); if ((new_comment = oggz_comment_new (comment->name, comment->value)) == NULL)
return OGGZ_ERR_OUT_OF_MEMORY;
_oggz_comment_add (stream, new_comment); if (_oggz_comment_add (stream, new_comment) == NULL)
return OGGZ_ERR_OUT_OF_MEMORY;
return 0; return 0;
} else { } else {
...@@ -398,9 +412,11 @@ oggz_comment_add_byname (OGGZ * oggz, long serialno, ...@@ -398,9 +412,11 @@ oggz_comment_add_byname (OGGZ * oggz, long serialno,
if (!oggz_comment_validate_byname (name, value)) if (!oggz_comment_validate_byname (name, value))
return OGGZ_ERR_COMMENT_INVALID; return OGGZ_ERR_COMMENT_INVALID;
new_comment = oggz_comment_new (name, value); if ((new_comment = oggz_comment_new (name, value)) == NULL)
return OGGZ_ERR_OUT_OF_MEMORY;
_oggz_comment_add (stream, new_comment); if (_oggz_comment_add (stream, new_comment) == NULL)
return OGGZ_ERR_OUT_OF_MEMORY;
return 0; return 0;
} else { } else {
...@@ -550,10 +566,16 @@ oggz_comments_decode (OGGZ * oggz, long serialno, ...@@ -550,10 +566,16 @@ oggz_comments_decode (OGGZ * oggz, long serialno,
if (stream == NULL) return OGGZ_ERR_BAD_SERIALNO; if (stream == NULL) return OGGZ_ERR_BAD_SERIALNO;
/* Vendor */ /* Vendor */
nvalue = oggz_strdup_len (c, len); if (len > 0) {
if (!nvalue) return -1; if ((nvalue = oggz_strdup_len (c, len)) == NULL)
_oggz_comment_set_vendor (oggz, serialno, nvalue); return OGGZ_ERR_OUT_OF_MEMORY;
if (nvalue) oggz_free (nvalue);
if (_oggz_comment_set_vendor (oggz, serialno, nvalue) == OGGZ_ERR_OUT_OF_MEMORY)
return OGGZ_ERR_OUT_OF_MEMORY;
oggz_free (nvalue);
}
#ifdef DEBUG #ifdef DEBUG
fwrite(c, 1, len, stderr); fputc ('\n', stderr); fwrite(c, 1, len, stderr); fputc ('\n', stderr);
#endif #endif
...@@ -580,18 +602,30 @@ oggz_comments_decode (OGGZ * oggz, long serialno, ...@@ -580,18 +602,30 @@ oggz_comments_decode (OGGZ * oggz, long serialno,
value++; value++;
n = c+len - value; n = c+len - value;
nvalue = oggz_strdup_len (value, n); if ((nvalue = oggz_strdup_len (value, n)) == NULL)
return OGGZ_ERR_OUT_OF_MEMORY;
#ifdef DEBUG #ifdef DEBUG
printf ("oggz_comments_decode: %s -> %s (length %d)\n", printf ("oggz_comments_decode: %s -> %s (length %d)\n",
name, nvalue, n); name, nvalue, n);
#endif #endif
comment = oggz_comment_new (name, nvalue); if ((comment = oggz_comment_new (name, nvalue)) == NULL)
_oggz_comment_add (stream, comment); return OGGZ_ERR_OUT_OF_MEMORY;
if (_oggz_comment_add (stream, comment) == NULL)
return OGGZ_ERR_OUT_OF_MEMORY;
oggz_free (nvalue); oggz_free (nvalue);
} else { } else {
nvalue = oggz_strdup_len (name, len); if ((nvalue = oggz_strdup_len (name, len)) == NULL)
comment = oggz_comment_new (nvalue, NULL); return OGGZ_ERR_OUT_OF_MEMORY;
_oggz_comment_add (stream, comment);
if ((comment = oggz_comment_new (nvalue, NULL)) == NULL)
return OGGZ_ERR_OUT_OF_MEMORY;
if (_oggz_comment_add (stream, comment) == NULL)
return OGGZ_ERR_OUT_OF_MEMORY;
oggz_free (nvalue); oggz_free (nvalue);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment