Skip to content

Commit 70b2acd

Browse files
authored
Merge pull request #3831 from smoe/29_error_open_detect
fix: Error detection after open(2)
2 parents 7242b3f + e654a61 commit 70b2acd

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/emc/tooldata/tooldata_common.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ int tooldata_read_entry(const char *input_line,
8383
return -1;
8484
}
8585
if (input_line[0] == ';') {return 0;} //ignore leading ';'
86-
strcpy(work_line, input_line);
86+
strncpy(work_line, input_line, sizeof(work_line)-1);
87+
work_line[sizeof(work_line)-1] = 0;
8788

8889
CANON_TOOL_TABLE empty = tooldata_entry_init();
8990
toolno = empty.toolno;

src/emc/tooldata/tooldata_mmap.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
** along with this program; if not, write to the Free Software
1717
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1818
*/
19+
1920
#include <stdio.h>
2021
#include <sys/types.h>
21-
#include <unistd.h>
22-
#include <fcntl.h>
22+
#include <unistd.h> // write(2),lseek(2)
23+
#include <fcntl.h> // open(2)
2324
#include <sys/mman.h>
2425
#include <string.h>
2526
#include "rtapi_mutex.h"
@@ -132,7 +133,7 @@ int tool_mmap_creator(EMC_TOOL_STAT const * ptr,int random_toolchanger)
132133
toolstat = ptr; //note NULL for sai
133134
creator_fd = open(tool_mmap_fname(),
134135
TOOL_MMAP_CREATOR_OPEN_FLAGS,TOOL_MMAP_MODE);
135-
if (!creator_fd) {
136+
if (creator_fd < 0) {
136137
perror("tool_mmap_creator(): file open fail");
137138
exit(EXIT_FAILURE);
138139
}

0 commit comments

Comments
 (0)