瀏覽代碼

fix integer overflows, cosmetic changes

ambrop7 14 年之前
父節點
當前提交
ba6234e350
共有 3 個文件被更改,包括 6 次插入6 次删除
  1. 4 4
      client/FragmentProtoAssembler.c
  2. 1 1
      flow/PacketBuffer.c
  3. 1 1
      security/OTPChecker.c

+ 4 - 4
client/FragmentProtoAssembler.c

@@ -396,12 +396,12 @@ int FragmentProtoAssembler_Init (FragmentProtoAssembler *o, int input_mtu, Packe
     o->time_tolerance = num_frames;
     
     // allocate frames
-    if (!(o->frames_entries = BAllocArray(num_frames, sizeof(struct FragmentProtoAssembler_frame)))) {
+    if (!(o->frames_entries = BAllocArray(num_frames, sizeof(o->frames_entries[0])))) {
         goto fail1;
     }
     
     // allocate chunks
-    if (!(o->frames_chunks = BAllocArray2(num_frames, o->num_chunks, sizeof(struct FragmentProtoAssembler_chunk)))) {
+    if (!(o->frames_chunks = BAllocArray2(num_frames, o->num_chunks, sizeof(o->frames_chunks[0])))) {
         goto fail2;
     }
     
@@ -418,9 +418,9 @@ int FragmentProtoAssembler_Init (FragmentProtoAssembler *o, int input_mtu, Packe
     for (int i = 0; i < num_frames; i++) {
         struct FragmentProtoAssembler_frame *frame = &o->frames_entries[i];
         // set chunks array pointer
-        frame->chunks = o->frames_chunks + i * o->num_chunks;
+        frame->chunks = o->frames_chunks + (size_t)i * o->num_chunks;
         // set buffer pointer
-        frame->buffer = o->frames_buffer + i * o->output_mtu;
+        frame->buffer = o->frames_buffer + (size_t)i * o->output_mtu;
         // add to free list
         LinkedList2_Append(&o->frames_free, &frame->list_node);
     }

+ 1 - 1
flow/PacketBuffer.c

@@ -97,7 +97,7 @@ int PacketBuffer_Init (PacketBuffer *buf, PacketRecvInterface *input, PacketPass
     if (num_blocks < 0) {
         goto fail0;
     }
-    if (!(buf->buf_data = BAllocArray(num_blocks, sizeof(struct ChunkBuffer2_block)))) {
+    if (!(buf->buf_data = BAllocArray(num_blocks, sizeof(buf->buf_data[0])))) {
         goto fail0;
     }
     

+ 1 - 1
security/OTPChecker.c

@@ -184,7 +184,7 @@ int OTPChecker_Init (OTPChecker *mc, int num_otps, int cipher, int num_tables, B
     // initialize tables
     for (int i = 0; i < mc->num_tables; i++) {
         struct OTPChecker_table *table = &mc->tables[i];
-        table->entries = mc->entries + i * mc->num_entries;
+        table->entries = mc->entries + (size_t)i * mc->num_entries;
         OTPChecker_Table_Empty(mc, table);
     }