Commit 07e49fc4 07e49fc428945768def979877f672a28e7b8c1ef by Alain Magloire

Nasty annoying memory overflow in argcv_get() that was causing random

crashes.  Couple of places check if (ptr == NULL) before free(), this is
not a bug since POSIX requires free(NULL) to be legal but on some old station
like SunOS-4 that will corrupt the freelist or crash.
Some Copyright updates.
1 parent 8e1d51ee
......@@ -41,17 +41,17 @@ argcv_get (const char *command, int *argc, char ***argv)
if (command[i] == ' ')
(*argc)++;
*argv = malloc ((*argc + 1) * sizeof (char *));
*argv = calloc ((*argc + 1), sizeof (char *));
for (i = 0; i <= len; i++)
{
if (command[i] == ' ' || command[i] == '\0')
{
(*argv)[j] = malloc ((i-start) * sizeof (char));
if (argv[j] == NULL && (i-start > 0))
/* Reserve space for the null. */
(*argv)[j] = calloc ((i - start + 1), sizeof (char));
if ((*argv[j]) == NULL)
return 1;
strncpy ((*argv)[j], &command[start], i-start);
(*argv)[j][i-start] = '\0';
strncpy ((*argv)[j], &command[start], i - start);
j++;
start = i+1;
}
......@@ -68,6 +68,7 @@ int
argcv_free (int argc, char **argv)
{
while (--argc >= 0)
if (argv[argc])
free (argv[argc]);
free (argv);
return 1;
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000 Free Software Foundation, Inc.
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......
......@@ -249,6 +249,7 @@ main (int argc, char **argv)
while (1)
{
int len;
if (command)
free (command);
command = readline (prompt->set && prompt->value != NULL ? prompt->value : " ");
len = strlen (command);
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
Copyright (C) 1999, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -45,6 +45,7 @@ mail_set (int argc, char **argv)
if (entry == NULL)
return 1;
entry->set = 0;
if (entry->value)
free (entry->value);
}
else if (strchr (argv[i], '=') != NULL)
......@@ -63,6 +64,7 @@ mail_set (int argc, char **argv)
if (entry == NULL)
return 1;
entry->set = 1;
if (entry->value)
free (entry->value);
entry->value = value;
}
......@@ -72,6 +74,7 @@ mail_set (int argc, char **argv)
if (entry == NULL)
return 1;
entry->set = 1;
if (entry->value)
free (entry->value);
entry->value = NULL;
}
......