aboutsummaryrefslogtreecommitdiffstats
path: root/exec/exec.c
diff options
context:
space:
mode:
Diffstat (limited to 'exec/exec.c')
-rw-r--r--exec/exec.c77
1 files changed, 5 insertions, 72 deletions
diff --git a/exec/exec.c b/exec/exec.c
index 935c94a59af..dae05755675 100644
--- a/exec/exec.c
+++ b/exec/exec.c
@@ -66,74 +66,6 @@ rpl_stpcpy (char *dest, const char *src)
66#define stpcpy rpl_stpcpy 66#define stpcpy rpl_stpcpy
67#endif /* !defined HAVE_STPCPY || !defined HAVE_DECL_STPCPY */ 67#endif /* !defined HAVE_STPCPY || !defined HAVE_DECL_STPCPY */
68 68
69#if !defined HAVE_STPNCPY || !defined HAVE_DECL_STPNCPY
70
71/* Copy no more than N bytes of SRC to DST, returning a pointer past
72 the last non-NUL byte written into DST. */
73
74static char *
75rpl_stpncpy (char *dest, const char *src, size_t n)
76{
77 char c, *s;
78 size_t n4;
79
80 s = dest;
81
82 if (n >= 4)
83 {
84 n4 = n >> 2;
85
86 for (;;)
87 {
88 c = *src++;
89 *dest++ = c;
90 if (c == '\0')
91 break;
92 c = *src++;
93 *dest++ = c;
94 if (c == '\0')
95 break;
96 c = *src++;
97 *dest++ = c;
98 if (c == '\0')
99 break;
100 c = *src++;
101 *dest++ = c;
102 if (c == '\0')
103 break;
104 if (--n4 == 0)
105 goto last_chars;
106 }
107 n -= dest - s;
108 goto zero_fill;
109 }
110
111 last_chars:
112 n &= 3;
113 if (n == 0)
114 return dest;
115
116 for (;;)
117 {
118 c = *src++;
119 --n;
120 *dest++ = c;
121 if (c == '\0')
122 break;
123 if (n == 0)
124 return dest;
125 }
126
127 zero_fill:
128 while (n-- > 0)
129 dest[n] = '\0';
130
131 return dest - 1;
132}
133
134#define stpncpy rpl_stpncpy
135#endif /* !defined HAVE_STPNCPY || !defined HAVE_DECL_STPNCPY */
136
137 69
138 70
139/* Executable reading functions. 71/* Executable reading functions.
@@ -1005,13 +937,14 @@ exec_0 (char *name, struct exec_tracee *tracee,
1005 else 937 else
1006 { 938 {
1007 /* If name is not absolute, then make it relative to TRACEE's 939 /* If name is not absolute, then make it relative to TRACEE's
1008 cwd. Use stpcpy, as sprintf is not reentrant. */ 940 cwd. Do not use sprintf at it is not reentrant and it
941 mishandles results longer than INT_MAX. */
1009 942
1010 if (name[0] && name[0] != '/') 943 if (name[0] && name[0] != '/')
1011 { 944 {
1012 /* Clear `buffer'. */ 945 /* Clear both buffers. */
1013 memset (buffer, 0, sizeof buffer); 946 memset (buffer, 0, sizeof buffer);
1014 memset (buffer1, 0, sizeof buffer); 947 memset (buffer1, 0, sizeof buffer1);
1015 948
1016 /* Copy over /proc, the PID, and /cwd/. */ 949 /* Copy over /proc, the PID, and /cwd/. */
1017 rewrite = stpcpy (buffer, "/proc/"); 950 rewrite = stpcpy (buffer, "/proc/");
@@ -1042,7 +975,7 @@ exec_0 (char *name, struct exec_tracee *tracee,
1042 975
1043 rewrite = buffer1 + link_size; 976 rewrite = buffer1 + link_size;
1044 remaining = buffer1 + sizeof buffer1 - rewrite - 1; 977 remaining = buffer1 + sizeof buffer1 - rewrite - 1;
1045 rewrite = stpncpy (rewrite, name, remaining); 978 memcpy (rewrite, name, strnlen (name, remaining));
1046 979
1047 /* Replace name with buffer1. */ 980 /* Replace name with buffer1. */
1048#ifndef REENTRANT 981#ifndef REENTRANT