openbsd-ports/mail/alpine/patches/patch-pico_file_c
ajacoutot e02a94359d - fix a crash when using tab-completion for selecting a save filename
(from alpine SVN)
- regen PLIST while here

reported to and fixed by upstream
issue spotted by Jonathan Thornburg <J.Thornburg at soton.ac dot uk>
2008-06-12 21:47:20 +00:00

64 lines
2.3 KiB
Plaintext

$OpenBSD: patch-pico_file_c,v 1.1 2008/06/12 21:47:20 ajacoutot Exp $
--- pico/file.c.orig Thu Dec 6 20:57:49 2007
+++ pico/file.c Thu Jun 12 23:15:54 2008
@@ -212,7 +212,7 @@ insfile(int f, int n)
dir[0] = '\0';
fn = file_split(dir, sizeof(dir), fname, 0);
- if(!pico_fncomplete(dir, sizeof(dir), fn, sizeof(fname)-(fn-fname)))
+ if(!pico_fncomplete(dir, fn, sizeof(fname)-(fn-fname)))
(*term.t_beep)();
}
@@ -650,7 +650,7 @@ filewrite(int f, int n)
dir[sizeof(dir)-1] = '\0';
}
- if(!pico_fncomplete(dir, sizeof(dir), fn, sizeof(fname)-(fn-fname)))
+ if(!pico_fncomplete(dir, fn, sizeof(fname)-(fn-fname)))
(*term.t_beep)();
}
@@ -1004,9 +1004,9 @@ ifile(char fname[])
* pico_fncomplete - pico's function to complete the given file name
*/
int
-pico_fncomplete(char *dir, size_t dirlen, char *fn, size_t fnlen)
+pico_fncomplete(char *dirarg, char *fn, size_t fnlen)
{
- char *p, *dlist, tmp[NLINE], dtmp[NLINE];
+ char *p, *dlist, tmp[NLINE], dir[NLINE];
int n, i, match = -1;
#ifdef DOS
#define FILECMP(x, y) (toupper((unsigned char)(x))\
@@ -1015,9 +1015,9 @@ pico_fncomplete(char *dir, size_t dirlen, char *fn, si
#define FILECMP(x, y) ((x) == (y))
#endif
- strncpy(dtmp, dir, sizeof(dtmp));
- dtmp[sizeof(dtmp)-1] = '\0';
- pfnexpand(dir = dtmp, sizeof(dtmp));
+ strncpy(dir, dirarg, sizeof(dir));
+ dir[sizeof(dir)-1] = '\0';
+ pfnexpand(dir, sizeof(dir));
if(*fn && (dlist = p = getfnames(dir, fn, &n, NULL, 0))){
memset(tmp, 0, sizeof(tmp));
while(n--){ /* any names in it */
@@ -1049,11 +1049,11 @@ pico_fncomplete(char *dir, size_t dirlen, char *fn, si
strncpy(fn, tmp, fnlen);
fn[fnlen-1] = '\0';
if(match == 1){
- if ((strlen(dir)+strlen(S_FILESEP)+strlen(fn)) < dirlen){
- strncat(dir, S_FILESEP, dirlen-strlen(dir)-1);
- dir[dirlen-1] = '\0';
- strncat(dir, fn, dirlen-strlen(dir)-1);
- dir[dirlen-1] = '\0';
+ if ((strlen(dir)+strlen(S_FILESEP)+strlen(fn)) < sizeof(dir)){
+ strncat(dir, S_FILESEP, sizeof(dir)-strlen(dir)-1);
+ dir[sizeof(dir)-1] = '\0';
+ strncat(dir, fn, sizeof(dir)-strlen(dir)-1);
+ dir[sizeof(dir)-1] = '\0';
if(isdir(dir, NULL, NULL)){
strncat(fn, S_FILESEP, fnlen-strlen(fn)-1);
fn[fnlen-1] = '\0';