Menu

FP with strcasecmp but not strcmp

2023-02-03
2023-02-07
  • Tobias Mark

    Tobias Mark - 2023-02-03

    Only when using --libray=posix

    Example

    void func(char *in) {
        char *b = strdup("b");
        if(strncasecmp(b, in, 3)) {
            printf("foo\n");
        }
        free(b);
    }
    

    Error:

    Buffer is accessed out of bounds: b [bufferAccessOutOfBounds]
    

    Error disappears with strncmp() or when not using strdup()

    Main cause seems to be different library definitions between strcasecmp (in cfg/posix.cfg) and strncmp (in cfg/std.cfg). The former also includes:

        <minsize type="argvalue" arg="3"/>
    
     
  • CHR

    CHR - 2023-02-03

    Since you have already identified the cause, why not submit a PR?

     
    • Tobias Mark

      Tobias Mark - 2023-02-07

      Because I'am not sure.
      Maybe there is a better solution then just removing the test?

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.