Skip to content

Commit

Permalink
NET: ROSE: Don't use static buffer.
Browse files Browse the repository at this point in the history
The use of a static buffer in rose2asc() to return its result is not
threadproof and can result in corruption if multiple threads are trying
to use one of the procfs files based on rose2asc().

Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Ralf Baechle authored and David S. Miller committed Jul 27, 2009
1 parent d513d01 commit dcf777f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion include/net/rose.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ extern int sysctl_rose_maximum_vcs;
extern int sysctl_rose_window_size;
extern int rosecmp(rose_address *, rose_address *);
extern int rosecmpm(rose_address *, rose_address *, unsigned short);
extern const char *rose2asc(const rose_address *);
extern char *rose2asc(char *buf, const rose_address *);
extern struct sock *rose_find_socket(unsigned int, struct rose_neigh *);
extern void rose_kill_by_neigh(struct rose_neigh *);
extern unsigned int rose_new_lci(struct rose_neigh *);
Expand Down
18 changes: 8 additions & 10 deletions net/rose/af_rose.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,21 @@ static void rose_set_lockdep_key(struct net_device *dev)
/*
* Convert a ROSE address into text.
*/
const char *rose2asc(const rose_address *addr)
char *rose2asc(char *buf, const rose_address *addr)
{
static char buffer[11];

if (addr->rose_addr[0] == 0x00 && addr->rose_addr[1] == 0x00 &&
addr->rose_addr[2] == 0x00 && addr->rose_addr[3] == 0x00 &&
addr->rose_addr[4] == 0x00) {
strcpy(buffer, "*");
strcpy(buf, "*");
} else {
sprintf(buffer, "%02X%02X%02X%02X%02X", addr->rose_addr[0] & 0xFF,
sprintf(buf, "%02X%02X%02X%02X%02X", addr->rose_addr[0] & 0xFF,
addr->rose_addr[1] & 0xFF,
addr->rose_addr[2] & 0xFF,
addr->rose_addr[3] & 0xFF,
addr->rose_addr[4] & 0xFF);
}

return buffer;
return buf;
}

/*
Expand Down Expand Up @@ -1437,7 +1435,7 @@ static void rose_info_stop(struct seq_file *seq, void *v)

static int rose_info_show(struct seq_file *seq, void *v)
{
char buf[11];
char buf[11], rsbuf[11];

if (v == SEQ_START_TOKEN)
seq_puts(seq,
Expand All @@ -1455,8 +1453,8 @@ static int rose_info_show(struct seq_file *seq, void *v)
devname = dev->name;

seq_printf(seq, "%-10s %-9s ",
rose2asc(&rose->dest_addr),
ax2asc(buf, &rose->dest_call));
rose2asc(rsbuf, &rose->dest_addr),
ax2asc(buf, &rose->dest_call));

if (ax25cmp(&rose->source_call, &null_ax25_address) == 0)
callsign = "??????-?";
Expand All @@ -1465,7 +1463,7 @@ static int rose_info_show(struct seq_file *seq, void *v)

seq_printf(seq,
"%-10s %-9s %-5s %3.3X %05d %d %d %d %d %3lu %3lu %3lu %3lu %3lu %3lu/%03lu %5d %5d %ld\n",
rose2asc(&rose->source_addr),
rose2asc(rsbuf, &rose->source_addr),
callsign,
devname,
rose->lci & 0x0FFF,
Expand Down
23 changes: 12 additions & 11 deletions net/rose/rose_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,7 @@ static void rose_node_stop(struct seq_file *seq, void *v)

static int rose_node_show(struct seq_file *seq, void *v)
{
char rsbuf[11];
int i;

if (v == SEQ_START_TOKEN)
Expand All @@ -1112,13 +1113,13 @@ static int rose_node_show(struct seq_file *seq, void *v)
const struct rose_node *rose_node = v;
/* if (rose_node->loopback) {
seq_printf(seq, "%-10s %04d 1 loopback\n",
rose2asc(&rose_node->address),
rose_node->mask);
rose2asc(rsbuf, &rose_node->address),
rose_node->mask);
} else { */
seq_printf(seq, "%-10s %04d %d",
rose2asc(&rose_node->address),
rose_node->mask,
rose_node->count);
rose2asc(rsbuf, &rose_node->address),
rose_node->mask,
rose_node->count);

for (i = 0; i < rose_node->count; i++)
seq_printf(seq, " %05d",
Expand Down Expand Up @@ -1267,7 +1268,7 @@ static void rose_route_stop(struct seq_file *seq, void *v)

static int rose_route_show(struct seq_file *seq, void *v)
{
char buf[11];
char buf[11], rsbuf[11];

if (v == SEQ_START_TOKEN)
seq_puts(seq,
Expand All @@ -1279,7 +1280,7 @@ static int rose_route_show(struct seq_file *seq, void *v)
seq_printf(seq,
"%3.3X %-10s %-9s %05d ",
rose_route->lci1,
rose2asc(&rose_route->src_addr),
rose2asc(rsbuf, &rose_route->src_addr),
ax2asc(buf, &rose_route->src_call),
rose_route->neigh1->number);
else
Expand All @@ -1289,10 +1290,10 @@ static int rose_route_show(struct seq_file *seq, void *v)
if (rose_route->neigh2)
seq_printf(seq,
"%3.3X %-10s %-9s %05d\n",
rose_route->lci2,
rose2asc(&rose_route->dest_addr),
ax2asc(buf, &rose_route->dest_call),
rose_route->neigh2->number);
rose_route->lci2,
rose2asc(rsbuf, &rose_route->dest_addr),
ax2asc(buf, &rose_route->dest_call),
rose_route->neigh2->number);
else
seq_puts(seq,
"000 * * 00000\n");
Expand Down

0 comments on commit dcf777f

Please sign in to comment.