~ubuntu-branches/ubuntu/quantal/flac/quantal

« back to all changes in this revision

Viewing changes to src/metaflac/options.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-12-06 16:57:20 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20071206165720-ldii5tm8dq6zxg0l
Tags: 1.2.1-1ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/control: xmms-dev dropped to allow xmms to move to universe,
    adjust maintainer field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include "usage.h"
25
25
#include "utils.h"
26
26
#include "FLAC/assert.h"
 
27
#include "share/alloc.h"
27
28
#include "share/grabbag/replaygain.h"
28
29
#include <ctype.h>
29
30
#include <stdio.h>
185
186
 
186
187
        if(options->num_files > 0) {
187
188
                unsigned i = 0;
188
 
                if(0 == (options->filenames = (char**)malloc(sizeof(char*) * options->num_files)))
 
189
                if(0 == (options->filenames = (char**)safe_malloc_mul_2op_(sizeof(char*), /*times*/options->num_files)))
189
190
                        die("out of memory allocating space for file names list");
190
191
                while(share__optind < argc)
191
192
                        options->filenames[i++] = local_strdup(argv[share__optind++]);
235
236
 
236
237
        /*
237
238
         * We need to create an OP__ADD_SEEKPOINT operation if there is
238
 
         * not one already,  and --import-cuesheet-from was specified but
 
239
         * not one already, and --import-cuesheet-from was specified but
239
240
         * --no-cued-seekpoints was not:
240
241
         */
241
242
        if(options->cued_seekpoints) {
469
470
        }
470
471
        else if(0 == strcmp(opt, "set-total-samples")) {
471
472
                op = append_shorthand_operation(options, OP__SET_TOTAL_SAMPLES);
472
 
                if(!parse_uint64(option_argument, &(op->argument.streaminfo_uint64.value)) || op->argument.streaminfo_uint64.value >= (1u<<FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN)) {
 
473
                if(!parse_uint64(option_argument, &(op->argument.streaminfo_uint64.value)) || op->argument.streaminfo_uint64.value >= (((FLAC__uint64)1)<<FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN)) {
473
474
                        fprintf(stderr, "ERROR (--%s): value must be a %u-bit unsigned integer\n", opt, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN);
474
475
                        ok = false;
475
476
                }
718
719
        }
719
720
        if(options->ops.capacity <= options->ops.num_operations) {
720
721
                unsigned original_capacity = options->ops.capacity;
721
 
                options->ops.capacity *= 4;
722
 
                if(0 == (options->ops.operations = (Operation*)realloc(options->ops.operations, sizeof(Operation) * options->ops.capacity)))
 
722
                if(options->ops.capacity > SIZE_MAX / 2) /* overflow check */
 
723
                        die("out of memory allocating space for option list");
 
724
                options->ops.capacity *= 2;
 
725
                if(0 == (options->ops.operations = (Operation*)safe_realloc_mul_2op_(options->ops.operations, sizeof(Operation), /*times*/options->ops.capacity)))
723
726
                        die("out of memory allocating space for option list");
724
727
                memset(options->ops.operations + original_capacity, 0, sizeof(Operation) * (options->ops.capacity - original_capacity));
725
728
        }
737
740
        }
738
741
        if(options->args.capacity <= options->args.num_arguments) {
739
742
                unsigned original_capacity = options->args.capacity;
740
 
                options->args.capacity *= 4;
741
 
                if(0 == (options->args.arguments = (Argument*)realloc(options->args.arguments, sizeof(Argument) * options->args.capacity)))
 
743
                if(options->args.capacity > SIZE_MAX / 2) /* overflow check */
 
744
                        die("out of memory allocating space for option list");
 
745
                options->args.capacity *= 2;
 
746
                if(0 == (options->args.arguments = (Argument*)safe_realloc_mul_2op_(options->args.arguments, sizeof(Argument), /*times*/options->args.capacity)))
742
747
                        die("out of memory allocating space for option list");
743
748
                memset(options->args.arguments + original_capacity, 0, sizeof(Argument) * (options->args.capacity - original_capacity));
744
749
        }
969
974
 
970
975
        /* make space */
971
976
        FLAC__ASSERT(out->num_entries > 0);
972
 
        if(0 == (out->entries = (unsigned*)malloc(sizeof(unsigned) * out->num_entries)))
 
977
        if(0 == (out->entries = (unsigned*)safe_malloc_mul_2op_(sizeof(unsigned), /*times*/out->num_entries)))
973
978
                die("out of memory allocating space for option list");
974
979
 
975
980
        /* load 'em up */
1008
1013
 
1009
1014
        /* make space */
1010
1015
        FLAC__ASSERT(out->num_entries > 0);
1011
 
        if(0 == (out->entries = (Argument_BlockTypeEntry*)malloc(sizeof(Argument_BlockTypeEntry) * out->num_entries)))
 
1016
        if(0 == (out->entries = (Argument_BlockTypeEntry*)safe_malloc_mul_2op_(sizeof(Argument_BlockTypeEntry), /*times*/out->num_entries)))
1012
1017
                die("out of memory allocating space for option list");
1013
1018
 
1014
1019
        /* load 'em up */