]> git.deb.at Git - pkg/beep.git/blob - debian/patches/CVE-2018-0492.patch
CVE-2018-0492
[pkg/beep.git] / debian / patches / CVE-2018-0492.patch
1 --- beep-1.3.orig/beep.c
2 +++ beep-1.3/beep.c
3 @@ -109,6 +109,7 @@ void do_beep(int freq) {
4       /* BEEP_TYPE_EVDEV */
5       struct input_event e;
6  
7 +     memset(&e, 0, sizeof(e));
8       e.type = EV_SND;
9       e.code = SND_TONE;
10       e.value = freq;
11 @@ -121,10 +122,6 @@ void do_beep(int freq) {
12  /* If we get interrupted, it would be nice to not leave the speaker beeping in
13     perpetuity. */
14  void handle_signal(int signum) {
15 -
16 -  if(console_device)
17 -    free(console_device);
18 -
19    switch(signum) {
20    case SIGINT:
21    case SIGTERM:
22 @@ -254,7 +251,7 @@ void parse_command_line(int argc, char *
23        result->verbose = 1;
24        break;
25      case 'e' : /* also --device */
26 -      console_device = strdup(optarg);
27 +      console_device = optarg;
28        break;
29      case 'h' : /* notice that this is also --help */
30      default :
31 @@ -273,26 +270,6 @@ void play_beep(beep_parms_t parms) {
32         "%d delay after) @ %.2f Hz\n",
33         parms.reps, parms.length, parms.delay, parms.end_delay, parms.freq);
34  
35 -  /* try to snag the console */
36 -  if(console_device)
37 -    console_fd = open(console_device, O_WRONLY);
38 -  else
39 -    if((console_fd = open("/dev/tty0", O_WRONLY)) == -1)
40 -      console_fd = open("/dev/vc/0", O_WRONLY);
41 -
42 -  if(console_fd == -1) {
43 -    fprintf(stderr, "Could not open %s for writing\n",
44 -      console_device != NULL ? console_device : "/dev/tty0 or /dev/vc/0");
45 -    printf("\a");  /* Output the only beep we can, in an effort to fall back on usefulness */
46 -    perror("open");
47 -    exit(1);
48 -  }
49 -
50 -  if (ioctl(console_fd, EVIOCGSND(0)) != -1)
51 -    console_type = BEEP_TYPE_EVDEV;
52 -  else
53 -    console_type = BEEP_TYPE_CONSOLE;
54 -  
55    /* Beep */
56    for (i = 0; i < parms.reps; i++) {                    /* start beep */
57      do_beep(parms.freq);
58 @@ -302,8 +279,6 @@ void play_beep(beep_parms_t parms) {
59      if(parms.end_delay || (i+1 < parms.reps))
60         usleep(1000*parms.delay);                        /* wait...    */
61    }                                                     /* repeat.    */
62 -
63 -  close(console_fd);
64  }
65  
66  
67 @@ -325,6 +300,26 @@ int main(int argc, char **argv) {
68    signal(SIGTERM, handle_signal);
69    parse_command_line(argc, argv, parms);
70  
71 +  /* try to snag the console */
72 +  if(console_device)
73 +    console_fd = open(console_device, O_WRONLY);
74 +  else
75 +    if((console_fd = open("/dev/tty0", O_WRONLY)) == -1)
76 +      console_fd = open("/dev/vc/0", O_WRONLY);
77 +
78 +  if(console_fd == -1) {
79 +    fprintf(stderr, "Could not open %s for writing\n",
80 +      console_device != NULL ? console_device : "/dev/tty0 or /dev/vc/0");
81 +    printf("\a");  /* Output the only beep we can, in an effort to fall back on usefulness */
82 +    perror("open");
83 +    exit(1);
84 +  }
85 +
86 +  if (ioctl(console_fd, EVIOCGSND(0)) != -1)
87 +    console_type = BEEP_TYPE_EVDEV;
88 +  else
89 +    console_type = BEEP_TYPE_CONSOLE;
90 +
91    /* this outermost while loop handles the possibility that -n/--new has been
92       used, i.e. that we have multiple beeps specified. Each iteration will
93       play, then free() one parms instance. */
94 @@ -362,8 +357,8 @@ int main(int argc, char **argv) {
95      parms = next;
96    }
97  
98 -  if(console_device)
99 -    free(console_device);
100 +  close(console_fd);
101 +  console_fd = -1;
102  
103    return EXIT_SUCCESS;
104  }