aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/plugin/infoleak-pr112969.c
blob: e78fe3659759f4cb0116e6ff1a51a3943fa27319 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* Reduced from -Wanalyzer-exposure-through-uninit-copy false positives
   seen in Linux kernel in drivers/net/ethernet/intel/ice/ice_ptp.c  */

/* { dg-do compile } */
/* { dg-options "-fanalyzer" } */
/* { dg-require-effective-target analyzer } */

extern unsigned long
copy_from_user(void* to, const void* from, unsigned long n);

extern unsigned long
copy_to_user(void* to, const void* from, unsigned long n);

struct ifreq
{
  union
  {
    void* ifru_data;
  } ifr_ifru;
};

struct hwtstamp_config
{
  int flags;
  int tx_type;
  int rx_filter;
};

struct ice_ptp
{
  long placeholder;
  struct hwtstamp_config tstamp_config;
};

struct ice_pf
{
  struct ice_ptp ptp;
};
int
ice_ptp_set_ts_config(struct ice_pf* pf, struct ifreq* ifr)
{
  struct hwtstamp_config config;
  int err;
  if (copy_from_user(&config, ifr->ifr_ifru.ifru_data, sizeof(config)))
    return -14;
  pf->ptp.tstamp_config.tx_type = 0;
  pf->ptp.tstamp_config.rx_filter = 0;
  config = pf->ptp.tstamp_config;
  if (copy_to_user(ifr->ifr_ifru.ifru_data, &config, sizeof(config))) /* { dg-bogus "-Wanalyzer-exposure-through-uninit-copy" "PR analyzer/112969" } */
    return -14;
  return 0;
}