Skip to contentSkip to conversation

linux-user: fix getcwd syscall

Qemu-devel Applied Arnaud Patard (Rtp) 3 participants 3 messages Apr 16, 2009

lore
Share & tools
lore
#0 lore raw

The patch called "prefer glibc over direct syscalls" (commit 7118) has replaced the getcwd syscall with a call to the glibc. With this change, the syscall is returning -1 in error case and 0 otherwise. This is problematic as the sys_getcwd syscall should return the number of bytes written to the buffer including the '\0'.

---

linux-user/syscall.c +1 -1
index 74b41a8..f5875aa 100644
@@ -293,7 +293,7 @@ static int sys_getcwd1(char *buf, size_t size)
       /* getcwd() sets errno */
       return (-1);
   }
-  return (0);
+  return strlen(buf)+1;
 }
 
 #ifdef CONFIG_ATFILE
Acked-by
#1 lore raw

Hi,

You are right. This is what I get for only checking the manpage.

Quoted 23 lines · Arnaud Patard

The patch called "prefer glibc over direct syscalls" (commit 7118) has replaced the getcwd syscall with a call to the glibc. With this change, the syscall is returning -1 in error case and 0 otherwise. This is problematic as the sys_getcwd syscall should return the number of bytes written to the buffer including the '\0'.

---

linux-user/syscall.c +1 -1
index 74b41a8..f5875aa 100644
@@ -293,7 +293,7 @@ static int sys_getcwd1(char *buf, size_t size)
       /* getcwd() sets errno */
       return (-1);
   }
-  return (0);
+  return strlen(buf)+1;
 }
 
 #ifdef CONFIG_ATFILE
Signature · 1 line
"rm -rf" only sounds scary if you don't have backups
#2 lore raw
In reply to Arnaud Patard (Rtp)
Quoted 9 lines · Arnaud Patard

The patch called "prefer glibc over direct syscalls" (commit 7118) has replaced the getcwd syscall with a call to the glibc. With this change, the syscall is returning -1 in error case and 0 otherwise. This is problematic as the sys_getcwd syscall should return the number of bytes written to the buffer including the '\0'.

---

Thanks, applied.

Quoted 13 lines
linux-user/syscall.c +1 -1
index 74b41a8..f5875aa 100644
@@ -293,7 +293,7 @@ static int sys_getcwd1(char *buf, size_t size)
       /* getcwd() sets errno */
       return (-1);
   }
-  return (0);
+  return strlen(buf)+1;
 }
 
 #ifdef CONFIG_ATFILE
Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net