Skip to content

Commit

Permalink
Merge pull request #1780 from ccoffing/more-path-cleanups
Browse files Browse the repository at this point in the history
Path cleanups
  • Loading branch information
ghaerr authored Dec 30, 2023
2 parents 86a6061 + bc79f0c commit fbbad70
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 31 deletions.
6 changes: 2 additions & 4 deletions elkscmd/file_utils/split.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <sys/param.h>
#include <fcntl.h>
#include <limits.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
Expand All @@ -31,9 +32,6 @@
#define OK 0 /* okay exit */
#define YES 1 /* yes/true */

#ifndef MAXPATHLEN
#define MAXPATHLEN 256
#endif
#define MAXBSIZE 2048
#define isdecimal(ch) (((ch) >= '0') && ((ch) <= '9'))

Expand All @@ -43,7 +41,7 @@ static int ifd = ERR, /* input file descriptor */
ofd = ERR; /* output file descriptor */
static short file_open; /* if a file open */
static char bfr[MAXBSIZE], /* I/O buffer */
fname[MAXPATHLEN]; /* file name */
fname[PATH_MAX]; /* file name */

void split1(void);
void split2(void);
Expand Down
3 changes: 2 additions & 1 deletion elkscmd/inet/httpd/httpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include <limits.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -86,7 +87,7 @@ void process_request(int fd)
{
int fin, ret;
off_t size;
char *c, *file, fullpath[128];
char *c, *file, fullpath[PATH_MAX];
struct stat st;

ret = read(fd, buf, sizeof(buf));
Expand Down
5 changes: 1 addition & 4 deletions elkscmd/minix2/lp.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <sys/wait.h>

char LPD1[] = "/bin/lpd"; /* Proper place of lpd */
char LPD2[] = "/usr/bin/lpd"; /* Minix has no sbin directories. */

void report(char *mess)
{
Expand All @@ -33,9 +32,7 @@ void lp(char *file)

if (file[0] != '/' || (pid= vfork()) == 0) {
execl(LPD1, LPD1, file, (char *) nil);
if (errno != ENOENT) fatal(LPD1);
execl(LPD2, LPD2, file, (char *) nil);
fatal(LPD2);
fatal(LPD1);
}

if (pid < 0) fatal("can't fork");
Expand Down
10 changes: 5 additions & 5 deletions elkscmd/minix3/mail.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

/* 2003-07-18: added -s option - ASW */

#include <limits.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
Expand Down Expand Up @@ -35,7 +36,6 @@

#define HELPFILE "/usr/lib/mail.help"
#define PROMPT "? "
#define PATHLEN 80
#define MAXRCPT 100 /* maximum number of recipients */
#define LINELEN 512

Expand Down Expand Up @@ -63,7 +63,7 @@ int verbose = 0; /* pass "-v" flag on to mailer */
int needupdate = 0; /* need to update mailbox */
int msgstatus = 0; /* return the mail status */
int distlist = 0; /* include distribution list */
char mailbox[PATHLEN]; /* user's mailbox/maildrop */
char mailbox[PATH_MAX]; /* user's mailbox/maildrop */
char tempname[] = "/tmp/mailXXXXXX"; /* temporary file */
char *subject = NULL;
FILE *boxfp = NULL; /* mailbox file */
Expand Down Expand Up @@ -116,7 +116,7 @@ int main(int argc, char *argv[])
case 'f':
setuid(getuid()); /* won't need to lock */
usedrop = 0;
strncpy(mailbox, optarg, (size_t)(PATHLEN - 1));
strncpy(mailbox, optarg, (size_t)(PATH_MAX - 1));
break;

case 'd': usemailer = 0; break;
Expand Down Expand Up @@ -174,7 +174,7 @@ int deliver(int count, char *vec[])
#endif
time_t now; /* for datestamping the postmark */
char sender[32]; /* sender's login name */
char lockname[PATHLEN]; /* maildrop lock */
char lockname[PATH_MAX]; /* maildrop lock */
int locktries; /* tries when box is locked */
struct passwd *pw; /* sender and recipent */
int to_console; /* deliver to console if everything fails */
Expand Down Expand Up @@ -624,7 +624,7 @@ void savelet(struct letter *let, char *savefile)
void updatebox()
{
FILE *tempfp; /* fp for tempfile */
char lockname[PATHLEN]; /* maildrop lock */
char lockname[PATH_MAX]; /* maildrop lock */
int locktries = 0; /* tries when box is locked */
struct letter *let; /* current letter */
int c;
Expand Down
5 changes: 2 additions & 3 deletions elkscmd/misc_utils/tar.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
Expand All @@ -50,8 +51,6 @@
#include <sys/dir.h>
#include <sys/time.h>

#define MAXPATHLEN 128

#define ELKS 1
#define DO_REPLACE 0 /* =1 for tar 'r' option, requires awk */

Expand Down Expand Up @@ -247,7 +246,7 @@ dorep(argv)
char *argv[];
{
register char *cp, *cp2;
char wdir[MAXPATHLEN], tempdir[MAXPATHLEN], *parent;
char wdir[PATH_MAX], tempdir[PATH_MAX], *parent;

if (!cflag) {
#if DO_REPLACE
Expand Down
2 changes: 1 addition & 1 deletion elkscmd/screen/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static inlen;
static ESCseen;
static GotSignal;
static char DefaultShell[] = "/bin/sh";
static char DefaultPath[] = ":/usr/ucb:/bin:/usr/bin";
static char DefaultPath[] = ":/bin:/usr/bin";
static char PtyProto[] = "/dev/ptyXY";
static char TtyProto[] = "/dev/ttyXY";
static int TtyMode = 0622;
Expand Down
19 changes: 10 additions & 9 deletions elkscmd/sh_utils/pwd.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#include <limits.h>
#include <unistd.h>
#include <string.h>

int main(int ac, char **av)
{
char wd[256];
if (getcwd(wd, sizeof(wd)) == NULL) {
write(STDOUT_FILENO, "Cannot get current directory\n", 29);
return 1;
}
write(STDOUT_FILENO, wd, strlen(wd));
write(STDOUT_FILENO, "\n", 1);
return 0;
char wd[PATH_MAX];

if (getcwd(wd, sizeof(wd)) == NULL) {
write(STDOUT_FILENO, "Cannot get current directory\n", 29);
return 1;
}
write(STDOUT_FILENO, wd, strlen(wd));
write(STDOUT_FILENO, "\n", 1);
return 0;
}
6 changes: 2 additions & 4 deletions elkscmd/test/libc/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <errno.h>
#include <getopt.h>
#include <libgen.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
Expand Down Expand Up @@ -117,21 +118,18 @@ TEST_CASE(misc_getopt)

TEST_CASE(misc_getcwd)
{
char buf[256];
char buf[PATH_MAX];
char *p;

p = getcwd(buf, 1);
EXPECT_EQ(errno, ERANGE);
EXPECT_EQ_P(p, NULL);

/* TODO:BUG hangs or crashes elksemu but not real ELKS */
#if 0
memset(buf, 'X', sizeof(buf));
p = getcwd(buf, sizeof(buf));
EXPECT_EQ_P(p, buf);
EXPECT_EQ(buf[0], '/');
EXPECT_LT(strlen(buf), sizeof(buf)); /* is NULL terminated */
#endif
}

static void validateCrypt(const char *s)
Expand Down

0 comments on commit fbbad70

Please sign in to comment.