summaryrefslogtreecommitdiffstats
path: root/usr.bin/calendar
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-06-23 06:52:13 +0000
committercharnier <charnier@FreeBSD.org>1997-06-23 06:52:13 +0000
commit2d49da06e0527f3ea89c74a20917a80b12f378b4 (patch)
tree0a21d04a14509de96671fc19025c96105fdbee3a /usr.bin/calendar
parent14698cd80ae1af087e716da460feb3a02c3b4017 (diff)
downloadFreeBSD-src-2d49da06e0527f3ea89c74a20917a80b12f378b4.zip
FreeBSD-src-2d49da06e0527f3ea89c74a20917a80b12f378b4.tar.gz
Use err(3). Abort if strdup() returns NULL.
Diffstat (limited to 'usr.bin/calendar')
-rw-r--r--usr.bin/calendar/day.c22
-rw-r--r--usr.bin/calendar/io.c27
2 files changed, 27 insertions, 22 deletions
diff --git a/usr.bin/calendar/day.c b/usr.bin/calendar/day.c
index 6000438..91b3731 100644
--- a/usr.bin/calendar/day.c
+++ b/usr.bin/calendar/day.c
@@ -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);
diff --git a/usr.bin/calendar/io.c b/usr.bin/calendar/io.c
index 014a805..9634dac 100644
--- a/usr.bin/calendar/io.c
+++ b/usr.bin/calendar/io.c
@@ -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);
}
-
OpenPOWER on IntegriCloud