Skip to content

Commit e6cb876

Browse files
zx2c4Kalle Valo
authored and
Kalle Valo
committed
wifi: airo: do not assign -1 to unsigned char
With char becoming unsigned by default, and with `char` alone being ambiguous and based on architecture, we get a warning when assigning the unchecked output of hex_to_bin() to that unsigned char. Mark `key` as a `u8`, which matches the struct's type, and then check each call to hex_to_bin() before casting. Cc: Kalle Valo <[email protected]> Cc: [email protected] Signed-off-by: Jason A. Donenfeld <[email protected]> Signed-off-by: Kalle Valo <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 69188df commit e6cb876

File tree

1 file changed

+14
-4
lines changed
  • drivers/net/wireless/cisco

1 file changed

+14
-4
lines changed

drivers/net/wireless/cisco/airo.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5232,7 +5232,7 @@ static int get_wep_tx_idx(struct airo_info *ai)
52325232
return -1;
52335233
}
52345234

5235-
static int set_wep_key(struct airo_info *ai, u16 index, const char *key,
5235+
static int set_wep_key(struct airo_info *ai, u16 index, const u8 *key,
52365236
u16 keylen, int perm, int lock)
52375237
{
52385238
static const unsigned char macaddr[ETH_ALEN] = { 0x01, 0, 0, 0, 0, 0 };
@@ -5283,7 +5283,7 @@ static void proc_wepkey_on_close(struct inode *inode, struct file *file)
52835283
struct net_device *dev = pde_data(inode);
52845284
struct airo_info *ai = dev->ml_priv;
52855285
int i, rc;
5286-
char key[16];
5286+
u8 key[16];
52875287
u16 index = 0;
52885288
int j = 0;
52895289

@@ -5311,12 +5311,22 @@ static void proc_wepkey_on_close(struct inode *inode, struct file *file)
53115311
}
53125312

53135313
for (i = 0; i < 16*3 && data->wbuffer[i+j]; i++) {
5314+
int val;
5315+
5316+
if (i % 3 == 2)
5317+
continue;
5318+
5319+
val = hex_to_bin(data->wbuffer[i+j]);
5320+
if (val < 0) {
5321+
airo_print_err(ai->dev->name, "WebKey passed invalid key hex");
5322+
return;
5323+
}
53145324
switch(i%3) {
53155325
case 0:
5316-
key[i/3] = hex_to_bin(data->wbuffer[i+j])<<4;
5326+
key[i/3] = (u8)val << 4;
53175327
break;
53185328
case 1:
5319-
key[i/3] |= hex_to_bin(data->wbuffer[i+j]);
5329+
key[i/3] |= (u8)val;
53205330
break;
53215331
}
53225332
}

0 commit comments

Comments
 (0)