Print Story It's been a while
Working life
By creo (Tue Aug 24, 2004 at 02:32:01 AM EST) (all tags)
Things have been busy what with the trip to Scotchlandia, another trip to Stockholm and having my Bank account access removed - but what got me motivated to write again is my recent requirement to port a C program to the Tandem.

So it was reacquint myself with C - and yep, it still sucks hairy goat balls.

Now I'm not against low level languages - I mean my working language has data type such as byte (8 bits), int (16 bits) and int(32) (32 bits) - it does not even have character typing or string handling. Eerily enough this makes string handling far easier than C, as you *know* that you have to use pointer arithmetic to work out string lengths, instead of relying on an amorphous null that may or may not be at the end of the string.

Now the Tandem is, shall we say, unusual. Basically you are restricted to a volume/directory/file structure, where file names cannot be longer than 8 bytes. The volume is a synonym for a physical disk - although in a burst of modernism we actually have virtual disks on some systems these days - but not on this one. Mind you, this is only 1 personality - their is another personality called OSS, which is an implementation of a UNIX like structure on top of the standard file system. So it's a single layer file system - it makes for interesting naming conventions...

So, the task. Basically it's a software implementation of DES, working out the CBC MAC of an input file. Now before some smarty says something like "Use EAYs DES lib or Gutmann's cryptlib" - refer to above. So I'm stuck with this thing. Even worse is that it is reading the file in 64 byte blocks, so it is slow as a wet week. Anyway, the thing works fine on small files, but breaks on larger files - so it's wade through someone elses butchered software DES implementation - great.

It quickly becomes obvious that the same person who wrote the scaffolding code did not write the DES stuff. The DES stuff is neat and concise - the scaffold code is pretty crap. Anyway I finally track it down to the following:

the decs

int retc=0;
int int_lgd;
char str_lgd[2];

unsigned char acc_mac[8];
unsigned char bposmac[8];

the code

case MIDDLE:
/* Check length of restdata in chaningvector */
/*int_lgd = atoi( memcpy(str_lgd,chaning_vector,2) ); */
memcpy(str_lgd,chaning_vector,2) );
int_lgd = atoi( str_lgd );
/* if ( (int_lgd <0) || (int_lgd> 7) )
retc = 3;

Of course the problem is that str_lgd is only 2 bytes for a 2 digit number - so atoi keeps going if the first byte of acc_mac is an ascii digit. I don't know if I was more pissed at stupid C, spastic atoi or retard programmer. The weird thing is this exact code runs fine on my loonix PC - a difference in the atoi implementations I guess. The fact that it broke in differing places for different files made me chase the illusion that it was a size issue, not the classic missing null thing.

This program is about 3000 lines long, and pretty dense - I implemented it in Python using cryptlib in about 30. The best thing is that the cryptlib imp you can just change the algorithm via a parameter. it's just a shame that there is no snake on the Tandem. Even worse is that there is no C compiler on our machine in the OSS personality, so I could not even attempt to try and build cryptlib. The C compiler on the guardian personality is that old that it does not even recognise // comments. Before I get flamed by all the C people I think my biggest beef is the really crap C implementation I was working with - it almost made C look good on HPUX - heh, HP now owns Tandem, conincidence? I think not.

Just briefly - had a great time in Scotchlandia, did the usual drive through the lochs and highland country. Drove through Rannoch Moor in the evening with pissing down rain and mist - the only thing missing was a bunch of clansmen with claymores.

More work
The boss is over here on Thursday - he warned me to have my beer hat ready for Thursday night - not a bad way to spend your birthday, drinking the bosses piss.

Fun Links Just weird stuff you pick up on the net:
This one brought back a few memories.

I liked this one - just for our US friends...

I think the effect would be better if the guy had rimless glasses and a leather overcoat, with a black Merc in the background, but it's good enough...

< Just another trip on the short bus... | BBC White season: 'Rivers of Blood' >
It's been a while | 14 comments (14 topical, 0 hidden) | Trackback
I forgot one by creo (3.00 / 0) #1 Tue Aug 24, 2004 at 02:46:30 AM EST
Probably the best link - and a perfect example of how if the stupid entertainment industries didn't draw attention to the sites they want to shut down then the "pirate" would not get half their traffic.

Anyway, the response of the Swedish website (a supplier of torrent links) to a DMCA take down request.

Ha Ha

"I shall do what I believe to be right and honourable" - Guderian

atoi considered SPAWN OF SATAN by Rogerborg (3.00 / 0) #2 Tue Aug 24, 2004 at 02:54:45 AM EST
Consider that we use C on about a dozen different platforms.  Can you see why we'd go to the bother of writing our own stdlib, just so the damn thing works consistently?

Metus amatores matrum compescit, non clementia.
Whoa. by i (3.00 / 0) #3 Tue Aug 24, 2004 at 03:00:09 AM EST
Long story short, atoi doesn't work, strtol does, so please use that, kthx.

[ Parent ]
int atoi(const char * string) by Rogerborg (3.00 / 0) #5 Tue Aug 24, 2004 at 03:08:10 AM EST
    return (int)strol(string, NULL, 0);

Metus amatores matrum compescit, non clementia.
[ Parent ]
Without the typo, I mean [n/t] by Rogerborg (5.50 / 2) #6 Tue Aug 24, 2004 at 03:08:35 AM EST

Metus amatores matrum compescit, non clementia.
[ Parent ]
Also without by i (3.00 / 0) #8 Tue Aug 24, 2004 at 04:14:18 AM EST
detecting errors.

[ Parent ]
If you want the real code by Rogerborg (3.00 / 0) #9 Tue Aug 24, 2004 at 04:16:08 AM EST
Our licensing terms are suprisingly usurious!

Metus amatores matrum compescit, non clementia.
[ Parent ]
No, no, no. by i (3.00 / 0) #10 Tue Aug 24, 2004 at 04:24:18 AM EST
atoi() must ignore errors. The standard demands it. That's the reason it's broken.

[ Parent ]
*Which* standard demands it? by Rogerborg (3.00 / 0) #11 Tue Aug 24, 2004 at 04:26:23 AM EST
Uh oh!

Metus amatores matrum compescit, non clementia.
[ Parent ]
The C standard. by i (3.00 / 0) #12 Tue Aug 24, 2004 at 04:34:32 AM EST
As published by ANSI and ISO.

[ Parent ]
Hahah, no, but seriously by Rogerborg (3.00 / 0) #14 Tue Aug 24, 2004 at 05:36:27 AM EST
Which one?  Can you point at it?

Metus amatores matrum compescit, non clementia.
[ Parent ]
Um... by i (6.00 / 1) #13 Tue Aug 24, 2004 at 04:54:27 AM EST
I've got it wrong, atoi() doesn't have to set errno, though it might. This doesn't change the basic conclusion about its brokenness.

[ Parent ]
I had vague recollections by creo (6.00 / 1) #4 Tue Aug 24, 2004 at 03:07:12 AM EST
that a lot of the standard C type functions were considered evil. The man pages I read on the loonix box basically screamed that atoi was not a good thing. At least the loonix implementation had man pages -the stuff on the Tandem is like a black box, no man pages and the manual is a programmers guide, moreso than a programmers reference...I only found out the behaviour through experiementation.

You know what it's like with someone elses code though - you just want the thing to work. I think I'm going to have to go through it now and make sure that there are no other litle presents like that one waiting to bite my butt.

I love maintenance programming...especially in languages I'm rusty in on a platform which is obscure and that I have never used it on.


"I shall do what I believe to be right and honourable" - Guderian

[ Parent ]
Clansmen with claymores by DullTrev (3.00 / 0) #7 Tue Aug 24, 2004 at 03:18:17 AM EST

They were there, waiting... Never stop your car when driving through the heathen Scotchlandia. It's too dangerous.

It's been a while | 14 comments (14 topical, 0 hidden) | Trackback