Skip to content

Loading…

Fix compilation with clang, work around double free #6

Merged
merged 2 commits into from

2 participants

@fuzxxl
Collaborator

These patches fix two things

  • there is some point in the code that does a double free. As I was not able to fix that, the first patch turns off automatic abortion in case of double free. This fixes bug #1.
  • Some functions that are not declared void return without a value. Fix that by returning a dummy value. This makes compilation with clang possible
fuzxxl added some commits
@fuzxxl fuzxxl Workaround double free problems
The source code for handling images has a double free problem. Recent versions
of the GNU libc have a mechanism to automagically abort the program in such a
case. This causes Mosaic to crash if images are displayed.

I work around this issue by turning of automatical program abortion with a call
to mallopt().
2b5f8dc
@fuzxxl fuzxxl Enable compilation with clang
Some functions that ought to return a value call return without any value. This
commit adds a dummy value to each of those returns so that clang stops
complaining.
a00b1bd
@alandipert alandipert merged commit c89d60c into alandipert:master
@alandipert
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 9, 2013
  1. @fuzxxl

    Workaround double free problems

    fuzxxl committed
    The source code for handling images has a double free problem. Recent versions
    of the GNU libc have a mechanism to automagically abort the program in such a
    case. This causes Mosaic to crash if images are displayed.
    
    I work around this issue by turning of automatical program abortion with a call
    to mallopt().
  2. @fuzxxl

    Enable compilation with clang

    fuzxxl committed
    Some functions that ought to return a value call return without any value. This
    commit adds a dummy value to each of those returns so that clang stops
    complaining.
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 15 deletions.
  1. +10 −10 libhtmlw/HTML.c
  2. +2 −2 libhtmlw/HTMLformat.c
  3. +2 −2 libhtmlw/HTMLtable.c
  4. +1 −1 libwww2/HTNews.c
  5. +9 −0 src/main.c
View
20 libhtmlw/HTML.c
@@ -741,13 +741,13 @@ XGCValues values;
hw->html.bgclip_SAVE=None;
if (NoBodyImages(hw)) {
- return;
+ return 0;
}
/* ??? Why is this here? */
hw->html.view->core.background_pixel = hw->html.background_SAVE ;
- return;
+ return 0;
}
int NoBodyImages(Widget w) {
@@ -770,7 +770,7 @@ unsigned long valuemask;
XGCValues values;
if (!bgname || !*bgname || !(hw->html.drawGC)) {
- return;
+ return 0;
}
if (hw->html.delay_images==True || currently_delaying_images==1) {
@@ -814,7 +814,7 @@ XGCValues values;
}
}
- return;
+ return 0;
}
@@ -832,7 +832,7 @@ hw_do_color(Widget w, char *att, char *cname)
int i;
if (!att || !*att || !cname || !*cname) {
- return;
+ return -1;
}
cmap = hw->core.colormap;
@@ -847,14 +847,14 @@ hw_do_color(Widget w, char *att, char *cname)
if(!allocated){
if(*val=='#') val++;
if (!*val) {
- return;
+ return -1;
}
if (strlen(val)>=6) {
/* Must be valid hex */
for (i=0; i<6; i++) {
if (!strchr("0123456789AaBbCcDdEeFf",val[i])) {
- return;
+ return -1;
}
}
@@ -875,10 +875,10 @@ hw_do_color(Widget w, char *att, char *cname)
col.flags = DoRed | DoGreen | DoBlue;
if (!XAllocColor(XtDisplay(w),cmap,&col)) {
- return;
+ return -1;
}
} else {
- return;
+ return -1;
}
}
@@ -910,7 +910,7 @@ hw_do_color(Widget w, char *att, char *cname)
hw->html.activeAnchor_fg = col.pixel;
}
- return;
+ return -1;
}
void
View
4 libhtmlw/HTMLformat.c
@@ -2706,7 +2706,7 @@ int extra;
if ((*mptr)->is_end) {
/* end of table */
- return;
+ return 0;
}
extra = 10;
@@ -2715,7 +2715,7 @@ int extra;
SetElement(hw, E_TABLE, currentFont, *x, *y, (char *) mptr, NULL, NULL, IMAGE_DEFAULT_BORDER);
if (!Current->table_data) {
/* no table */
- return;
+ return 0;
}
Current->alignment = ALIGN_MIDDLE;
Current->width = Current->table_data->width;
View
4 libhtmlw/HTMLtable.c
@@ -1078,11 +1078,11 @@ int baseLine;
int yy;
if (field->type == F_NONE) { /* nothing to display in field */
- return;
+ return -1;
}
if (field->type != F_TEXT) { /* routine only does text at this time */
- return;
+ return -1;
}
/* adjust for aesthetic surounding space */
View
2 libwww2/HTNews.c
@@ -960,7 +960,7 @@ int NNTPgetarthdrs(char *art,char **ref, char **grp, char **subj, char **from)
char ch = *p++ = HTGetCharacter ();
if (ch==(char)EOF) {
abort_socket(); /* End of file, close socket */
- return; /* End of file on response */
+ return -1; /* End of file on response */
}
if ((ch == LF)
View
9 src/main.c
@@ -71,6 +71,7 @@
#include <signal.h>
#include <sys/utsname.h>
#include <string.h>
+#include <malloc.h>
/* swp */
#define _KCMS_H_
@@ -231,6 +232,14 @@ main (int argc, char **argv, char **envp)
/* Since we're doing lots of TCP, just ignore SIGPIPE altogether. */
signal (SIGPIPE, SIG_IGN);
+#ifdef M_CHECK_ACTION
+ /* some code here has the habit of freeing pointers twice. The glibc
+ catches this and causes the program to abort. In order to make the
+ code somehow work, we turn aborting the program off. */
+
+ mallopt(M_CHECK_ACTION,5);
+#endif
+
InitChildProcessor();
MoCCIPreInitialize();
Something went wrong with that request. Please try again.