Fixing a long standing bug in view.c
view.c erroneously assumes it can easily malloc a file if mmap failed and passes view-s.st_size to g_malloc. But if largefile support has been enabled, view-s.st_size is a 64 bit value and thus possibly exceeds the limit of gulong which g_malloc takes for size. This patch fixes it. 2003-02-26 Philipp Thomas [EMAIL PROTECTED] * view.c(load_view_file): Check file size doesn't exceed limit before passing it to g_malloc. --- src/view.c +++ src/view.c @@ -585,11 +585,24 @@ } #endif /* HAVE_MMAP */ -/* For those OS that dont provide mmap call. Try to load all the +/* For those OS's that don't provide mmap call. Try to load all the * file into memory ([EMAIL PROTECTED]). Also, mmap can fail * for any reason, so we use this as fallback ([EMAIL PROTECTED]) */ -view-data = (unsigned char *) g_malloc (view-s.st_size); +/* If large file support is enabled, s.st_size is a 64 bit value and + * g_malloc can't handle file sizes ULONG_MAX */ + +#if GLIB_MAJOR_VERSION 2 +# define MC_ULONG_MAX ULONG_MAX +#else +# define MC_ULONG_MAX G_MAXULONG +#endif + +if (sizeof(off_t) = sizeof(gulong) || view-s.st_size MC_ULONG_MAX) + view-data = (unsigned char*) g_malloc (view-s.st_size); +else + view-data = NULL; + if (view-data == NULL || mc_lseek (view-file, 0, SEEK_SET) != 0 || mc_read (view-file, view-data, -- Philipp Thomas [EMAIL PROTECTED] SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nuremberg, Germany ___ Mc-devel mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/mc-devel
Re: patchfs update
Adam Byrtek / alpha wrote: Hi, I'm attaching MC patchfs update. Could you please review and test this patch, and if everything is ok - apply it? Regards . . . Index: ChangeLog === RCS file: /cvs/gnome/mc/vfs/ChangeLog,v retrieving revision 1.583 diff -u -u -0 -r1.583 ChangeLog --- ChangeLog 19 Feb 2003 14:04:35 - 1.583 +++ ChangeLog 23 Feb 2003 23:16:28 - @@ -0,0 +1,5 @@ +2003-02-24 Adam Byrtek [EMAIL PROTECTED] + + * extfs/patchfs.in: rm and proper copyin support, more + functions to make code more clear + Good job! Applied, thanks. -- Regards, Andrew V. Samoilov ___ Mc-devel mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/mc-devel
Re: patchfs update
On Wed, Feb 26, 2003 at 05:12:59PM +0200, Andrew V. Samoilov wrote: +2003-02-24 Adam Byrtek [EMAIL PROTECTED] + +* extfs/patchfs.in: rm and proper copyin support, more +functions to make code more clear + Good job! Applied, thanks. I've sent this patch to Andrew privately for review, it is the feature Arpi asked for. As is has been accepted I'm sending the patch to the list - could you please test it? Regards -- _.|._ |_ _. : Adam Byrtek /alpha/ (_|||_)| |(_| : email alpha@(irc.pl|debian.org) | : jabber alpha.pl(at)jabber.org, pgp 0xB25952C0 ___ Mc-devel mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/mc-devel
Re: patchfs update
On Wed, Feb 26, 2003 at 04:21:21PM +0100, Adam Byrtek / alpha wrote: I've sent this patch to Andrew privately for review, it is the feature Arpi asked for. As is has been accepted I'm sending the patch to the list - could you please test it? Forgotten to attach the patch... -- _.|._ |_ _. : Adam Byrtek /alpha/ (_|||_)| |(_| : email alpha@(irc.pl|debian.org) | : jabber alpha.pl(at)jabber.org, pgp 0xB25952C0 Index: patchfs.in === RCS file: /cvs/gnome/mc/vfs/extfs/patchfs.in,v retrieving revision 1.12 diff -u -r1.12 patchfs.in --- extfs/patchfs.in13 Jan 2003 12:07:46 - 1.12 +++ extfs/patchfs.in23 Feb 2003 22:57:26 - @@ -7,11 +7,12 @@ use bytes; use strict; use POSIX; +use File::Temp tempfile; # standard binaries -my $bzip = 'bzip2'; -my $gzip = 'gzip'; -my $file = 'file'; +my $bzip = bzip2; +my $gzip = gzip; +my $file = file; # date parsing requires Date::Parse from TimeDate module my $parsedates = eval require Date::Parse; @@ -55,6 +56,96 @@ exit 1; } +# (compressed) input +sub myin +{ +my ($qfname)=(quotemeta $_[0]); + +$_=`$file $qfname`; +if (/bzip/) { + return $bzip -dc $qfname; +} elsif (/gzip/) { + return $gzip -dc $qfname; +} else { + return cat $qfname; +} +} + +# (compressed) output +sub myout +{ +my ($qfname,$append)=(quotemeta $_[0],$_[1]); +my ($sep); + +if ($append) { + $sep=; +} else { + $sep=; +} + +$_=`$file $qfname`; +if (/bzip/) { + return $bzip -c $sep $qfname; +} elsif (/gzip/) { + return $gzip -c $sep $qfname; +} else { + return cat $sep $qfname; +} +} + +# select diff filename conforming with rules found in diff.info +sub diff_filename +{ +my ($fsrc,$fdst)[EMAIL PROTECTED]; + +if (!$fdst !$fsrc) { + error 'Index: not yet implemented'; +} elsif (!$fsrc || $fsrc eq '/dev/null') { + return ($fdst,PATCH-CREATE/); +} elsif (!$fdst || $fdst eq '/dev/null') { + return ($fsrc,PATCH-REMOVE/); +} elsif (($fdst eq /dev/null) ($fsrc eq /dev/null)) { + error Malformed diff; +} else { + # fewest path name components + if ($fdst=~s|/|/|g $fsrc=~s|/|/|g) { + return ($fdst,); + } elsif ($fdst=~s|/|/|g $fsrc=~s|/|/|g) { + return ($fsrc,); + } else { + # shorter base name + if (($fdst=~/$basename/,length $2) ($fsrc=~/$basename/,length $2)) { + return ($fdst,); + } elsif (($fdst=~/$basename/,length $2) ($fsrc=~/$basename/,length $2)) { + return ($fsrc,); + } else { + # shortest names + if (length $fdst length $fsrc) { + return ($fdst,); + } else { + return ($fsrc,); + } + } + } +} +} + +# parse unified or context header +sub parse_header +{ +my ($unified,$context,$buf)[EMAIL PROTECTED]; + +if ($unified) { + error Can't parse unified diff header + unless ((($$buf.=I).=I)=~/$unified_header/); + return $$buf=~/$unified_extract/; +} elsif ($context) { + error Can't parse context diff header + unless ((($$buf.=I).=I)=~/$context_header/); + return $$buf=~/$context_extract/; +} +} + # list files affected by patch sub list { @@ -69,7 +160,7 @@ import Date::Parse if ($parsedates); # state==1 means diff contents, state==0 means comments -$state=0; $len=0; $f=''; +$state=0; $len=0; $f=; while (I) { # recognize diff type @@ -91,49 +182,8 @@ } $state=1; - # parse diff header - if ($unified) { - error Can't parse unified diff header - unless ((($_.=I).=I)=~/$unified_header/); - ($fsrc,$fdst,$time)=/$unified_extract/; - } elsif ($context) { - error Can't parse context diff header - unless ((($_.=I).=I)=~/$context_header/); - ($fsrc,$fdst,$time)=/$context_extract/; - } - - # select filename, conform with (diff.info)Multiple patches - $prefix=; - if (!$fdst !$fsrc) { - error 'Index: not yet implemented'; - } elsif (!$fsrc || $fsrc eq '/dev/null') { - $f=$fdst; $prefix=PATCH-CREATE/; - } elsif (!$fdst || $fdst eq '/dev/null') { - $f=$fsrc; $prefix=PATCH-REMOVE/; - } elsif (($fdst eq /dev/null) ($fsrc eq /dev/null)) { - error Malformed diff; - } else { - # fewest path name components - if ($fdst=~s|/|/|g $fsrc=~s|/|/|g) { - $f=$fdst; - } elsif ($fdst=~s|/|/|g $fsrc=~s|/|/|g) { - $f=$fsrc; - } else { - #
cons.handler.c for FreeBSD
hi, there! Attached patch implements cons.handler.c for FreeBSD console. Tested on both FreeBSD 4.x and 5.x. /fjoe --- src/cons.handler.c.orig Mon Sep 23 13:43:23 2002 +++ src/cons.handler.c Wed Feb 26 22:09:57 2003 @@ -186,9 +186,8 @@ } } -#endif /* #ifdef linux */ +#elif defined(SCO_FLAVOR) -#ifdef SCO_FLAVOR /* ** SCO console save/restore handling routines ** Copyright (C) 1997 Alex Tkachenko [EMAIL PROTECTED] @@ -393,10 +392,212 @@ } } -#endif /* SCO_FLAVOR */ +#elif defined(__FreeBSD__) +/* + * FreeBSD support copyright (C) 2003 Alexander Serkov [EMAIL PROTECTED]. + * Support for screenmaps by Max Khon [EMAIL PROTECTED] + */ + +#include sys/consio.h +#include sys/errno.h +#include sys/fcntl.h +#include sys/ioctl.h -#if !defined(linux) !defined(__linux__) !defined(SCO_FLAVOR) +#include stdarg.h +#include stdio.h +#include syslog.h +#include unistd.h +#include osreldate.h + +#include dialog.h +#include wtools.h + +#define FD_OUT 1 + +static struct scrshot screen_shot; +static struct vid_info screen_info; +/* + * Color indexes returned by SCRSHOT differ from that ones VT220 accepts. + * color_map defines mapping from SCRSHOT colors to VT220. + */ +static int color_map[8] = { 0, 4, 2, 6, 1, 5, 3, 7 }; + +static void +console_init(void) +{ + if (console_flag) + return; + + screen_info.size = sizeof(screen_info); + if (ioctl(FD_OUT, CONS_GETINFO, screen_info) == -1) + return; + +#if __FreeBSD_version = 50 + screen_shot.x = 0; + screen_shot.y = 0; +#endif + screen_shot.xsize = screen_info.mv_csz; + screen_shot.ysize = screen_info.mv_rsz; + if ((screen_shot.buf = malloc( + screen_info.mv_csz * screen_info.mv_rsz)) == NULL) + return; + + console_flag = 1; +} + +static void +set_attr(unsigned attr) +{ + char cmd[17]; + int bc, tc; + + tc = attr 0xF; + bc = (attr 4) 0xF; + + strcpy(cmd, \x1B[); + strcat(cmd, (bc 8) ? 5; : 25;); + strcat(cmd, (tc 8) ? 1; : 22;); + strcat(cmd, 3%d;4%dm); + printf(cmd, color_map[tc 7], color_map[bc 7]); +} + +#define cursor_to(x, y) do { \ + printf(\x1B[%d;%df, (y) + 1, (x) + 1);\ + fflush(stdout); \ +} while (0) + +static void +console_restore(void) +{ + int i, last; + + if (!console_flag) + return; + + cursor_to(0, 0); + + /* restoring all content up to cursor position */ + last = screen_info.mv_row * screen_info.mv_csz + screen_info.mv_col; + for (i = 0; i last; ++i) { + set_attr((screen_shot.buf[i] 8) 0xFF); + putc(screen_shot.buf[i] 0xFF, stdout); + } + + /* restoring cursor color */ + set_attr((screen_shot.buf[last] 8) 0xFF); + + fflush(stdout); +} + +static void +console_shutdown(void) +{ + if (!console_flag) + return; + + free(screen_shot.buf); + + console_flag = 0; +} + +static void +console_save(void) +{ + int i; + scrmap_t map; + scrmap_t revmap; + + if (!console_flag) + return; + + /* screen_info.size is already set in console_init() */ + if (ioctl(FD_OUT, CONS_GETINFO, screen_info) == -1) { + console_shutdown(); + return; + } + + /* handle console resize */ + if (screen_info.mv_csz != screen_shot.xsize + || screen_info.mv_rsz != screen_shot.ysize) { + console_shutdown(); + console_init(); + } + + if (ioctl(FD_OUT, CONS_SCRSHOT, screen_shot) == -1) { + console_shutdown(); + return; + } + + if (ioctl(FD_OUT, GIO_SCRNMAP, map) == -1) { + console_shutdown(); + exit(1); + } + + for (i = 0; i 256; i++) { + char *p = memchr(map.scrmap, i, 256); + revmap.scrmap[i] = p ? p - map.scrmap : i; + } + + for (i = 0; i screen_shot.xsize * screen_shot.ysize; i++) { + screen_shot.buf[i] = + (screen_shot.buf[i] 0xff00) | + (unsigned char) revmap.scrmap[screen_shot.buf[i] 0xff]; + } +} + +void +show_console_contents(int starty, unsigned char begin_line, +unsigned char end_line) +{ + int i, first, last; + + if (look_for_rxvt_extensions()) { + show_rxvt_contents(starty, begin_line, end_line); + return; + } + + if (!console_flag) + return; + + cursor_to(0, starty); + + first = starty * screen_info.mv_csz; + last = first + (end_line - begin_line + 1) * screen_info.mv_csz - 1; + for (i = first; i = last; ++i) { + set_attr((screen_shot.buf[i] 8) 0xFF); + putc(screen_shot.buf[i] 0xFF, stdout); + } + +
Re: Fixing a long standing bug in view.c
Hello, Philipp! view.c erroneously assumes it can easily malloc a file if mmap failed and passes view-s.st_size to g_malloc. But if largefile support has been enabled, view-s.st_size is a 64 bit value and thus possibly exceeds the limit of gulong which g_malloc takes for size. This patch fixes it. I've applied a much simple patch for this: /* Make sure view-s.st_size is not truncated when passed to g_malloc */ if ((gulong) view-s.st_size == view-s.st_size) view-data = (unsigned char *) g_malloc ((gulong) view-s.st_size); Thank you for reporting the problem! -- Regards, Pavel Roskin ___ Mc-devel mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/mc-devel
Re: Fixing a long standing bug in view.c
* Pavel Roskin ([EMAIL PROTECTED]) [20030226 19:08]: I've applied a much simple patch for this: /* Make sure view-s.st_size is not truncated when passed to g_malloc */ if ((gulong) view-s.st_size == view-s.st_size) view-data = (unsigned char *) g_malloc ((gulong) view-s.st_size); Yes, this sure is much simpler :) Just don't forget to view-data=NULL in the else branch as otherwise you'll get a segfault here: if (view-data != NULL) g_free (view-data); Thank you for reporting the problem! You're welcome. I had to fix this anyway to get a working mc package for the next version of SuSE Linux, and a fix accepted upstream is one fix less I have to maintain :) Philipp -- Philipp Thomas [EMAIL PROTECTED] SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nuremberg, Germany ___ Mc-devel mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/mc-devel
Re: cons.handler.c for FreeBSD
Hello, Max! Attached patch implements cons.handler.c for FreeBSD console. Tested on both FreeBSD 4.x and 5.x. Applied. Thank you! -- Regards, Pavel Roskin ___ Mc-devel mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/mc-devel
Re: Fixing a long standing bug in view.c
Yes, this sure is much simpler :) Just don't forget to view-data=NULL in the else branch as otherwise you'll get a segfault here: if (view-data != NULL) g_free (view-data); Thanks! Fixed. -- Regards, Pavel Roskin ___ Mc-devel mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/mc-devel
Re: Fixing a long standing bug in view.c
On Wed, Feb 26, 2003 at 01:08:34PM -0500, Pavel Roskin wrote: Hello, Philipp! view.c erroneously assumes it can easily malloc a file if mmap failed and passes view-s.st_size to g_malloc. But if largefile support has been enabled, view-s.st_size is a 64 bit value and thus possibly exceeds the limit of gulong which g_malloc takes for size. This patch fixes it. I've applied a much simple patch for this: /* Make sure view-s.st_size is not truncated when passed to g_malloc */ if ((gulong) view-s.st_size == view-s.st_size) view-data = (unsigned char *) g_malloc ((gulong) view-s.st_size); Shouldn't that be g_try_malloc? mc died on me today when trying to view a 2.8GB file, I assume because mmap failed and g_malloc kills the application if it fails... Jakub ___ Mc-devel mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/mc-devel
Re: cons.handler.c for FreeBSD
hi, there! On Wed, Feb 26, 2003 at 02:16:14PM -0500, Pavel Roskin wrote: Attached patch implements cons.handler.c for FreeBSD console. Tested on both FreeBSD 4.x and 5.x. Applied. Thank you! If you have the list of contributors please mention Alexander Serkov [EMAIL PROTECTED]. He did most of the work. /fjoe ___ Mc-devel mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/mc-devel