Github user wengyanqing commented on a diff in the pull request:

    https://github.com/apache/incubator-hawq/pull/1354#discussion_r181687215
  
    --- Diff: src/backend/resourcemanager/utils/simplestring.c ---
    @@ -200,6 +200,45 @@ int  SimpleStringToStorageSizeMB(SimpStringPtr str, 
uint32_t *value)
        return FUNC_RETURN_OK;
     }
     
    +int  SimpleStringToBytes(SimpStringPtr str, uint32_t *value)
    +{
    +   int     tail    = strlen(str->Str) - 1;
    +   int     scanres = -1;
    +   int32_t val;
    +   char    buff[256];
    +
    +   if ( tail < 2 || tail > sizeof(buff)-1 )
    +           return UTIL_SIMPSTRING_WRONG_FORMAT;
    +
    +   strncpy(buff, str->Str, tail-1);
    +   buff[tail-1] = '\0';
    +
    +   scanres = sscanf(buff, "%d", &val);
    +   if ( scanres != 1 )
    +           return UTIL_SIMPSTRING_WRONG_FORMAT;
    +
    +   if ( (str->Str[tail]   == 'b' || str->Str[tail] == 'B' ) &&
    +            (str->Str[tail-1] == 'k' || str->Str[tail-1] == 'K') ) {
    +           *value = val * 1024;
    +   }
    +   else if ( (str->Str[tail]   == 'b' || str->Str[tail] == 'B' ) &&
    +            (str->Str[tail-1] == 'm' || str->Str[tail-1] == 'M') ) {
    +           *value = val * 1024 *1024;
    +   }
    +   else if ( (str->Str[tail]   == 'b' || str->Str[tail] == 'B' ) &&
    +                     (str->Str[tail-1] == 'g' || str->Str[tail-1] == 'G') 
) {
    +           *value = val * 1024 * 1024 *1024;
    +   }
    +   else if ( (str->Str[tail]   == 'b' || str->Str[tail] == 'B' ) &&
    +                     (str->Str[tail-1] == 't' || str->Str[tail-1] == 'T') 
) {
    +           *value = val * 1024 * 1024 *1024 * 1024;
    --- End diff --
    
    value is int32, it will overflow here.


---

Reply via email to