Wednesday, February 29, 2012

How to run with JRE 1.4.2 on Linux

I needed to test an old applet against Java 1.4.2, so I went on the question of running Firefox on Linux with JRE 1.4.2.

First of all, Oracle requires registering:

The first page led me to this download page which required that I register, so I did, and was finally able to download the file j2re-1_4_2_19-linux-i586.bin

I put the file on a Fedora 32-bit virtual machine and extracted it by running

chmod +x j2re-1_4_2_19-linux-i586.bin
./j2re-1_4_2_19-linux-i586.bin

After clicking through the license agreement, the directory j2re1.4.2_19 was created.

I used this page to determine the plugin directory on Linux:

$HOME/.mozilla/plugins
program_directory/plugins
/usr/lib/mozilla/plugins
/usr/lib/xulrunner/plugins

So I started by

cd ~/.mozilla/plugins
ln -s /home/javasux/j2re1.4.2_19/plugin/i386/ns4/libjavaplugin.so .

But when I ran Firefox, and browsed to about:plugins, it gave me the following error:

LoadPlugin: failed to initialize shared library /home/javasux/j2re1.4.2_19/plugin/i386/ns4/libjavaplugin.so [/home/javasux/j2re1.4.2_19/plugin/i386/ns4/libjavaplugin.so: cannot restore segment prot after reloc: Permission denied]
LoadPlugin: failed to initialize shared library /home/javasux/j2re1.4.2_19/plugin/i386/ns4/libjavaplugin.so [/home/javasux/j2re1.4.2_19/plugin/i386/ns4/libjavaplugin.so: cannot restore segment prot after reloc: Permission denied]
[WARN 10071] polkit-session.c:144:polkit_session_set_uid(): session != NULL
 Not built with -rdynamic so unable to print a backtrace

I could not figure out what the problem was. There are other posts linking to this problem, but none of them have a solution that worked for me. What did work for me was following the directions in this post and running:

/usr/sbin/setenforce 0

Now when Firefox ran, it showed me two Java plugins! The system Java plugin, and the 1.4.2 plugin I had installed. Going to this and this website confirmed that I was running Java 1.6, when I wanted 1.4.2.

So, I temporarily disabled the Java version on my system by running the following commands:

sudo mv /usr/lib/mozilla/plugins/libjavaplugin.so /usr/lib/mozilla/plugins/libjavaplugin.so.bak
sudo mv /etc/alternatives/libjavaplugin.so /etc/alternatives/libjavaplugin.so.bak

Now when I run Firefox, about:plugins shows me the 1.4.2 plugin loaded, but the test websites tell me that I don't have Java installed!

The java.com website says that I need Java 6 Update 10 and above for Firefox 3.6 and later versions. Well, I'm running Firefox 3.5b4, but maybe they're on to something, so upon searching, I find the Mozilla download for Firefox 3.0.19.

wget ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/3.0.19-real-real/linux-i686/en-US/firefox-3.0.19.tar.bz2  
tar xfj firefox-3.0.19.tar.bz2
cd firefox
./firefox

It's still not working! So I'm giving up and finding a machine that already has an old Firefox installed with an old Java version.

Friday, February 17, 2012

Password Check - NYTimes.com

Password Check - NYTimes.com: That’s right, a deputized LOLcat is about to haz a warrant for your arrest.
Oh nytimes you

Tuesday, February 14, 2012

Cross-compiling Perl for MIPS/ARM etc.

Here's me trying to cross-compile Perl for MIPS. I gave up eventually, but you may have better luck.

Instructions

  1. Save patch file to my-compile-perl-001.patch
  2. Save script to, say, my-compile-perl.sh
  3. ./my-compile-perl.sh
When asked for Any additional cc flags? [none], enter -fno-strict-aliasing
When asked Do you wish to use dynamic loading? [y], enter n
Tweak a few more answers, but you can hit Enter and accept the
default for most. It still asks for remote root password
sometimes, not sure why.

Thursday, February 9, 2012

GCC and unsigned enumerations

Enumerations in C are signed or unsigned in GCC depending on whether
one of the values is negative. This prohibits forward-looking checks
that expect that enumerations may include a negative value in the
future.

For example, say we had silly color_t enumeration:

typedef enum { RED = 0, GREEN = 1 } color_t;
const char * string_of_color (color_t color) {
    static const char * colors[2] = { "RED", "GREEN" };
    return colors[color];
}
int main(void) {
    printf("Color: %s\n", string_of_color(0));
}

The output will be:

Color: RED

The program may crash if main was to call string_of_color(10). So we'll put in a check:

typedef enum { RED = 0, GREEN = 1 } color_t;
const char * string_of_color (color_t color) {
    static const char * colors[2] = { "RED", "GREEN" };
    if (color < 0 || color > 1) return "INVALID";
    return colors[color];
}
int main(void) {
    printf("Color: %s\n", string_of_color(0));
}

But now GCC complains:

warning: comparison of unsigned expression < 0 is always false

This breaks things because I might expect that we'd change the color enumeration to:

typedef enum { INVALID = -1, RED = 0, GREEN = 1 } color_t;

Now my check is valid and GCC doesn't complain. My workaround?

if ((int)color < 0 || color > 1) return "INVALID";

Another possible workaround is to add a negative value in color_t or use a GCC compile-time option.

Monday, February 6, 2012

Data independent memcmp

My try at validating the memcmp function from this Tor diff using Frama-C. The loop_precondition is what I'm stuck on.
/*@ predicate IsValidRange( unsigned char *a, integer n ) =   @     ( 0 <= n ) && \valid_range( a, 0, n - 1 );
  @*/
/*@ requires \valid(x) && \valid(y);
  @ assigns nothing;
  @ 
  @ behavior zero_length:
  @  assumes len == 0;
  @  ensures \result == 0;
  @
  @ behavior equal:
  @  assumes len > 0;
  @  assumes x_y_equal : \forall integer n;
  @     0 <= n < len ==> x[n] == y[n];
  @  requires IsValidRange(x, len);
  @  requires IsValidRange(y, len);
  @  ensures \result == 0;
  @
  @ behavior not_equal:
  @  assumes len > 0;
  @  assumes x_y_not_equal : \exists integer n;
  @    0 <= n < len ==> x[n] != y[n];
  @  requires IsValidRange(x, len);
  @  requires IsValidRange(y, len);
  @  ensures \result != 0;
  @
  @ complete behaviors zero_length, equal, not_equal;
  @ disjoint behaviors zero_length, equal, not_equal;
  @*/
int
tor_memcmp(const unsigned char *x, const unsigned char *y, unsigned int len)
{
    unsigned int i = len;
    int retval = 0, newval;
    if (len == 0) return 0;
    while (i--) {
        //@ assert loop_precondition: (retval == 0) || (\exists integer n; i < n < len && x[i] != y[i]);
        int v1 = x[i];
        int v2 = y[i];
        int equal_p = v1 ^ v2;
        //@ assert (x[i] == y[i] && equal_p == 0) || (x[i] != y[i] && 0 < equal_p <= 255);
        // relies on two's complement!
        --equal_p;
        //@ assert (x[i] == y[i] && equal_p == -1) || (x[i] != y[i] && 0 <= equal_p < 255);
        // relies on signed right shift!
        equal_p >>= 8;
        //@ assert (x[i] == y[i] && equal_p == -1) || (x[i] != y[i] && equal_p =>= 0);
        newval = retval & equal_p;
        //@ assert (x[i] == y[i] && retval == newval) || (x[i] != y[i] && newval == 0);
        retval = newval;
        newval = retval + (v1 - v2);
        //@ assert (x[i] == y[i] && newval == retval) || (x[i] != y[i] && newval == (v1 - v2));
        retval = newval;
    }   
    return retval;
}

Thursday, February 2, 2012

IBM takes on Google and Microsoft with a cloud based service called IBM Docs

IBM takes on Google and Microsoft with a cloud based service called IBM Docs | Hacker News: I think the word "Lotus" on this is going to kill it dead before it even gets of the ground. There is almost universal hatred for that brand (other than from a few people who paid for it and don't have to use products from that division of IBM).

It's literally like branding your new product with swastikas.
Morning laughs

Wednesday, February 1, 2012

Types of random numbers

While reading these slides I came upon the following classification of random numbers:
  • "Real" random numbers: use a physical source of randomness
  • Pseudo-random numbers: deterministic sequence that passes tests of
    randomness
  • Quasi-random numbers: well distributed (low discrepancy) points
I hadn't heard about quasi-random numbers before. Wikipedia links
to low-discrepancy sequence and has diagrams that point out the difference.

"Real" random numbers are often used in cryptographic applications, and
pseudo-random numbers are used all over the place in simulations and
games.
random.org has a good overview for the other two types:

CharacteristicPseudo-randomReal-random
EfficiencyExcellentPoor
DeterminismDeterministicNon-deterministic
PeriodicityPeriodicAperiodic