Skip to content

Commit d3bde7d

Browse files
committed
print_string: Validate tty before accessing its operations
Close #81
1 parent b990049 commit d3bde7d

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

examples/print_string.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,14 @@
1111

1212
static void print_string(char *str)
1313
{
14-
struct tty_struct *my_tty;
15-
const struct tty_operations *ttyops;
16-
17-
/* The tty for the current task, for 2.6.6+ kernels */
18-
my_tty = get_current_tty();
19-
ttyops = my_tty->driver->ops;
14+
/* The tty for the current task */
15+
struct tty_struct *my_tty = get_current_tty();
2016

2117
/* If my_tty is NULL, the current task has no tty you can print to (i.e.,
2218
* if it is a daemon). If so, there is nothing we can do.
2319
*/
2420
if (my_tty) {
21+
const struct tty_operations *ttyops = my_tty->driver->ops;
2522
/* my_tty->driver is a struct which holds the tty's functions,
2623
* one of which (write) is used to write strings to the tty.
2724
* It can be used to take a string either from the user's or

0 commit comments

Comments
 (0)