Skip to content

Commit 33a50f4

Browse files
committed
Enable -D_FORTIFY_SOURCE=2 and fix resulting diagnostics
1 parent 5446431 commit 33a50f4

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

src/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ INCLUDE += $(LIBTIRPC_CFLAGS)
244244
# Compilation options. Perhaps some of these should come from Makefile.inc? (CXXFLAGS now does)
245245
INTEGER_OVERFLOW_FLAGS := -fwrapv
246246
OPT := -Os $(INTEGER_OVERFLOW_FLAGS)
247-
DEBUG := $(DEBUG) -g -Wall -Wno-stringop-truncation
247+
DEBUG := $(DEBUG) -g -Wall -Wno-stringop-truncation -D_FORTIFY_SOURCE=2
248248
CFLAGS := $(INCLUDE) $(OPT) $(DEBUG) $(EXTRA_DEBUG) -DULAPI -std=gnu11 -Werror=implicit-function-declaration $(CFLAGS) $(CPPFLAGS)
249249
CXXFLAGS := $(INCLUDE) $(EXTRA_DEBUG) -DULAPI $(DEBUG) $(OPT) -Werror=overloaded-virtual $(CXXFLAGS) $(CPPFLAGS)
250250
CXXFLAGS += -std=gnu++17

src/hal/user_comps/sendkeys.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void emit(int fd, int type, int code, int val)
6262
ie.type = type;
6363
ie.code = code;
6464
ie.value = val;
65-
write(fd, &ie, sizeof(ie));
65+
if (write(fd, &ie, sizeof(ie)) != sizeof(ie)) { perror("write(input_event)"); }
6666
}
6767

6868
static void exit_handler(int sig) {
@@ -219,7 +219,6 @@ int init(int argc, char* argv[]){
219219
}
220220

221221
int main(int argc, char* argv[]) {
222-
struct uinput_user_dev uidev;
223222
int i, j;
224223

225224
signal(SIGINT, exit_handler);
@@ -246,24 +245,28 @@ int main(int argc, char* argv[]) {
246245
if (! *hal->init) continue;
247246
if (*hal->init && ! param->inited) {
248247
param->fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
249-
if (param->fd < 0) rtapi_print_msg(RTAPI_MSG_ERR,
250-
"Cannot open /dev/uinput. Suggest chmod 666 /dev/uinput\n");
248+
if (param->fd < 0) {
249+
rtapi_print_msg(RTAPI_MSG_ERR,
250+
"Cannot open /dev/uinput. Suggest chmod 666 /dev/uinput\n");
251+
abort();
252+
}
251253
ioctl(param->fd, UI_SET_EVBIT, EV_KEY);
252254
for (j = 0; j < param->num_events; j++){
253255
if (hal->event[j] > 0 && hal->event[j] < KEY_MAX){
254256
ioctl(param->fd, UI_SET_KEYBIT, hal->event[j]);
255257
rtapi_print("SET_EVBIT %i\n", hal->event[j]);
256258
}
257259
}
260+
struct uinput_user_dev uidev;
258261
memset(&uidev, 0, sizeof(uidev));
259262
strcpy(uidev.name, "linuxcnc-hal");
260263
uidev.id.bustype = BUS_USB;
261264
uidev.id.vendor = 0x1;
262265
uidev.id.product = 0x1;
263266
uidev.id.version = 1;
264267

265-
write(param->fd, &uidev, sizeof(uidev));
266-
ioctl(param->fd, UI_DEV_CREATE);
268+
if (write(param->fd, &uidev, sizeof(uidev)) != sizeof(uidev)) { perror("write(uinput_user_dev)"); abort(); }
269+
if (ioctl(param->fd, UI_DEV_CREATE) < 0) { perror("ioctl(UI_DEV_CREATE)"); abort(); }
267270
param->inited = 1;
268271
}
269272
if (*hal->keycode != param->oldcode) {

src/rtapi/uspace_rtapi_app.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,14 +523,14 @@ int main(int argc, char **argv) {
523523
" sudo env RTAPI_UID=`id -u` RTAPI_FIFO_PATH=$HOME/.rtapi_fifo gdb " EMC2_BIN_DIR "/rtapi_app\n");
524524
exit(1);
525525
}
526-
setreuid(fallback_uid, 0);
526+
if (setreuid(fallback_uid, 0) != 0) { perror("setreuid"); abort(); }
527527
fprintf(stderr,
528528
"Running with fallback_uid. getuid()=%d geteuid()=%d\n",
529529
getuid(), geteuid());
530530
}
531531
ruid = getuid();
532532
euid = geteuid();
533-
setresuid(euid, euid, ruid);
533+
if (setresuid(euid, euid, ruid) != 0) { perror("setresuid"); abort(); }
534534
#ifdef __linux__
535535
setfsuid(ruid);
536536
#endif

0 commit comments

Comments
 (0)