From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Thu, 17 Aug 1995 00:35:07 -0400 From: Vadim Antonov avg@postman.ncube.com Subject: BUG FIX for getwd() Topicbox-Message-UUID: 17a99dbc-eac8-11e9-9e20-41e7f4b1d025 Message-ID: <19950817043507.2LhkKy_fQumyi0zrZFowRzy50ku5atJAj8mxIhZCZsk@z> ----FORWARDED MESSAGE---- From: markw@kira (Mark Wiley) Subject: This is too much fun to keep to myself ... If you call getwd with a buffer which it too small to contain the current working directory, it returns 0 and places the message 'buffer too small' in the buffer EVEN if the buffer is too small to contain that message. Sigh. Markw ------------------------- The fix is appended, although the right way to do things would be to change the way the error message is returned (it should be in errstr...) --vadim File /sys/src/libc/9sys/getwd.c: naiad% diff getwd.c.old getwd.c 14c14 < getwd(char *s , int size) --- > getwd(char *s , int size0) 18a19 > int size; 19a21 > size = size0; 22c24 < strcpy(s, "stat of / failed"); --- > strncpy(s, "stat of / failed", size0); 29c31 < strcpy(s, "stat of . failed"); --- > strncpy(s, "stat of . failed", size0); 51c53 < strcpy(s, "chdir .. failed"); --- > strncpy(s, "chdir .. failed", size0); 65c67 < strcpy(s, "buffer too small"); --- > strncpy(s, "buffer too small", size0); 77c79 < strcpy(s, "failed to return to ."); --- > strncpy(s, "failed to return to .", size0);