=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mktemp/mktemp.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- src/usr.bin/mktemp/mktemp.c 2009/10/27 23:59:40 1.15 +++ src/usr.bin/mktemp/mktemp.c 2013/03/12 15:07:12 1.16 @@ -1,7 +1,8 @@ -/* $OpenBSD: mktemp.c,v 1.15 2009/10/27 23:59:40 deraadt Exp $ */ +/* $OpenBSD: mktemp.c,v 1.16 2013/03/12 15:07:12 millert Exp $ */ /* - * Copyright (c) 1996, 1997, 2001 Todd C. Miller + * Copyright (c) 1996, 1997, 2001-2003, 2013 + * Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -30,7 +31,7 @@ { int ch, fd, uflag = 0, quiet = 0, tflag = 0, makedir = 0; char *cp, *template, *tempfile, *prefix = _PATH_TMP; - int plen; + size_t len; while ((ch = getopt(argc, argv, "dp:qtu")) != -1) switch(ch) { @@ -78,14 +79,23 @@ cp = getenv("TMPDIR"); if (cp != NULL && *cp != '\0') prefix = cp; - plen = strlen(prefix); - while (plen != 0 && prefix[plen - 1] == '/') - plen--; + len = strlen(prefix); + while (len != 0 && prefix[len - 1] == '/') + len--; - if (asprintf(&tempfile, "%.*s/%s", plen, prefix, template) < 0) + if (asprintf(&tempfile, "%.*s/%s", (int)len, prefix, template) < 0) tempfile = NULL; - } else + } else { + len = strlen(template); + if (len < 6 || strcmp(&template[len - 6], "XXXXXX")) { + if (!quiet) { + warningx("insufficient number of Xs in template `%s'", + template); + } + exit(1); + } tempfile = strdup(template); + } if (tempfile == NULL) { if (!quiet) warnx("cannot allocate memory");