Commit f1a136e0d098a4478236a1c24f9a57db5abf0755

Authored by Jesper Juhl
Committed by Linus Torvalds
1 parent 2ab1346085

[PATCH] kallsyms: handle malloc() failure

This fixes coverity bugs #398 and #397

Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

Showing 1 changed file with 11 additions and 1 deletions Side-by-side Diff

... ... @@ -124,6 +124,11 @@
124 124 * compressed together */
125 125 s->len = strlen(str) + 1;
126 126 s->sym = malloc(s->len + 1);
  127 + if (!s->sym) {
  128 + fprintf(stderr, "kallsyms failure: "
  129 + "unable to allocate required amount of memory\n");
  130 + exit(EXIT_FAILURE);
  131 + }
127 132 strcpy((char *)s->sym + 1, str);
128 133 s->sym[0] = stype;
129 134  
... ... @@ -272,7 +277,12 @@
272 277  
273 278 /* table of offset markers, that give the offset in the compressed stream
274 279 * every 256 symbols */
275   - markers = (unsigned int *) malloc(sizeof(unsigned int) * ((table_cnt + 255) / 256));
  280 + markers = malloc(sizeof(unsigned int) * ((table_cnt + 255) / 256));
  281 + if (!markers) {
  282 + fprintf(stderr, "kallsyms failure: "
  283 + "unable to allocate required memory\n");
  284 + exit(EXIT_FAILURE);
  285 + }
276 286  
277 287 output_label("kallsyms_names");
278 288 off = 0;