[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#374195: Can't do anything: "terminate called after throwing an instance of 'std::logic_error'"



On Thu, Jun 29, 2006 at 03:43:44PM +0300, Marius Vollmer wrote:
> I have seen this bug in version 0.6.42.3 and in my case the
> "terminate" output was due to a bug in DPkgPM::Go.  That function
> fails to parse status outputs from dpkg that span more than one line.
> 
> Specifically, this dpkg output causes DPkgPM::Go to crash (two lines):
> 
> status: big : error : Package is in a very bad inconsistent state - you should
>  reinstall it before attempting a removal.
> 
> Note the second line that starts with a space.  DPkgPM::Go can't deal
> with that; it doesn't expect continuation lines at all.  Concretely,
> it is not checking that the call to TokSplitString actually has found
> the expected fields.  (Bad boy!  Go to bed without dinner!)
> 
> Using dpkg --force-remove-reinstreq just gets rid of the problematic
> package and thus the bug is not triggered anymore.
> 
> Fixing the crash by simply ignoring the second line is of course the
> easy and wrong solution.  DPkgPM::Go should be able to deal with
> continuation lines like this.

Thanks for your bugreport and the detailed analysis. I'm in the middle
of catching up with the bugreports after being on vacation and
commited the easy and wrong solution for now (because it has to be
added anyway to make it a bit more robust against bogus data).

I think dpkg should be patched to strip out the \n from the messages
that it sends over the status pipe. The GUI frontends that use those
messages will not make a lot of use from those "\n" anyway.

I attached a patch for dpkg to strip out the \n when it sends errors
over the status pipe. Comments welcome. 

Cheers,
 Michael

-- 
Linux is not The Answer. Yes is the answer. Linux is The Question. - Neo
diff -Nru /tmp/ZTgF8wNNud/dpkg-1.13.22ubuntu4/src/errors.c /tmp/uECXKIITPT/dpkg-1.13.22ubuntu5/src/errors.c
--- /tmp/ZTgF8wNNud/dpkg-1.13.22ubuntu4/src/errors.c	2006-01-18 09:30:03.000000000 +0100
+++ /tmp/uECXKIITPT/dpkg-1.13.22ubuntu5/src/errors.c	2006-07-25 10:47:10.000000000 +0200
@@ -54,6 +54,7 @@
 
 void print_error_perpackage(const char *emsg, const char *arg) {
   struct error_report *nr;
+  char *striped_emsg, *c;
   
   fprintf(stderr, _("%s: error processing %s (--%s):\n %s\n"),
           DPKG, arg, cipaction->olong, emsg);
@@ -68,11 +69,18 @@
      } else
 	varbufreset(status);
 
-     r= varbufprintf(status, "status: %s : %s : %s\n", arg, "error",emsg);
+     /* when using the pipe, replace the '\n' with ' ' */
+     striped_emsg = strdup(emsg);
+     if(!striped_emsg)
+	ohshit("Can't allocate memory");
+     for(c = striped_emsg; *c; c++) if(*c == '\n') *c = ' ';
+     r= varbufprintf(status, "status: %s : %s : %s\n", arg, "error",
+		     striped_emsg);
      while (pipef) {
 	write(pipef->fd, status->buf, r);
 	pipef= pipef->next;
      }
+     free(striped_emsg);
   }
 
 

Reply to: