Changeset 562 for trunk/src/yulectl.c


Ignore:
Timestamp:
Jun 29, 2021, 10:23:44 PM (3 years ago)
Author:
katerina
Message:

Fix for ticket #450 (compiler warnings) and fixes for tests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/yulectl.c

    r481 r562  
    4848#endif
    4949
     50#define SH_PW_SIZE 15
     51
    5052static int    sock     = -1;
    51 static char   password[15] = "";
     53static char   password[SH_PW_SIZE] = "";
    5254static int    verbose = 0;
    5355
     
    123125static char * safe_copy(char * to, const char * from, size_t size)
    124126{
    125   if (to && from)
    126     {
    127       strncpy (to, from, size);
    128       if (size > 0)
    129         to[size-1] = '\0';
    130       else
    131         *to = '\0';
     127  if (to && from && (size > 0))
     128    {
     129      strncpy (to, from, size-1);
     130      to[size-1] = '\0';
    132131    }
    133132  return to;
     
    144143   */
    145144  name.sun_family = AF_UNIX;
    146   strncpy (name.sun_path, serversock, sizeof(name.sun_path) - 1);
     145  memcpy(name.sun_path, serversock, sizeof(name.sun_path));
     146  name.sun_path[sizeof(name.sun_path)-1] = '\0';
     147  if (strlen(serversock) > strlen(name.sun_path))
     148    {
     149      perror (_("ERROR: socket path too long"));
     150      return -1;
     151    }
    147152  size = (offsetof (struct sockaddr_un, sun_path)
    148153          + strlen (name.sun_path) + 1);
     
    401406   */
    402407  pw = getenv(_("YULECTL_PASSWORD"));
    403   if (pw && strlen(pw) < 15)
     408  if (pw && strlen(pw) < SH_PW_SIZE)
    404409    {
    405410      strcpy(password, pw);
     
    413418    return -1;
    414419
    415   if ( (strlen(home) + strlen(_("/.yulectl_cred")) + 1) > 4096)
     420  if ( (strlen(home) + strlen(_("/.yulectl_cred")) + 1) > sizeof(home))
    416421    {
    417422      fprintf (stderr, "%s", _("ERROR: path for $HOME is too long.\n"));
     
    451456  (void) rtrim(message2);
    452457
    453   if (strlen(message2) > 14)
     458  if (strlen(message2) > (SH_PW_SIZE -1))
    454459    {
    455460      fprintf (stderr, "%s",
Note: See TracChangeset for help on using the changeset viewer.