Coverage Report

Created: 2025-11-16 06:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/samba/lib/util/util_str_hex.c
Line
Count
Source
1
#include "replace.h"
2
#include "util_str_hex.h"
3
#include "lib/util/data_blob.h"
4
#include "librpc/gen_ndr/misc.h"
5
6
static bool hex_uint16(const char *in, uint16_t *out)
7
417k
{
8
417k
  uint8_t hi=0, lo=0;
9
417k
  bool ok = hex_byte(in, &hi) && hex_byte(in+2, &lo);
10
417k
  *out = (((uint16_t)hi)<<8) + lo;
11
417k
  return ok;
12
417k
}
13
14
bool hex_uint32(const char *in, uint32_t *out)
15
104k
{
16
104k
  uint16_t hi=0, lo=0;
17
104k
  bool ok = hex_uint16(in, &hi) && hex_uint16(in+4, &lo);
18
104k
  *out = (((uint32_t)hi)<<16) + lo;
19
104k
  return ok;
20
104k
}
21
22
bool parse_guid_string(const char *s, struct GUID *guid)
23
104k
{
24
104k
  bool ok;
25
104k
  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
33
  */
34
35
104k
  ok = hex_uint32(s, &guid->time_low);
36
104k
  if (!ok || (s[8] != '-')) {
37
212
    return false;
38
212
  }
39
104k
  s += 9;
40
41
104k
  ok = hex_uint16(s, &guid->time_mid);
42
104k
  if (!ok || (s[4] != '-')) {
43
49
    return false;
44
49
  }
45
104k
  s += 5;
46
47
104k
  ok = hex_uint16(s, &guid->time_hi_and_version);
48
104k
  if (!ok || (s[4] != '-')) {
49
66
    return false;
50
66
  }
51
104k
  s += 5;
52
53
104k
  ok = hex_byte(s, &guid->clock_seq[0]) &&
54
103k
    hex_byte(s+2, &guid->clock_seq[1]);
55
104k
  if (!ok || (s[4] != '-')) {
56
148
    return false;
57
148
  }
58
103k
  s += 5;
59
60
726k
  for (i = 0; i < 6; i++) {
61
622k
    ok = hex_byte(s, &guid->node[i]);
62
622k
    if (!ok) {
63
134
      return false;
64
134
    }
65
622k
    s += 2;
66
622k
  }
67
68
103k
  return true;
69
103k
}