1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-04 12:52:15 +00:00

Use err(3). Abort if strdup() returns NULL.

This commit is contained in:
Philippe Charnier 1997-06-23 06:52:13 +00:00
parent 84497b4ad4
commit 4d2854f4b5
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=26839
2 changed files with 27 additions and 22 deletions

View File

@ -29,6 +29,8 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
@ -41,6 +43,7 @@
#include <sys/uio.h>
#include <string.h>
#include <stdlib.h>
#include <err.h>
#include "pathnames.h"
#include "calendar.h"
@ -88,7 +91,8 @@ void setnnames(void)
buf[l] = '\0';
if (ndays[i].name != NULL)
free(ndays[i].name);
ndays[i].name = strdup(buf);
if ((ndays[i].name = strdup(buf)) == NULL)
errx(1, "cannot allocate memory");
ndays[i].len = strlen(buf);
strftime(buf, sizeof(buf), "%A", &tm);
@ -99,7 +103,8 @@ void setnnames(void)
buf[l] = '\0';
if (fndays[i].name != NULL)
free(fndays[i].name);
fndays[i].name = strdup(buf);
if ((fndays[i].name = strdup(buf)) == NULL)
errx(1, "cannot allocate memory");
fndays[i].len = strlen(buf);
}
@ -113,7 +118,8 @@ void setnnames(void)
buf[l] = '\0';
if (nmonths[i].name != NULL)
free(nmonths[i].name);
nmonths[i].name = strdup(buf);
if ((nmonths[i].name = strdup(buf)) == NULL)
errx(1, "cannot allocate memory");
nmonths[i].len = strlen(buf);
strftime(buf, sizeof(buf), "%B", &tm);
@ -124,7 +130,8 @@ void setnnames(void)
buf[l] = '\0';
if (fnmonths[i].name != NULL)
free(fnmonths[i].name);
fnmonths[i].name = strdup(buf);
if ((fnmonths[i].name = strdup(buf)) == NULL)
errx(1, "cannot allocate memory");
fnmonths[i].len = strlen(buf);
}
}
@ -163,11 +170,8 @@ time_t Mktime (dp)
int len;
struct tm tm;
date = strdup(dp);
if (date == NULL) {
fprintf(stderr, "calendar: strdup failed in Mktime\n");
exit(1);
}
if ((date = strdup(dp)) == NULL)
errx(1, "strdup failed in Mktime");
(void)time(&t);
tp = localtime(&t);

View File

@ -29,6 +29,8 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#ifndef lint
@ -112,14 +114,16 @@ cal()
if (strncasecmp(buf, "Easter=", 7) == 0 && buf[7]) {
if (neaster.name != NULL)
free(neaster.name);
neaster.name = strdup(buf + 7);
if ((neaster.name = strdup(buf + 7)) == NULL)
errx(1, "cannot allocate memory");
neaster.len = strlen(buf + 7);
continue;
}
if (strncasecmp(buf, "Paskha=", 7) == 0 && buf[7]) {
if (npaskha.name != NULL)
free(npaskha.name);
npaskha.name = strdup(buf + 7);
if ((npaskha.name = strdup(buf + 7)) == NULL)
errx(1, "cannot allocate memory");
npaskha.len = strlen(buf + 7);
continue;
}
@ -259,20 +263,19 @@ opencal()
(void)close(pdes[0]);
uid = geteuid();
if (setuid(getuid()) < 0) {
fprintf(stderr, "calendar: first setuid failed\n");
warnx("first setuid failed");
_exit(1);
};
if (setgid(getegid()) < 0) {
fprintf(stderr, "calendar: setgid failed\n");
warnx("setgid failed");
_exit(1);
}
if (setuid(uid) < 0) {
fprintf(stderr, "calendar: setuid failed\n");
warnx("setuid failed");
_exit(1);
}
execl(_PATH_CPP, "cpp", "-P", "-I.", _PATH_INCLUDE, NULL);
(void)fprintf(stderr,
"calendar: execl: %s: %s.\n", _PATH_CPP, strerror(errno));
warn(_PATH_CPP);
_exit(1);
}
/* parent -- set stdin to pipe output */
@ -322,21 +325,20 @@ closecal(fp)
(void)close(pdes[1]);
uid = geteuid();
if (setuid(getuid()) < 0) {
fprintf(stderr, "calendar: setuid failed\n");
warnx("setuid failed");
_exit(1);
};
if (setgid(getegid()) < 0) {
fprintf(stderr, "calendar: setgid failed\n");
warnx("setgid failed");
_exit(1);
}
if (setuid(uid) < 0) {
fprintf(stderr, "calendar: setuid failed\n");
warnx("setuid failed");
_exit(1);
}
execl(_PATH_SENDMAIL, "sendmail", "-i", "-t", "-F",
"\"Reminder Service\"", NULL);
(void)fprintf(stderr,
"calendar: %s: %s.\n", _PATH_SENDMAIL, strerror(errno));
warn(_PATH_SENDMAIL);
_exit(1);
}
/* parent -- write to pipe input */
@ -352,4 +354,3 @@ done: (void)fclose(fp);
(void)unlink(path);
while (wait(&status) >= 0);
}