소스 검색

Fix off-by-1 error in vfscanf

Scanf function requires look ahead to function properly, In case of
scanning from a buffer that will not be an issue, but in our case we are
reading from file, so lookaheads needs to be undone (via lseek) in our
case. The only problem here is that if we opened a file that doesn't
support lseek such as many of the file /dev/*
oddcoder 4 년 전
부모
커밋
d7d3e00867
1개의 변경된 파일6개의 추가작업 그리고 2개의 파일을 삭제
  1. 6 2
      src/header/stdio/mod.rs

+ 6 - 2
src/header/stdio/mod.rs

@@ -1041,8 +1041,12 @@ pub unsafe extern "C" fn vsprintf(s: *mut c_char, format: *const c_char, ap: va_
 
 #[no_mangle]
 pub unsafe extern "C" fn vfscanf(file: *mut FILE, format: *const c_char, ap: va_list) -> c_int {
-    let mut file = (*file).lock();
-    scanf::scanf(&mut *file, format, ap)
+    let ret = {
+        let mut file = (*file).lock();
+        scanf::scanf(&mut *file, format, ap)
+    };
+    fseeko(file, -1, SEEK_CUR);
+    ret
 }
 
 #[no_mangle]