avatar
问题 求教--在线等# Security - 系统安全
g*s
1
Here are two approaches to handling an input
file of arbitrary size:
A. Use a library or syscall that lets you determine the size
of the file. malloc a buffer to be that size. Then read
chars into the buffer until you hit EOF.
B. Malloc a buffer of a specific size. Read chars until
you hit that size, or EOF. If you fill the buffer,
use realloc to get a larger buffer.
From a security perspective, which is better? Why?
谢谢
avatar
p*y
2
A is not good i think,
If the size of the file changes after you determine the size of it,
the surplus part may overwrite the memory portion after the buffer
you allocated. And that portion may be a piece of code, the return addr
of a function call, etc.
Someone may write malicious code or address to get control of the host.

【在 g*s 的大作中提到】
: Here are two approaches to handling an input
: file of arbitrary size:
: A. Use a library or syscall that lets you determine the size
: of the file. malloc a buffer to be that size. Then read
: chars into the buffer until you hit EOF.
: B. Malloc a buffer of a specific size. Read chars until
: you hit that size, or EOF. If you fill the buffer,
: use realloc to get a larger buffer.
: From a security perspective, which is better? Why?
: 谢谢

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。