Skip to content

Conversation

Shivam7-1
Copy link

In this PR replaces instances of strcpy() with strncpy() to mitigate the risk of buffer overflows. strncpy() ensures safer handling of strings by limiting the number of copied characters and adding null-termination, enhancing the overall security and stability of the code.

@Cyborgscode
Copy link
Collaborator

A quick check with the man page of strncpy ... it has 3 arguments :

char *strncpy(char dst[restrict .dsize], const char *restrict src, size_t dsize);

I'm wondering what the none-optional third one does ...

@Cyborgscode
Copy link
Collaborator

Just for education:

strncpy(), even if used correctly, which you didn't, would not enhance security, because the buffersize check is right infront of that strcpy() call :

  if ((int)strlen(pw->pw_dir) + (int)strlen(filename) + 1 > sizeof(buffer))
    {
    printf("exim_lock: expanded file name %s%s is too long", pw->pw_dir,
      filename);
    exit(EXIT_FAILURE);
    }

  strcpy(buffer, pw->pw_dir);
  strcat(buffer, filename);
  filename = buffer;
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants