Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INTERNAL: Prevent overflow when convert string to 32bit int #730

Merged
merged 1 commit into from
Jan 20, 2024

Conversation

ing-eoking
Copy link
Collaborator

@ing-eoking ing-eoking commented Jan 19, 2024

  • jam2in/arcus-works#475

문자열을 32bit 정수 자료형 변환 과정이 3단계(string -> long(64bit) -> int(32bit))로 이루어짐으로써
overflow 발생 시 undefined value로 변환되는 현상을 수정합니다.

해당 현상 발생시 return false를 하도록 수정했습니다.

Copy link
Collaborator

@jhpark816 jhpark816 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리뷰 완료

util.c Outdated
@@ -74,7 +74,7 @@ bool safe_strtoul(const char *str, uint32_t *out) {
errno = 0;

l = strtoul(str, &endptr, 10);
if (errno == ERANGE) {
if (UINT32_MAX < l || errno == ERANGE) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error 먼저 검사하고, l 값이 왼쪽에 상수는 오론쪽에 나오게 하시죠.

if (error == ERANGE || l > UINT32_MAX) {

util.c Outdated
@@ -100,7 +100,7 @@ bool safe_strtol(const char *str, int32_t *out) {
*out = 0;
char *endptr;
long l = strtol(str, &endptr, 10);
if (errno == ERANGE)
if (INT32_MIN > l || INT32_MAX < l || errno == ERANGE)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (errno == ERANGE || l < INT32_MIN || l > INT32_MAX)

@ing-eoking
Copy link
Collaborator Author

@jhpark816
수정되었습니다.

@jhpark816 jhpark816 merged commit 9b57d2d into naver:develop Jan 20, 2024
1 check passed
@ing-eoking ing-eoking deleted the int branch February 22, 2024 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants