mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-22 16:19:20 +02:00
Make sure that readlong/putlong uses 32 bits
This commit is contained in:
parent
3f0dbf5ce5
commit
51f3d75d2d
3
dns.c
3
dns.c
|
@ -26,6 +26,7 @@
|
|||
#include <time.h>
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
|
@ -286,7 +287,7 @@ int
|
|||
dns_parse_reply(char *outbuf, int buflen, char *packet, int packetlen)
|
||||
{
|
||||
int rv;
|
||||
long ttl;
|
||||
uint32_t ttl;
|
||||
short rlen;
|
||||
short type;
|
||||
short class;
|
||||
|
|
22
read.c
22
read.c
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
static int
|
||||
readname_loop(char *packet, int packetlen, char **src, char *dst, size_t length, size_t loop)
|
||||
|
@ -95,19 +95,20 @@ readshort(char *packet, char **src, short *dst)
|
|||
}
|
||||
|
||||
int
|
||||
readlong(char *packet, char **src, long *dst)
|
||||
readlong(char *packet, char **src, uint32_t *dst)
|
||||
{
|
||||
// A long as described in dns protocol is always 32 bits
|
||||
unsigned char *p;
|
||||
|
||||
p = *src;
|
||||
|
||||
*dst = ((long)p[0] << 24)
|
||||
| ((long)p[1] << 16)
|
||||
| ((long)p[2] << 8)
|
||||
| ((long)p[3]);
|
||||
*dst = ((uint32_t)p[0] << 24)
|
||||
| ((uint32_t)p[1] << 16)
|
||||
| ((uint32_t)p[2] << 8)
|
||||
| ((uint32_t)p[3]);
|
||||
|
||||
(*src) += sizeof(long);
|
||||
return sizeof(long);
|
||||
(*src) += sizeof(uint32_t);
|
||||
return sizeof(uint32_t);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -147,8 +148,9 @@ putshort(char **dst, short value)
|
|||
}
|
||||
|
||||
int
|
||||
putlong(char **dst, long value)
|
||||
putlong(char **dst, uint32_t value)
|
||||
{
|
||||
// A long as described in dns protocol is always 32 bits
|
||||
unsigned char *p;
|
||||
|
||||
p = *dst;
|
||||
|
@ -159,7 +161,7 @@ putlong(char **dst, long value)
|
|||
*p++ = (value);
|
||||
|
||||
(*dst) = p;
|
||||
return sizeof(long);
|
||||
return sizeof(uint32_t);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
4
read.h
4
read.h
|
@ -19,12 +19,12 @@
|
|||
|
||||
int readname(char *, int, char **, char *, size_t);
|
||||
int readshort(char *, char **, short *);
|
||||
int readlong(char *, char **, long *);
|
||||
int readlong(char *, char **, uint32_t *);
|
||||
int readdata(char *, char **, char *, size_t);
|
||||
|
||||
int putbyte(char **, char);
|
||||
int putshort(char **, short);
|
||||
int putlong(char **, long);
|
||||
int putlong(char **, uint32_t);
|
||||
int putdata(char **, char *, size_t);
|
||||
|
||||
#endif
|
||||
|
|
13
test.c
13
test.c
|
@ -23,6 +23,7 @@
|
|||
#include <arpa/nameser8_compat.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
@ -73,10 +74,10 @@ static void
|
|||
test_readputlong()
|
||||
{
|
||||
char buf[4];
|
||||
long putint;
|
||||
long tempi;
|
||||
long tint;
|
||||
long *l;
|
||||
uint32_t putint;
|
||||
uint32_t tempi;
|
||||
uint32_t tint;
|
||||
uint32_t *l;
|
||||
char* p;
|
||||
int i;
|
||||
|
||||
|
@ -89,13 +90,13 @@ test_readputlong()
|
|||
p = buf;
|
||||
putlong(&p, tint);
|
||||
l = &putint;
|
||||
memcpy(l, buf, sizeof(int));
|
||||
memcpy(l, buf, sizeof(uint32_t));
|
||||
if (putint != tempi) {
|
||||
printf("Bad value on putlong for %d\n", i);
|
||||
exit(2);
|
||||
}
|
||||
l = &tempi;
|
||||
memcpy(buf, l, sizeof(int));
|
||||
memcpy(buf, l, sizeof(uint32_t));
|
||||
p = buf;
|
||||
readlong(NULL, &p, &tempi);
|
||||
if (tempi != tint) {
|
||||
|
|
Loading…
Reference in New Issue