/mandos/release

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

« back to all changes in this revision

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

  • Committer: Teddy Hogeborn
  • Date: 2019-08-01 17:35:45 UTC
  • mto: This revision was merged to the branch mainline in revision 386.
  • Revision ID: teddy@recompile.se-20190801173545-swvm0c6e1e00qdwi
password-agent: Fix memory alignment issue

On many architectures (armel, armhf, mips, mips64el, mipsel, hppa,
ia64, sh4, and sparc64) GCC shows a warning when casting a "char *" to
a "struct inotify_event *"; The exact warning message from GCC is
"cast increases required alignment of target type [-Wcast-align]".

* dracut-module/password-agent.c (read_inotify_event): Change
  "ievent_buffer" to an anonymous struct instead of a char array.
  (test_read_inotify_event_IN_CLOSE_WRITE): - '' -
  (test_read_inotify_event_IN_MOVED_TO): - '' -
  (test_read_inotify_event_IN_DELETE): - '' -
  (test_read_inotify_event_IN_CLOSE_WRITE_badname): - '' -
  (test_read_inotify_event_IN_MOVED_TO_badname): - '' -
  (test_read_inotify_event_IN_DELETE_badname): - '' -

Show diffs side-by-side

added added

removed removed

Lines of Context:
1071
1071
  /* "sufficient to read at least one event." - inotify(7) */
1072
1072
  const size_t ievent_size = (sizeof(struct inotify_event)
1073
1073
                              + NAME_MAX + 1);
1074
 
  char ievent_buffer[sizeof(struct inotify_event) + NAME_MAX + 1];
1075
 
  struct inotify_event *ievent = ((struct inotify_event *)
1076
 
                                  ievent_buffer);
 
1074
  struct {
 
1075
    struct inotify_event event;
 
1076
    char name_buffer[NAME_MAX + 1];
 
1077
  } ievent_buffer;
 
1078
  struct inotify_event *const ievent = &ievent_buffer.event;
1077
1079
 
1078
1080
  const ssize_t read_length = read(fd, ievent, ievent_size);
1079
1081
  if(read_length == 0){ /* EOF */
3929
3931
  const size_t ievent_max_size = (sizeof(struct inotify_event)
3930
3932
                                  + NAME_MAX + 1);
3931
3933
  g_assert_cmpint(ievent_max_size, <=, PIPE_BUF);
3932
 
  char ievent_buffer[sizeof(struct inotify_event) + NAME_MAX + 1];
3933
 
  struct inotify_event *ievent = ((struct inotify_event *)
3934
 
                                  ievent_buffer);
 
3934
  struct {
 
3935
    struct inotify_event event;
 
3936
    char name_buffer[NAME_MAX + 1];
 
3937
  } ievent_buffer;
 
3938
  struct inotify_event *const ievent = &ievent_buffer.event;
3935
3939
 
3936
3940
  const char dummy_file_name[] = "ask.dummy_file_name";
3937
3941
  ievent->mask = IN_CLOSE_WRITE;
3939
3943
  memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
3940
3944
  const size_t ievent_size = (sizeof(struct inotify_event)
3941
3945
                              + sizeof(dummy_file_name));
3942
 
  g_assert_cmpint(write(pipefds[1], ievent_buffer, ievent_size),
 
3946
  g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
3943
3947
                  ==, ievent_size);
3944
3948
  g_assert_cmpint(close(pipefds[1]), ==, 0);
3945
3949
 
4022
4026
  const size_t ievent_max_size = (sizeof(struct inotify_event)
4023
4027
                                  + NAME_MAX + 1);
4024
4028
  g_assert_cmpint(ievent_max_size, <=, PIPE_BUF);
4025
 
  char ievent_buffer[sizeof(struct inotify_event) + NAME_MAX + 1];
4026
 
  struct inotify_event *ievent = ((struct inotify_event *)
4027
 
                                  ievent_buffer);
 
4029
  struct {
 
4030
    struct inotify_event event;
 
4031
    char name_buffer[NAME_MAX + 1];
 
4032
  } ievent_buffer;
 
4033
  struct inotify_event *const ievent = &ievent_buffer.event;
4028
4034
 
4029
4035
  const char dummy_file_name[] = "ask.dummy_file_name";
4030
4036
  ievent->mask = IN_MOVED_TO;
4032
4038
  memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4033
4039
  const size_t ievent_size = (sizeof(struct inotify_event)
4034
4040
                              + sizeof(dummy_file_name));
4035
 
  g_assert_cmpint(write(pipefds[1], ievent_buffer, ievent_size),
 
4041
  g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4036
4042
                  ==, ievent_size);
4037
4043
  g_assert_cmpint(close(pipefds[1]), ==, 0);
4038
4044
 
4117
4123
  const size_t ievent_max_size = (sizeof(struct inotify_event)
4118
4124
                                  + NAME_MAX + 1);
4119
4125
  g_assert_cmpint(ievent_max_size, <=, PIPE_BUF);
4120
 
  char ievent_buffer[sizeof(struct inotify_event) + NAME_MAX + 1];
4121
 
  struct inotify_event *ievent = ((struct inotify_event *)
4122
 
                                  ievent_buffer);
 
4126
  struct {
 
4127
    struct inotify_event event;
 
4128
    char name_buffer[NAME_MAX + 1];
 
4129
  } ievent_buffer;
 
4130
  struct inotify_event *const ievent = &ievent_buffer.event;
4123
4131
 
4124
4132
  const char dummy_file_name[] = "ask.dummy_file_name";
4125
4133
  ievent->mask = IN_DELETE;
4127
4135
  memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4128
4136
  const size_t ievent_size = (sizeof(struct inotify_event)
4129
4137
                              + sizeof(dummy_file_name));
4130
 
  g_assert_cmpint(write(pipefds[1], ievent_buffer, ievent_size),
 
4138
  g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4131
4139
                  ==, ievent_size);
4132
4140
  g_assert_cmpint(close(pipefds[1]), ==, 0);
4133
4141
 
4199
4207
  const size_t ievent_max_size = (sizeof(struct inotify_event)
4200
4208
                                  + NAME_MAX + 1);
4201
4209
  g_assert_cmpint(ievent_max_size, <=, PIPE_BUF);
4202
 
  char ievent_buffer[sizeof(struct inotify_event) + NAME_MAX + 1];
4203
 
  struct inotify_event *ievent = ((struct inotify_event *)
4204
 
                                  ievent_buffer);
 
4210
  struct {
 
4211
    struct inotify_event event;
 
4212
    char name_buffer[NAME_MAX + 1];
 
4213
  } ievent_buffer;
 
4214
  struct inotify_event *const ievent = &ievent_buffer.event;
4205
4215
 
4206
4216
  const char dummy_file_name[] = "ignored.dummy_file_name";
4207
4217
  ievent->mask = IN_CLOSE_WRITE;
4209
4219
  memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4210
4220
  const size_t ievent_size = (sizeof(struct inotify_event)
4211
4221
                              + sizeof(dummy_file_name));
4212
 
  g_assert_cmpint(write(pipefds[1], ievent_buffer, ievent_size),
 
4222
  g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4213
4223
                  ==, ievent_size);
4214
4224
  g_assert_cmpint(close(pipefds[1]), ==, 0);
4215
4225
 
4273
4283
  const size_t ievent_max_size = (sizeof(struct inotify_event)
4274
4284
                                  + NAME_MAX + 1);
4275
4285
  g_assert_cmpint(ievent_max_size, <=, PIPE_BUF);
4276
 
  char ievent_buffer[sizeof(struct inotify_event) + NAME_MAX + 1];
4277
 
  struct inotify_event *ievent = ((struct inotify_event *)
4278
 
                                  ievent_buffer);
 
4286
  struct {
 
4287
    struct inotify_event event;
 
4288
    char name_buffer[NAME_MAX + 1];
 
4289
  } ievent_buffer;
 
4290
  struct inotify_event *const ievent = &ievent_buffer.event;
4279
4291
 
4280
4292
  const char dummy_file_name[] = "ignored.dummy_file_name";
4281
4293
  ievent->mask = IN_MOVED_TO;
4283
4295
  memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4284
4296
  const size_t ievent_size = (sizeof(struct inotify_event)
4285
4297
                              + sizeof(dummy_file_name));
4286
 
  g_assert_cmpint(write(pipefds[1], ievent_buffer, ievent_size),
 
4298
  g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4287
4299
                  ==, ievent_size);
4288
4300
  g_assert_cmpint(close(pipefds[1]), ==, 0);
4289
4301
 
4350
4362
  const size_t ievent_max_size = (sizeof(struct inotify_event)
4351
4363
                                  + NAME_MAX + 1);
4352
4364
  g_assert_cmpint(ievent_max_size, <=, PIPE_BUF);
4353
 
  char ievent_buffer[sizeof(struct inotify_event) + NAME_MAX + 1];
4354
 
  struct inotify_event *ievent = ((struct inotify_event *)
4355
 
                                  ievent_buffer);
 
4365
  struct {
 
4366
    struct inotify_event event;
 
4367
    char name_buffer[NAME_MAX + 1];
 
4368
  } ievent_buffer;
 
4369
  struct inotify_event *const ievent = &ievent_buffer.event;
4356
4370
 
4357
4371
  const char dummy_file_name[] = "ignored.dummy_file_name";
4358
4372
  ievent->mask = IN_DELETE;
4360
4374
  memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4361
4375
  const size_t ievent_size = (sizeof(struct inotify_event)
4362
4376
                              + sizeof(dummy_file_name));
4363
 
  g_assert_cmpint(write(pipefds[1], ievent_buffer, ievent_size),
 
4377
  g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4364
4378
                  ==, ievent_size);
4365
4379
  g_assert_cmpint(close(pipefds[1]), ==, 0);
4366
4380