| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 2904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2915 int32_t nDots = 0; | 2915 int32_t nDots = 0; |
| 2916 int32_t iDotPos[4] = {0,0,0,0}; | 2916 int32_t iDotPos[4] = {0,0,0,0}; |
| 2917 | 2917 |
| 2918 for (i = 0; (i < len) && (nDots < 4); i++) | 2918 for (i = 0; (i < len) && (nDots < 4); i++) |
| 2919 { | 2919 { |
| 2920 if (ipadr[i] == (char)'.') | 2920 if (ipadr[i] == (char)'.') |
| 2921 { | 2921 { |
| 2922 // Store index of dots and count number of dots. | 2922 // Store index of dots and count number of dots. |
| 2923 iDotPos[nDots++] = i; | 2923 iDotPos[nDots++] = i; |
| 2924 } | 2924 } |
| 2925 else if (isdigit(ipadr[i]) == 0) |
| 2926 { |
| 2927 return false; |
| 2928 } |
| 2925 } | 2929 } |
| 2926 | 2930 |
| 2927 bool allUnder256 = false; | 2931 bool allUnder256 = false; |
| 2928 // TODO (hellner): while loop seems to be abused here to get | 2932 // TODO (hellner): while loop seems to be abused here to get |
| 2929 // label like functionality. Fix later to avoid introducing bugs now. | 2933 // label like functionality. Fix later to avoid introducing bugs now. |
| 2930 | 2934 |
| 2931 // Check that all numbers are smaller than 256. | 2935 // Check that all numbers are smaller than 256. |
| 2932 do | 2936 do |
| 2933 { | 2937 { |
| 2934 if (nDots != 3 ) | 2938 if (nDots != 3 ) |
| 2935 { | 2939 { |
| 2936 break; | 2940 break; |
| 2937 } | 2941 } |
| 2938 | 2942 |
| 2939 if (iDotPos[0] <= 3) | 2943 if (iDotPos[0] <= 3) |
| 2940 { | 2944 { |
| 2941 char nr[4]; | 2945 char nr[4]; |
| 2942 memset(nr,0,4); | 2946 memset(nr,0,4); |
| 2943 strncpy(nr,&ipadr[0],iDotPos[0]); | 2947 strncpy(nr,&ipadr[0],iDotPos[0]); |
| 2944 int32_t num = atoi(nr); | 2948 int32_t num = atoi(nr); |
| 2945 if (num > 255) | 2949 if (num > 255 || num < 0) |
| 2946 { | 2950 { |
| 2947 break; | 2951 break; |
| 2948 } | 2952 } |
| 2949 } else { | 2953 } else { |
| 2950 break; | 2954 break; |
| 2951 } | 2955 } |
| 2952 | 2956 |
| 2953 if (iDotPos[1] - iDotPos[0] <= 4) | 2957 if (iDotPos[1] - iDotPos[0] <= 4) |
| 2954 { | 2958 { |
| 2955 char nr[4]; | 2959 char nr[4]; |
| 2956 memset(nr,0,4); | 2960 memset(nr,0,4); |
| 2957 strncpy(nr,&ipadr[iDotPos[0]+1], iDotPos[1] - iDotPos[0] - 1); | 2961 strncpy(nr,&ipadr[iDotPos[0]+1], iDotPos[1] - iDotPos[0] - 1); |
| 2958 int32_t num = atoi(nr); | 2962 int32_t num = atoi(nr); |
| 2959 if (num > 255) | 2963 if (num > 255 || num < 0) |
| 2960 break; | 2964 break; |
| 2961 } else { | 2965 } else { |
| 2962 break; | 2966 break; |
| 2963 } | 2967 } |
| 2964 | 2968 |
| 2965 if (iDotPos[2] - iDotPos[1] <= 4) | 2969 if (iDotPos[2] - iDotPos[1] <= 4) |
| 2966 { | 2970 { |
| 2967 char nr[4]; | 2971 char nr[4]; |
| 2968 memset(nr,0,4); | 2972 memset(nr,0,4); |
| 2969 strncpy(nr,&ipadr[iDotPos[1]+1], iDotPos[1] - iDotPos[0] - 1); | 2973 strncpy(nr,&ipadr[iDotPos[1]+1], iDotPos[2] - iDotPos[1] - 1); |
| 2970 int32_t num = atoi(nr); | 2974 int32_t num = atoi(nr); |
| 2971 if (num > 255) | 2975 if (num > 255 || num < 0) |
| 2972 break; | 2976 break; |
| 2977 } else { |
| 2978 break; |
| 2979 } |
| 2973 | 2980 |
| 2981 if (len - iDotPos[2] <= 4) |
| 2982 { |
| 2983 char nr[4]; |
| 2974 memset(nr,0,4); | 2984 memset(nr,0,4); |
| 2975 strncpy(nr,&ipadr[iDotPos[2]+1], len - iDotPos[2] -1); | 2985 strncpy(nr,&ipadr[iDotPos[2]+1], len - iDotPos[2] -1); |
| 2976 num = atoi(nr); | 2986 int32_t num = atoi(nr); |
| 2977 if (num > 255) | 2987 if (num > 255 || num < 0) |
| 2978 break; | 2988 break; |
| 2979 else | 2989 else |
| 2980 allUnder256 = true; | 2990 allUnder256 = true; |
| 2981 } else | 2991 } else { |
| 2982 break; | 2992 break; |
| 2993 } |
| 2983 } while(false); | 2994 } while(false); |
| 2984 | 2995 |
| 2985 if (nDots != 3 || !allUnder256) | 2996 if (nDots != 3 || !allUnder256) |
| 2986 { | 2997 { |
| 2987 return false; | 2998 return false; |
| 2988 } | 2999 } |
| 2989 } | 3000 } |
| 2990 return true; | 3001 return true; |
| 2991 } | 3002 } |
| 2992 | 3003 |
| 2993 } // namespace test | 3004 } // namespace test |
| 2994 } // namespace webrtc | 3005 } // namespace webrtc |
| OLD | NEW |