• ranshid's avatar
    Avoid using unsafe C functions (#10932) · eacca729
    ranshid authored
    replace use of:
    sprintf --> snprintf
    strcpy/strncpy  --> redis_strlcpy
    strcat/strncat  --> redis_strlcat
    
    **why are we making this change?**
    Much of the code uses some unsafe variants or deprecated buffer handling
    functions.
    While most cases are probably not presenting any issue on the known path
    programming errors and unterminated strings might lead to potential
    buffer overflows which are not covered by tests.
    
    **As part of this PR we change**
    1. added implementation for redis_strlcpy and redis_strlcat based on the strl implementation: https://linux.die.net/man/3/strl
    2. change all occurrences of use of sprintf with use of snprintf
    3. change occurrences of use of  strcpy/strncpy with redis_strlcpy
    4. change occurrences of use of strcat/strncat with redis_strlcat
    5. change the behavior of ll2string/ull2string/ld2string so that it will always place null
      termination ('\0') on the output buffer in the first index. this was done in order to make
      t...
    eacca729
util.c 35.2 KB