Commit 974b9bed authored by conrad's avatar conrad

oggz-chop: chase potential malloc, strdup failures

git-svn-id: http://svn.annodex.net/liboggz/trunk@3855 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent 51620137
...@@ -103,15 +103,23 @@ prepend_document_root (char * path_info) ...@@ -103,15 +103,23 @@ prepend_document_root (char * path_info)
if (path_info == NULL) return NULL; if (path_info == NULL) return NULL;
if (dr == NULL || *dr == '\0') return strdup (path_info); if (dr == NULL || *dr == '\0') {
if ((path_translated = strdup (path_info)) == NULL)
dr_len = strlen (dr); goto prepend_oom;
} else {
pt_len = dr_len + strlen(path_info) + 1; dr_len = strlen (dr);
path_translated = malloc (pt_len);
snprintf (path_translated, pt_len , "%s%s", dr, path_info); pt_len = dr_len + strlen(path_info) + 1;
if ((path_translated = malloc (pt_len)) == NULL)
goto prepend_oom;
snprintf (path_translated, pt_len , "%s%s", dr, path_info);
}
return path_translated; return path_translated;
prepend_oom:
fprintf (stderr, "oggz-chop: Out of memory");
return NULL;
} }
static int static int
......
...@@ -75,7 +75,8 @@ track_state_new (void) ...@@ -75,7 +75,8 @@ track_state_new (void)
{ {
OCTrackState * ts; OCTrackState * ts;
ts = (OCTrackState *) malloc (sizeof(*ts)); if ((ts = (OCTrackState *) malloc (sizeof(*ts))) == NULL)
return NULL;
memset (ts, 0, sizeof(*ts)); memset (ts, 0, sizeof(*ts));
...@@ -103,7 +104,8 @@ track_state_add (OggzTable * state, long serialno) ...@@ -103,7 +104,8 @@ track_state_add (OggzTable * state, long serialno)
{ {
OCTrackState * ts; OCTrackState * ts;
ts = track_state_new (); if ((ts = track_state_new ()) == NULL)
return NULL;
if (oggz_table_insert (state, serialno, ts) == ts) { if (oggz_table_insert (state, serialno, ts) == ts) {
return ts; return ts;
...@@ -146,11 +148,21 @@ _ogg_page_copy (const ogg_page * og) ...@@ -146,11 +148,21 @@ _ogg_page_copy (const ogg_page * og)
{ {
ogg_page * new_og; ogg_page * new_og;
new_og = malloc (sizeof (*og)); if ((new_og = malloc (sizeof (*og))) == NULL)
new_og->header = malloc (og->header_len); return NULL;
if ((new_og->header = malloc (og->header_len)) == NULL) {
free (new_og);
return NULL;
}
new_og->header_len = og->header_len; new_og->header_len = og->header_len;
memcpy (new_og->header, og->header, og->header_len); memcpy (new_og->header, og->header, og->header_len);
new_og->body = malloc (og->body_len);
if ((new_og->body = malloc (og->body_len)) == NULL) {
free (new_og->header);
free (new_og);
return NULL;
}
new_og->body_len = og->body_len; new_og->body_len = og->body_len;
memcpy (new_og->body, og->body, og->body_len); memcpy (new_og->body, og->body, og->body_len);
...@@ -201,8 +213,14 @@ page_accum_new (const ogg_page * og, double time) ...@@ -201,8 +213,14 @@ page_accum_new (const ogg_page * og, double time)
{ {
OCPageAccum * pa; OCPageAccum * pa;
pa = malloc(sizeof (*pa)); if ((pa = malloc(sizeof (*pa))) == NULL)
pa->og = _ogg_page_copy (og); return NULL;
if ((pa->og = _ogg_page_copy (og)) == NULL) {
free (pa);
return NULL;
}
pa->time = time; pa->time = time;
return pa; return pa;
...@@ -359,7 +377,9 @@ fisbone_init (OGGZ * oggz, OCState * state, OCTrackState * ts, long serialno) ...@@ -359,7 +377,9 @@ fisbone_init (OGGZ * oggz, OCState * state, OCTrackState * ts, long serialno)
content_type = oggz_stream_get_content (oggz, serialno); content_type = oggz_stream_get_content (oggz, serialno);
name = type_names[content_type]; name = type_names[content_type];
len = snprintf (NULL, 0, CONTENT_TYPE_FMT, name); len = snprintf (NULL, 0, CONTENT_TYPE_FMT, name);
ts->fisbone.message_header_fields = malloc(len+1); if ((ts->fisbone.message_header_fields = malloc(len+1)) == NULL) {
return -1;
}
snprintf (ts->fisbone.message_header_fields, len+1, CONTENT_TYPE_FMT, name); snprintf (ts->fisbone.message_header_fields, len+1, CONTENT_TYPE_FMT, name);
ts->fisbone.current_header_size = len+1; ts->fisbone.current_header_size = len+1;
} }
...@@ -717,8 +737,14 @@ read_bos (OGGZ * oggz, const ogg_page * og, long serialno, void * user_data) ...@@ -717,8 +737,14 @@ read_bos (OGGZ * oggz, const ogg_page * og, long serialno, void * user_data)
fishead_update (state, og); fishead_update (state, og);
} }
} else { } else {
ts = track_state_add (state->tracks, serialno); if ((ts = track_state_add (state->tracks, serialno)) == NULL) {
fisbone_init (oggz, state, ts, serialno); /* Out of memory */
return OGGZ_STOP_ERR;
}
if (fisbone_init (oggz, state, ts, serialno) == -1) {
/* Out of memory */
return OGGZ_STOP_ERR;
}
ts->headers_remaining = ts->fisbone.nr_header_packet; ts->headers_remaining = ts->fisbone.nr_header_packet;
} }
......
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