libata: use ata_id_c_string()

There were several places where ATA ID strings are manually terminated
and in some places possibly unterminated strings were passed to string
functions which don't limit length like strstr().  This patch converts
all of them over to ata_id_c_string().

Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Jeff Garzik <jeff@garzik.org>
This commit is contained in:
Tejun Heo
2007-01-02 20:19:40 +09:00
committed by Jeff Garzik
parent a0cf733b33
commit 8bfa79fcb8
6 changed files with 23 additions and 78 deletions

View File

@ -3325,35 +3325,20 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
{ }
};
static int ata_strim(char *s, size_t len)
{
len = strnlen(s, len);
/* ATAPI specifies that empty space is blank-filled; remove blanks */
while ((len > 0) && (s[len - 1] == ' ')) {
len--;
s[len] = 0;
}
return len;
}
unsigned long ata_device_blacklisted(const struct ata_device *dev)
{
unsigned char model_num[ATA_ID_PROD_LEN];
unsigned char model_rev[ATA_ID_FW_REV_LEN];
unsigned int nlen, rlen;
unsigned char model_num[ATA_ID_PROD_LEN + 1];
unsigned char model_rev[ATA_ID_FW_REV_LEN + 1];
const struct ata_blacklist_entry *ad = ata_device_blacklist;
ata_id_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num));
ata_id_string(dev->id, model_rev, ATA_ID_FW_REV, sizeof(model_rev));
nlen = ata_strim(model_num, sizeof(model_num));
rlen = ata_strim(model_rev, sizeof(model_rev));
ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num));
ata_id_c_string(dev->id, model_rev, ATA_ID_FW_REV, sizeof(model_rev));
while (ad->model_num) {
if (!strncmp(ad->model_num, model_num, nlen)) {
if (!strcmp(ad->model_num, model_num)) {
if (ad->model_rev == NULL)
return ad->horkage;
if (!strncmp(ad->model_rev, model_rev, rlen))
if (!strcmp(ad->model_rev, model_rev))
return ad->horkage;
}
ad++;