Просмотр исходного кода

client: check device MTU before DPReceiveDevice_Init to avoid assertion failure if the MTU is too large

ambrop7 14 лет назад
Родитель
Сommit
0c4deb8ae0
1 измененных файлов с 7 добавлено и 8 удалено
  1. 7 8
      client/client.c

+ 7 - 8
client/client.c

@@ -485,6 +485,13 @@ int main (int argc, char *argv[])
     
     BLog(BLOG_INFO, "device MTU is %d", device_mtu);
     
+    // calculate data MTU
+    if (device_mtu > INT_MAX - DATAPROTO_MAX_OVERHEAD) {
+        BLog(BLOG_ERROR, "Device MTU is too large");
+        goto fail7;
+    }
+    data_mtu = DATAPROTO_MAX_OVERHEAD + device_mtu;
+    
     // init device input
     if (!DataProtoSource_Init(&device_input_dpd, BTap_GetOutput(&device), device_input_dpd_handler, NULL, &ss)) {
         BLog(BLOG_ERROR, "DataProtoSource_Init failed");
@@ -497,13 +504,6 @@ int main (int argc, char *argv[])
         goto fail7a;
     }
     
-    // calculate data MTU
-    if (device_mtu > INT_MAX - DATAPROTO_MAX_OVERHEAD) {
-        BLog(BLOG_ERROR, "Device MTU is too large");
-        goto fail8;
-    }
-    data_mtu = DATAPROTO_MAX_OVERHEAD + device_mtu;
-    
     // init peers list
     LinkedList2_Init(&peers);
     num_peers = 0;
@@ -540,7 +540,6 @@ int main (int argc, char *argv[])
     ServerConnection_Free(&server);
 fail9:
     FrameDecider_Free(&frame_decider);
-fail8:
     DPReceiveDevice_Free(&device_output_dprd);
 fail7a:
     DataProtoSource_Free(&device_input_dpd);