/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to dracut-module/password-agent.c

  • Committer: Teddy Hogeborn
  • Date: 2023-02-11 06:58:15 UTC
  • Revision ID: teddy@recompile.se-20230211065815-jtffi61tbdrgr875
Suppress warnings

Suppress warnings about mlock()ing uninitialized memory and reading an
ievent struct.

* dracut-module/password-agent.c (send_password_to_socket): Suppress
  "-Wmaybe-uninitialized" when mlock()ing password send buffer.
  (test_read_inotify_event_IN_DELETE_badname): When reading from
    a struct ievent, suppress "-Wstringop-overread".

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
/*
3
3
 * Mandos password agent - Simple password agent to run Mandos client
4
4
 *
5
 
 * Copyright © 2019-2021 Teddy Hogeborn
6
 
 * Copyright © 2019-2021 Björn Påhlsson
 
5
 * Copyright © 2019-2022 Teddy Hogeborn
 
6
 * Copyright © 2019-2022 Björn Påhlsson
7
7
 * 
8
8
 * This file is part of Mandos.
9
9
 * 
1098
1098
  } ievent_buffer;
1099
1099
  struct inotify_event *const ievent = &ievent_buffer.event;
1100
1100
 
 
1101
#if defined(__GNUC__) and __GNUC__ >= 7
 
1102
#pragma GCC diagnostic push
 
1103
  /* ievent is pointing into a struct which is of sufficient size */
 
1104
#pragma GCC diagnostic ignored "-Wstringop-overflow"
 
1105
#endif
1101
1106
  const ssize_t read_length = read(fd, ievent, ievent_size);
 
1107
#if defined(__GNUC__) and __GNUC__ >= 7
 
1108
#pragma GCC diagnostic pop
 
1109
#endif
1102
1110
  if(read_length == 0){ /* EOF */
1103
1111
    error(0, 0, "Got EOF from inotify fd for directory %s", filename);
1104
1112
    *quit_now = true;
1480
1488
    if(send_buffer == NULL){
1481
1489
      error(0, errno, "Failed to allocate send_buffer");
1482
1490
    } else {
 
1491
#if defined(__GNUC__) and __GNUC__ >= 5
 
1492
#pragma GCC diagnostic push
 
1493
  /* mlock() does not access the memory */
 
1494
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
 
1495
#endif
1483
1496
      if(mlock(send_buffer, send_buffer_length) != 0){
 
1497
#if defined(__GNUC__) and __GNUC__ >= 5
 
1498
#pragma GCC diagnostic pop
 
1499
#endif
1484
1500
        /* Warn but do not treat as fatal error */
1485
1501
        if(errno != EPERM and errno != ENOMEM){
1486
1502
          error(0, errno, "Failed to lock memory for password"
2653
2669
  bool password_is_read = false;
2654
2670
  const char helper_directory[] = "/nonexistent";
2655
2671
  const char *const argv[] = { "/bin/sh", "-c",
2656
 
    "echo -n ${MANDOSPLUGINHELPERDIR}", NULL };
 
2672
    "printf %s \"${MANDOSPLUGINHELPERDIR}\"", NULL };
2657
2673
 
2658
2674
  const bool success = start_mandos_client(queue, epoll_fd,
2659
2675
                                           &mandos_client_exited,
4182
4198
  memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4183
4199
  const size_t ievent_size = (sizeof(struct inotify_event)
4184
4200
                              + sizeof(dummy_file_name));
 
4201
#if defined(__GNUC__) and __GNUC__ >= 11
 
4202
#pragma GCC diagnostic push
 
4203
  /* ievent is pointing into a struct which is of sufficient size */
 
4204
#pragma GCC diagnostic ignored "-Wstringop-overread"
 
4205
#endif
4185
4206
  g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4186
4207
                  ==, ievent_size);
 
4208
#if defined(__GNUC__) and __GNUC__ >= 11
 
4209
#pragma GCC diagnostic pop
 
4210
#endif
4187
4211
  g_assert_cmpint(close(pipefds[1]), ==, 0);
4188
4212
 
4189
4213
  bool quit_now = false;
4277
4301
  memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4278
4302
  const size_t ievent_size = (sizeof(struct inotify_event)
4279
4303
                              + sizeof(dummy_file_name));
 
4304
#if defined(__GNUC__) and __GNUC__ >= 11
 
4305
#pragma GCC diagnostic push
 
4306
  /* ievent is pointing into a struct which is of sufficient size */
 
4307
#pragma GCC diagnostic ignored "-Wstringop-overread"
 
4308
#endif
4280
4309
  g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4281
4310
                  ==, ievent_size);
 
4311
#if defined(__GNUC__) and __GNUC__ >= 11
 
4312
#pragma GCC diagnostic pop
 
4313
#endif
4282
4314
  g_assert_cmpint(close(pipefds[1]), ==, 0);
4283
4315
 
4284
4316
  bool quit_now = false;
4374
4406
  memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4375
4407
  const size_t ievent_size = (sizeof(struct inotify_event)
4376
4408
                              + sizeof(dummy_file_name));
 
4409
#if defined(__GNUC__) and __GNUC__ >= 11
 
4410
#pragma GCC diagnostic push
 
4411
  /* ievent is pointing into a struct which is of sufficient size */
 
4412
#pragma GCC diagnostic ignored "-Wstringop-overread"
 
4413
#endif
4377
4414
  g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4378
4415
                  ==, ievent_size);
 
4416
#if defined(__GNUC__) and __GNUC__ >= 11
 
4417
#pragma GCC diagnostic pop
 
4418
#endif
4379
4419
  g_assert_cmpint(close(pipefds[1]), ==, 0);
4380
4420
 
4381
4421
  bool quit_now = false;
4459
4499
  memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4460
4500
  const size_t ievent_size = (sizeof(struct inotify_event)
4461
4501
                              + sizeof(dummy_file_name));
 
4502
#if defined(__GNUC__) and __GNUC__ >= 11
 
4503
#pragma GCC diagnostic push
 
4504
  /* ievent is pointing into a struct which is of sufficient size */
 
4505
#pragma GCC diagnostic ignored "-Wstringop-overread"
 
4506
#endif
4462
4507
  g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4463
4508
                  ==, ievent_size);
 
4509
#if defined(__GNUC__) and __GNUC__ >= 11
 
4510
#pragma GCC diagnostic pop
 
4511
#endif
4464
4512
  g_assert_cmpint(close(pipefds[1]), ==, 0);
4465
4513
 
4466
4514
  bool quit_now = false;
4543
4591
  memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4544
4592
  const size_t ievent_size = (sizeof(struct inotify_event)
4545
4593
                              + sizeof(dummy_file_name));
 
4594
#if defined(__GNUC__) and __GNUC__ >= 11
 
4595
#pragma GCC diagnostic push
 
4596
  /* ievent is pointing into a struct which is of sufficient size */
 
4597
#pragma GCC diagnostic ignored "-Wstringop-overread"
 
4598
#endif
4546
4599
  g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4547
4600
                  ==, ievent_size);
 
4601
#if defined(__GNUC__) and __GNUC__ >= 11
 
4602
#pragma GCC diagnostic pop
 
4603
#endif
4548
4604
  g_assert_cmpint(close(pipefds[1]), ==, 0);
4549
4605
 
4550
4606
  bool quit_now = false;
4619
4675
  memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4620
4676
  const size_t ievent_size = (sizeof(struct inotify_event)
4621
4677
                              + sizeof(dummy_file_name));
 
4678
#if defined(__GNUC__) and __GNUC__ >= 11
 
4679
#pragma GCC diagnostic push
 
4680
  /* ievent is pointing into a struct which is of sufficient size */
 
4681
#pragma GCC diagnostic ignored "-Wstringop-overread"
 
4682
#endif
4622
4683
  g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4623
4684
                  ==, ievent_size);
 
4685
#if defined(__GNUC__) and __GNUC__ >= 11
 
4686
#pragma GCC diagnostic pop
 
4687
#endif
4624
4688
  g_assert_cmpint(close(pipefds[1]), ==, 0);
4625
4689
 
4626
4690
  bool quit_now = false;
4698
4762
  memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4699
4763
  const size_t ievent_size = (sizeof(struct inotify_event)
4700
4764
                              + sizeof(dummy_file_name));
 
4765
#if defined(__GNUC__) and __GNUC__ >= 11
 
4766
#pragma GCC diagnostic push
 
4767
  /* ievent is pointing into a struct which is of sufficient size */
 
4768
#pragma GCC diagnostic ignored "-Wstringop-overread"
 
4769
#endif
4701
4770
  g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4702
4771
                  ==, ievent_size);
 
4772
#if defined(__GNUC__) and __GNUC__ >= 11
 
4773
#pragma GCC diagnostic pop
 
4774
#endif
4703
4775
  g_assert_cmpint(close(pipefds[1]), ==, 0);
4704
4776
 
4705
4777
  bool quit_now = false;
4783
4855
  memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4784
4856
  const size_t ievent_size = (sizeof(struct inotify_event)
4785
4857
                              + sizeof(dummy_file_name));
 
4858
#if defined(__GNUC__) and __GNUC__ >= 11
 
4859
#pragma GCC diagnostic push
 
4860
  /* ievent is pointing into a struct which is of sufficient size */
 
4861
#pragma GCC diagnostic ignored "-Wstringop-overread"
 
4862
#endif
4786
4863
  g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4787
4864
                  ==, ievent_size);
 
4865
#if defined(__GNUC__) and __GNUC__ >= 11
 
4866
#pragma GCC diagnostic pop
 
4867
#endif
4788
4868
  g_assert_cmpint(close(pipefds[1]), ==, 0);
4789
4869
 
4790
4870
  bool quit_now = false;