Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update exim_lock.c Enhance Security with strncpy #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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