Date: Wed, 10 Jun 1998 12:18:24 -0700 (PDT) From: Archie Cobbs <archie@whistle.com> To: FreeBSD-gnats-submit@FreeBSD.ORG Subject: bin/6907: more(1) core dumps when a long filename is not found Message-ID: <199806101918.MAA04962@bubba.whistle.com>
next in thread | raw e-mail | index | archive | help
>Number: 6907 >Category: bin >Synopsis: more(1) core dumps when a long filename is not found >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Jun 10 12:20:01 PDT 1998 >Last-Modified: >Originator: Archie Cobbs >Organization: Whistle Communications, Inc. >Release: FreeBSD 3.0-current >Environment: FreeBSD 3.0-current circa Wed Jun 10 12:03:13 PDT 1998 >Description: The more(1) program core dumps when you say ``more file'' and file is not found and is a long filename. >How-To-Repeat: $ /usr/bin/more xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx >Fix: The following patch replaces all instances of sprintf(): Index: ch.c =================================================================== RCS file: /cvs/freebsd/src/usr.bin/more/ch.c,v retrieving revision 1.4 diff -c -r1.4 ch.c *** ch.c 1995/05/30 06:32:28 1.4 --- ch.c 1998/06/10 19:17:40 *************** *** 394,401 **** * If we don't have ANY, then quit. * Otherwise, just report the error and return. */ ! (void)sprintf(message, "cannot allocate %d buffers", ! want_nbufs - nbufs); error(message); if (nbufs == 0) quit(); --- 394,401 ---- * If we don't have ANY, then quit. * Otherwise, just report the error and return. */ ! (void)snprintf(message, sizeof(message), ! "cannot allocate %d buffers", want_nbufs - nbufs); error(message); if (nbufs == 0) quit(); Index: command.c =================================================================== RCS file: /cvs/freebsd/src/usr.bin/more/command.c,v retrieving revision 1.7 diff -c -r1.7 command.c *** command.c 1997/03/02 18:55:41 1.7 --- command.c 1998/06/10 19:17:40 *************** *** 185,203 **** putstr(current_name); putstr(":"); if (!ispipe) { ! (void)sprintf(pbuf, " file %d/%d", curr_ac + 1, ac); putstr(pbuf); } if (linenums) { ! (void)sprintf(pbuf, " line %d", currline(BOTTOM)); putstr(pbuf); } if ((pos = position(BOTTOM)) != NULL_POSITION) { ! (void)sprintf(pbuf, " byte %qd", pos); putstr(pbuf); if (!ispipe && (len = ch_length())) { ! (void)sprintf(pbuf, "/%qd pct %qd%%", ! len, ((100 * pos) / len)); putstr(pbuf); } } --- 185,205 ---- putstr(current_name); putstr(":"); if (!ispipe) { ! (void)snprintf(pbuf, sizeof(pbuf), ! " file %d/%d", curr_ac + 1, ac); putstr(pbuf); } if (linenums) { ! (void)snprintf(pbuf, sizeof(pbuf), ! " line %d", currline(BOTTOM)); putstr(pbuf); } if ((pos = position(BOTTOM)) != NULL_POSITION) { ! (void)snprintf(pbuf, sizeof(pbuf), " byte %qd", pos); putstr(pbuf); if (!ispipe && (len = ch_length())) { ! (void)snprintf(pbuf, sizeof(pbuf), ! "/%qd pct %qd%%", len, ((100 * pos) / len)); putstr(pbuf); } } *************** *** 218,224 **** else if (!ispipe && (pos = position(BOTTOM)) != NULL_POSITION && (len = ch_length())) { ! (void)sprintf(pbuf, " (%qd%%)", ((100 * pos) / len)); putstr(pbuf); } so_exit(); --- 220,227 ---- else if (!ispipe && (pos = position(BOTTOM)) != NULL_POSITION && (len = ch_length())) { ! (void)snprintf(pbuf, sizeof(pbuf), ! " (%qd%%)", ((100 * pos) / len)); putstr(pbuf); } so_exit(); *************** *** 620,628 **** dolinenumber = 0; } if (dolinenumber && (c = currline(MIDDLE))) ! (void)sprintf(buf, "%s +%d %s", editor, c, current_file); else ! (void)sprintf(buf, "%s %s", editor, current_file); lsystem(buf); } --- 623,632 ---- dolinenumber = 0; } if (dolinenumber && (c = currline(MIDDLE))) ! (void)snprintf(buf, sizeof(buf), ! "%s +%d %s", editor, c, current_file); else ! (void)snprintf(buf, sizeof(buf), "%s %s", editor, current_file); lsystem(buf); } Index: help.c =================================================================== RCS file: /cvs/freebsd/src/usr.bin/more/help.c,v retrieving revision 1.1.1.1 diff -c -r1.1.1.1 help.c *** help.c 1994/05/27 12:30:46 1.1.1.1 --- help.c 1998/06/10 19:17:40 *************** *** 44,49 **** { char cmd[MAXPATHLEN + 20]; ! (void)sprintf(cmd, "-more %s", _PATH_HELPFILE); lsystem(cmd); } --- 44,49 ---- { char cmd[MAXPATHLEN + 20]; ! (void)snprintf(cmd, sizeof(cmd), "-more %s", _PATH_HELPFILE); lsystem(cmd); } Index: main.c =================================================================== RCS file: /cvs/freebsd/src/usr.bin/more/main.c,v retrieving revision 1.9 diff -c -r1.9 main.c *** main.c 1998/02/20 04:13:28 1.9 --- main.c 1998/06/10 19:17:40 *************** *** 48,53 **** --- 48,54 ---- */ #include <sys/types.h> + #include <sys/param.h> #include <sys/file.h> #include <stdio.h> #include <stdlib.h> *************** *** 87,93 **** register char *m; off_t initial_pos, position(); static int didpipe; ! char message[100], *p; char *rindex(), *strerror(), *save(), *bad_file(); initial_pos = NULL_POSITION; --- 88,94 ---- register char *m; off_t initial_pos, position(); static int didpipe; ! char message[MAXPATHLEN + 50], *p; char *rindex(), *strerror(), *save(), *bad_file(); initial_pos = NULL_POSITION; *************** *** 122,128 **** return(0); } else if ((f = open(filename, O_RDONLY, 0)) < 0) { ! (void)sprintf(message, "%s: %s", filename, strerror(errno)); error(message); free(filename); return(0); --- 123,130 ---- return(0); } else if ((f = open(filename, O_RDONLY, 0)) < 0) { ! (void)snprintf(message, sizeof(message), ! "%s: %s", filename, strerror(errno)); error(message); free(filename); return(0); Index: os.c =================================================================== RCS file: /cvs/freebsd/src/usr.bin/more/os.c,v retrieving revision 1.2 diff -c -r1.2 os.c *** os.c 1998/02/20 04:13:28 1.2 --- os.c 1998/06/10 19:17:40 *************** *** 123,129 **** cmd = shell; else { ! (void)sprintf(cmdbuf, "%s -c \"%s\"", shell, cmd); cmd = cmdbuf; } } --- 123,130 ---- cmd = shell; else { ! (void)snprintf(cmdbuf, sizeof(cmdbuf), ! "%s -c \"%s\"", shell, cmd); cmd = cmdbuf; } } *************** *** 215,233 **** /* * Read the output of <echo filename>. */ ! cmd = malloc((u_int)(strlen(filename)+8)); if (cmd == NULL) return (filename); - (void)sprintf(cmd, "echo \"%s\"", filename); } else { /* * Read the output of <$SHELL -c "echo filename">. */ ! cmd = malloc((u_int)(strlen(p)+12)); if (cmd == NULL) return (filename); - (void)sprintf(cmd, "%s -c \"echo %s\"", p, filename); } if ((f = popen(cmd, "r")) == NULL) --- 216,232 ---- /* * Read the output of <echo filename>. */ ! (void)asprintf(&cmd, "echo \"%s\"", filename); if (cmd == NULL) return (filename); } else { /* * Read the output of <$SHELL -c "echo filename">. */ ! (void)asprintf(&cmd, "%s -c \"echo %s\"", p, filename); if (cmd == NULL) return (filename); } if ((f = popen(cmd, "r")) == NULL) *************** *** 255,261 **** char *strcat(), *strerror(); if (stat(filename, &statbuf) < 0) { ! (void)sprintf(message, "%s: %s", filename, strerror(errno)); return(message); } if ((statbuf.st_mode & S_IFMT) == S_IFDIR) { --- 254,261 ---- char *strcat(), *strerror(); if (stat(filename, &statbuf) < 0) { ! (void)snprintf(message, len, ! "%s: %s", filename, strerror(errno)); return(message); } if ((statbuf.st_mode & S_IFMT) == S_IFDIR) { Index: prim.c =================================================================== RCS file: /cvs/freebsd/src/usr.bin/more/prim.c,v retrieving revision 1.5 diff -c -r1.5 prim.c *** prim.c 1995/05/30 06:32:35 1.5 --- prim.c 1998/06/10 19:17:40 *************** *** 374,381 **** while ((c = ch_forw_get()) != '\n') if (c == EOI) { char message[40]; ! (void)sprintf(message, "File has only %d lines", ! nlines - 1); error(message); return; } --- 374,381 ---- while ((c = ch_forw_get()) != '\n') if (c == EOI) { char message[40]; ! (void)snprintf(message, sizeof(message), ! "File has only %d lines", nlines - 1); error(message); return; } >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199806101918.MAA04962>