Prevent string overflow by replacing usage of strcpy by strncpy

CID 8951, CID 10733, CID 10734, CID 10735, CID 10736, CID 10737, CID 10738,
CID 10739
This commit is contained in:
Philippe Saint-Pierre 2011-11-27 01:45:21 -05:00
parent d2780f6f25
commit 3927bd3c0d
9 changed files with 20 additions and 11 deletions

View File

@ -98,7 +98,8 @@ EXRTranslator::DerivedIdentify(BPositionIO *stream,
outInfo->quality = EXR_IN_QUALITY;
outInfo->capability = EXR_IN_CAPABILITY;
strcpy(outInfo->MIME, "image/exr");
strcpy(outInfo->name, B_TRANSLATE("EXR image"));
strncpy(outInfo->name, B_TRANSLATE("EXR image"),
sizeof(outInfo->name));
}
} catch (const std::exception &e) {
return B_NO_TRANSLATOR;

View File

@ -170,14 +170,15 @@ Identify(BPositionIO *inSource, const translation_format *inFormat,
outInfo->type = GIF_TYPE;
outInfo->quality = 0.8;
outInfo->capability = 0.8;
strcpy(outInfo->name, B_TRANSLATE("GIF image"));
strncpy(outInfo->name, B_TRANSLATE("GIF image"), sizeof(outInfo->name));
strcpy(outInfo->MIME, "image/gif");
}
else {
outInfo->type = B_TRANSLATOR_BITMAP;
outInfo->quality = 0.3;
outInfo->capability = 0.3;
strcpy(outInfo->name, B_TRANSLATE("Be Bitmap Format (GIFTranslator)"));
strncpy(outInfo->name, B_TRANSLATE("Be Bitmap Format (GIFTranslator)"),
sizeof(outInfo->name));
strcpy(outInfo->MIME, "image/x-be-bitmap");
}
return B_OK;

View File

@ -238,7 +238,8 @@ identify_png_header(BPositionIO *inSource, translator_info *outInfo)
outInfo->quality = PNG_IN_QUALITY;
outInfo->capability = PNG_IN_CAPABILITY;
strcpy(outInfo->MIME, "image/png");
strcpy(outInfo->name, B_TRANSLATE("PNG image"));
strncpy(outInfo->name, B_TRANSLATE("PNG image"),
sizeof(outInfo->name));
}
return B_OK;

View File

@ -280,14 +280,15 @@ Identify( /* required */
outInfo->type = PPM_TYPE;
outInfo->quality = 0.3; /* no alpha, etc */
outInfo->capability = 0.8; /* we're pretty good at PPM reading, though */
strcpy(outInfo->name, B_TRANSLATE("PPM image"));
strncpy(outInfo->name, B_TRANSLATE("PPM image"), sizeof(outInfo->name));
strcpy(outInfo->MIME, "image/x-portable-pixmap");
}
else {
outInfo->type = B_TRANSLATOR_BITMAP;
outInfo->quality = 0.4; /* B_TRANSLATOR_BITMAP can do alpha, at least */
outInfo->capability = 0.8; /* and we might not know many variations thereof */
strcpy(outInfo->name, B_TRANSLATE("Be Bitmap Format (PPMTranslator)"));
strncpy(outInfo->name, B_TRANSLATE("Be Bitmap Format (PPMTranslator)"),
sizeof(outInfo->name));
strcpy(outInfo->MIME, "image/x-be-bitmap"); /* this is the MIME type of B_TRANSLATOR_BITMAP */
}
return B_OK;

View File

@ -135,7 +135,8 @@ RTFTranslator::Identify(BPositionIO *stream,
info->group = B_TRANSLATOR_TEXT;
info->quality = RTF_IN_QUALITY;
info->capability = RTF_IN_CAPABILITY;
strcpy(info->name, B_TRANSLATE("RichTextFormat file"));
strncpy(info->name, B_TRANSLATE("RichTextFormat file"),
sizeof(info->name));
strcpy(info->MIME, "text/rtf");
return B_OK;

View File

@ -203,7 +203,8 @@ identify_sgi_header(BPositionIO *inSource, translator_info *outInfo, uint32 outT
outInfo->quality = SGI_IN_QUALITY;
outInfo->capability = SGI_IN_CAPABILITY;
strcpy(outInfo->MIME, "image/sgi");
strcpy(outInfo->name, B_TRANSLATE("SGI image"));
strncpy(outInfo->name, B_TRANSLATE("SGI image"),
sizeof(outInfo->name));
}
} else {
delete sgiImage;

View File

@ -305,7 +305,8 @@ BaseTranslator::identify_bits_header(BPositionIO *inSource,
outInfo->group = B_TRANSLATOR_BITMAP;
outInfo->quality = 0.2;
outInfo->capability = 0.2;
strcpy(outInfo->name, B_TRANSLATE("Be Bitmap Format"));
strncpy(outInfo->name, B_TRANSLATE("Be Bitmap Format"),
sizeof(outInfo->name));
strcpy(outInfo->MIME, "image/x-be-bitmap");
// Look for quality / capability info in fInputFormats

View File

@ -860,7 +860,8 @@ identify_stxt_header(const TranslatorStyledTextStreamHeader &header,
outInfo->group = B_TRANSLATOR_TEXT;
outInfo->quality = STXT_IN_QUALITY;
outInfo->capability = STXT_IN_CAPABILITY;
strcpy(outInfo->name, B_TRANSLATE("Be styled text file"));
strncpy(outInfo->name, B_TRANSLATE("Be styled text file"),
sizeof(outInfo->name));
strcpy(outInfo->MIME, "text/x-vnd.Be-stxt");
return B_OK;

View File

@ -134,7 +134,8 @@ identify_wbi_header(BPositionIO* inSource, translator_info* outInfo,
outInfo->quality = WBI_IN_QUALITY;
outInfo->capability = WBI_IN_CAPABILITY;
strcpy(outInfo->MIME, "image/x-wonderbrush");
strcpy(outInfo->name, B_TRANSLATE("WonderBrush image"));
strncpy(outInfo->name, B_TRANSLATE("WonderBrush image"),
sizeof(outInfo->name));
}
} else {
delete wbImage;