Jump to content

Functor

Members
  • Posts

    351
  • Joined

  • Last visited

  • Days Won

    26

Posts posted by Functor

  1. 6 minutes ago, Chopps said:

    Our admin can contact you on Skype? So we can send all other requirements to upgrade to 3.0, and pay of course!

    Sure.

    P.S. I haven't seen your "src", but I think you use very old emulator. It looks like your "src" doesn't have applied fix, which was released 8 years ago. ?

    Check it: https://github.com/rathena/rathena/commit/5b66b21b67b048427f8e00cea36171a040f7de2c

  2. Example - https://rextester.com/DGDTO79874

    #include  <stdio.h>
    
    int main(void)
    {
        char buffer_1[32];
        char buffer_2[32];
        
        unsigned int len_1 = 0;
        unsigned int len_2 = 0;
        
        memset(buffer_1, '\0', sizeof(buffer_1));
        memset(buffer_2, '\0', sizeof(buffer_2));
        
        int result_1 = sscanf("hello_1", "%31c%n", buffer_1, &len_1);
        int result_2 = sscanf("hello_2", "%31s%n", buffer_2, &len_2);
         
        printf("%s - %u - result %d\n", buffer_1, len_1, result_1);
        printf("%s - %u - result %d\n", buffer_2, len_2, result_2);
        
        return 0;
    }

    The result:

    Quote
    
    hello_1 - 0 - result -1
    hello_2 - 7 - result 1

    As you can see if "sscanf" fails - it returns "-1". So, it is important to check the result.

     

    11 minutes ago, Rytech said:

    Also is there anything else I should look for in all of the code that could be a possible issue with VS 2015 to fix?

    If I find something - I will let you know.

  3. 2 hours ago, Rytech said:

    That doesn't look right.

    It is the result of your masking of the problem. ? I mean:

    10 hours ago, Rytech said:

    make the code safer and it fixed the crash issue

     

    P.S. Try to change from "%31c%n" to "%31s%n" + add validation the result of the execution "sscanf" function and value of "len" variable. Keep in mind that execution of a "%n" directive does not increment the assignment count returned at the completion of execution of the sscanf function.

  4. @Rytech

    int i,j,p,len;

    This line reserves memory on the stack for the variables. But it doesn't initialize them.

    So, they contain values after the execution of previous functions("garbage data").

    There is a possibility that function "sscanf" will not assign the value to the variable "len", but you use it without any validation.

    Different compilers generate different machine code. In this case, "len" variable can contain different values. 

    For example, when we compile server by using VS2008 - the uninitialized "len" variable is equal "2" and it doesn't cause a crash.

    But when we use VS2015 - the uninitialized "len" variable is equal "100500" and it causes a crash.

    You should press the button "Run it (F8)" to execute code:

    Clang (len == 0) https://rextester.com/TUUGW99405
    VC++ (len == random value) https://rextester.com/DBNPV42856

    As you can see, code is the same - the results are different for different compilers.

    It isn't a problem of compilator. It is the problem of the code. 

    • MVP 1
×
×
  • Create New...