scotties walk under SCO Unix

Hans Bayle (hansb@aie.nl)
Mon, 24 Apr 1995 16:43:32 -0700

Hi,

Finally got the place in the code where scotties walk is going wrong on SCO.
During getnext queries, some parts of the OID
in the snmp udp (especially 193, part of our ip address) are encoded wrong.
I experimented a bit with the asn1.c file, but was not able to determine if
it is a bug in the code
or in the compiler. I experimented with intermediary steps and dummy
variables but the bug stayed there.

For some reason the combination of the bitwise AND operation of 129 and the
BIT_8 mask with the increment
operator did not work in this piece of code with my compiler (native cc on
SCO ODT 3.0)
When I replaced this with " (*packet++ - 128) ", 129/65 decodes right and
the walk will work.

/* decode the subidentifer */

while (asnlen > 0) {
memset ((char *)op, '\0', sizeof (oid)); /* initialise */
while (*packet > 0x7F) { /* *packet > 127 */
*op = ( *op << 7 ) + (*packet++ - 128); /*ripoff8thbit 128 */
asnlen -= 1;
*packetlen += 1;
}

*op = ( *op << 7 ) + ( *packet++ );
op += 1;
*oidlen += 1;
asnlen -= 1;
*packetlen += 1;
}

return packet;
}

The funny thing is, that the following piece of code does not give problems:

#include <stdio.h>
#include <sys/types.h>
#define BIT_8 ( 0x80 )

main(int argc, char **argv)
{

u_int test[20];
u_int *ptr;
u_int oid;
u_int *op;

ptr=test;
op=&oid;

test[0] = 129;
test[1] = 65;

memset((char *)op, '\0', sizeof(oid));
printf("this is not a bug %u\n", (*ptr & ~BIT_8));
*op = ( *op << 7 ) + (*ptr++ & ~BIT_8);
*op = ( *op << 7 ) + ( *ptr++ );
printf("this is not a bug %u\n", *op);

}

| Hans Bayle |
| hansb@aie.nl | Shut your mouth or unveil this mystery to me :)
| AI Engineering |
| +31 20 6750415 |