Re: undelfs warnings fix
- From: "Andrew V. Samoilov" <andrew email zp ua>
- To: Pavel Roskin <proski gnu org>
- Cc: mc-devel gnome org
- Subject: Re: undelfs warnings fix
- Date: Fri, 14 Nov 2003 17:37:50 +0200 (EET)
> > On Thu, 13 Nov 2003, Andrew V. Samoilov wrote:
> >
> > > Hello, Pavel!
> > >
> > > Small fix for last changes.
> >
> > The warnings have been fixed already. I'm not sure about com_err(). See
> > "man com_err". Maybe it's used to override com_err() from the library.
>
> It seems you are right about com_err(). Well, this patch cleans up argument
> names for com_err() and also fixes program termination if where is no enough
> memory while scanning deleted entries.
>
> As far as I remember there was some problems with g_malloc() & free() mixing,
> at least on FreeBSD, so I propose to define free as g_free() for glib2+,
> and use free() to release memory, allocated by malloc()/realloc() for
> glib 1.2.x. I fix this for undelfs, but view->data case in view.c is more
> complicated.
Previous patch implementation breaks mcfs compilation, and as I understood
recently current implementaion of com_err() is wrong and have format string
vulnerability.
New implementation fixes com_err() and does not define free, sorry about
glib and libc memory allocation function mix, but we have it for glib 1.2x.
already.
--
Regards,
Andrew V. Samoilov.
src/ChangeLog:
* glibcompat.h: Define g_try_realloc as realloc for glib 1.2.x.
vfs/ChangeLog:
* undelfs.c (undelfs_loaddel): Use g_try_malloc()/g_try_relloc()
since we want to recover and not abort the program if we don't
have enough memory.
(com_err): Fix implementation.
--- ChangeLog~ Tue Nov 11 14:20:01 2003
+++ ChangeLog Fri Nov 14 12:26:50 2003
@@ -257,7 +257,7 @@
* glibcompat.h: Define g_try_malloc as malloc for glib 1.2.x.
* view.c (load_view_file): Use g_try_malloc() because the
- failure to allcate memory is acceptable here.
+ failure to allocate memory is acceptable here.
Reported by Pavel S. Shirshov <pavelsh mail ru>
2003-10-14 Pavel Roskin <proski gnu org>
--- src/glibcompat.h~ Wed Oct 22 13:53:32 2003
+++ src/glibcompat.h Fri Nov 14 12:29:09 2003
@@ -21,6 +21,7 @@
#if GLIB_MAJOR_VERSION < 2
gsize g_strlcpy (gchar *dest, const gchar *src, gsize dest_size);
#define g_try_malloc(x) malloc(x)
+#define g_try_realloc(x) realloc(x)
#endif /* GLIB_MAJOR_VERSION < 2 */
#endif /* !__MC_GLIBCOMPAT_H */
--- vfs/undelfs.c~ Thu Nov 13 20:01:26 2003
+++ vfs/undelfs.c Fri Nov 14 12:14:04 2003
@@ -177,12 +177,12 @@ undelfs_loaddel (void)
max_delarray = 100;
num_delarray = 0;
- delarray = g_new (struct deleted_info, max_delarray);
+ delarray = g_try_malloc (sizeof (struct deleted_info) * max_delarray);
if (!delarray) {
message (1, undelfserr, _(" not enough memory "));
return 0;
}
- block_buf = g_malloc (fs->blocksize * 3);
+ block_buf = g_try_malloc (fs->blocksize * 3);
if (!block_buf) {
message (1, undelfserr, _(" while allocating block buffer "));
goto free_delarray;
@@ -224,15 +224,18 @@ undelfs_loaddel (void)
}
if (lsd.free_blocks && !lsd.bad_blocks) {
if (num_delarray >= max_delarray) {
- max_delarray += 50;
- delarray =
- g_renew (struct deleted_info, delarray, max_delarray);
- if (!delarray) {
+ struct deleted_info *delarray_new =
+ g_try_realloc (delarray,
+ sizeof (struct deleted_info) *
+ (max_delarray + 50));
+ if (!delarray_new) {
message (1, undelfserr,
_
(" no more memory while reallocating array "));
goto error_out;
}
+ delarray = delarray_new;
+ max_delarray += 50;
}
delarray[num_delarray].ino = ino;
@@ -269,12 +272,16 @@ undelfs_loaddel (void)
return 0;
}
-void com_err (const char *str, long err_code, const char *s2, ...)
+void com_err (const char *whoami, long err_code, const char *fmt, ...)
{
char *cptr;
+ va_list ap;
+
+ va_start (ap, fmt);
+ str = g_strdup_vprintf (fmt, ap);
+ va_end (ap);
- cptr = g_strdup_printf (" %s (%s: %ld) ", s2, str, err_code);
- message (1, _(" Ext2lib error "), cptr);
+ message (1, _(" Ext2lib error "), " %s (%s: %ld) ", cptr, whoami, err_code);
g_free (cptr);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]