s3: smbd: Deliberately currupt an uninitialized pointer.
[Samba.git] / lib / util / util_str_hex.c
blob553fb30681ef69cb20bbf810c42c7a5374a0ca0d
1 #include "replace.h"
2 #include "util_str_hex.h"
3 #include "lib/util/data_blob.h"
4 #include "librpc/gen_ndr/misc.h"
6 static bool hex_uint16(const char *in, uint16_t *out)
8 uint8_t hi=0, lo=0;
9 bool ok = hex_byte(in, &hi) && hex_byte(in+2, &lo);
10 *out = (((uint16_t)hi)<<8) + lo;
11 return ok;
14 bool hex_uint32(const char *in, uint32_t *out)
16 uint16_t hi=0, lo=0;
17 bool ok = hex_uint16(in, &hi) && hex_uint16(in+4, &lo);
18 *out = (((uint32_t)hi)<<16) + lo;
19 return ok;
22 bool parse_guid_string(const char *s, struct GUID *guid)
24 bool ok;
25 int i;
26 /* "e12b56b6-0a95-11d1-adbb-00c04fd8d5cd"
27 | | | | |
28 | | | | \ node[6]
29 | | | \_____ clock_seq[2]
30 | | \__________ time_hi_and_version
31 | \_______________ time_mid
32 \_____________________ time_low
35 ok = hex_uint32(s, &guid->time_low);
36 if (!ok || (s[8] != '-')) {
37 return false;
39 s += 9;
41 ok = hex_uint16(s, &guid->time_mid);
42 if (!ok || (s[4] != '-')) {
43 return false;
45 s += 5;
47 ok = hex_uint16(s, &guid->time_hi_and_version);
48 if (!ok || (s[4] != '-')) {
49 return false;
51 s += 5;
53 ok = hex_byte(s, &guid->clock_seq[0]) &&
54 hex_byte(s+2, &guid->clock_seq[1]);
55 if (!ok || (s[4] != '-')) {
56 return false;
58 s += 5;
60 for (i = 0; i < 6; i++) {
61 ok = hex_byte(s, &guid->node[i]);
62 if (!ok) {
63 return false;
65 s += 2;
68 return true;