* Fix ~40 off-by-one strncpy's
This commit is contained in:
parent
838e6b7466
commit
403aa4b36d
|
@ -81,12 +81,12 @@ R_API char *r_anal_cc_to_string (RAnal *anal, RAnalCC* cc) {
|
|||
snprintf (str, sizeof (str), "%s(", fcn->name);
|
||||
else if (cc->jump != -1LL)
|
||||
snprintf (str, sizeof (str), "0x%08"PFMT64x"(", cc->jump);
|
||||
else strncpy (str, "unk(", sizeof (str));
|
||||
else strncpy (str, "unk(", sizeof (str)-1);
|
||||
if (fcn) cc->nargs = (fcn->nargs>cc->nargs?cc->nargs:fcn->nargs);
|
||||
for (i=0; i<cc->nargs; i++) {
|
||||
if (cc->args[cc->nargs-i] != -1LL)
|
||||
snprintf (buf, sizeof (buf), "0x%"PFMT64x, cc->args[cc->nargs-i]);
|
||||
else strncpy (buf, "unk", sizeof (buf));
|
||||
else strncpy (buf, "unk", sizeof (buf)-1);
|
||||
strcat (str, buf);
|
||||
if (i<cc->nargs-1) strcat (str, ", ");
|
||||
}
|
||||
|
|
|
@ -99,10 +99,10 @@ R_API char *r_bin_demangle (RBin *bin, const char *str) {
|
|||
#ifdef TEST
|
||||
main() {
|
||||
char *out, str[128];
|
||||
strncpy (str, "_Z1hic", sizeof (str));
|
||||
strncpy (str, "main(Ljava/lang/String;I)V", sizeof (str));
|
||||
strncpy (str, "main([Ljava/lang/String;)V", sizeof (str));
|
||||
strncpy (str, "foo([III)Ljava/lang/Polla;", sizeof (str));
|
||||
strncpy (str, "_Z1hic", sizeof (str)-1);
|
||||
strncpy (str, "main(Ljava/lang/String;I)V", sizeof (str)-1);
|
||||
strncpy (str, "main([Ljava/lang/String;)V", sizeof (str)-1);
|
||||
strncpy (str, "foo([III)Ljava/lang/Polla;", sizeof (str)-1);
|
||||
//out = cplus_demangle_v3 (str, flags);
|
||||
out = r_bin_demangle_java (str); //, flags);
|
||||
printf ("INPUT (%s)\n", str);
|
||||
|
|
|
@ -137,7 +137,7 @@ struct r_bin_dyldcache_lib_t *r_bin_dyldcache_extract(struct r_bin_dyldcache_obj
|
|||
/* Fill r_bin_dyldcache_lib_t ret */
|
||||
ret->b = dbuf;
|
||||
libname = (char*)(bin->b->buf+libpath);
|
||||
strncpy (ret->path, libname, sizeof (ret->path));
|
||||
strncpy (ret->path, libname, sizeof (ret->path)-1);
|
||||
ret->size = libsz;
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -33,15 +33,15 @@ static RBinInfo* info(RBinArch *arch) {
|
|||
if (!(ret = R_NEW (RBinInfo)))
|
||||
return NULL;
|
||||
memset (ret, '\0', sizeof (RBinInfo));
|
||||
strncpy (ret->file, arch->file, R_BIN_SIZEOF_STRINGS);
|
||||
strncpy (ret->rpath, "NONE", R_BIN_SIZEOF_STRINGS);
|
||||
strncpy (ret->type, "fs", sizeof (ret->type)); // asm.arch
|
||||
strncpy (ret->bclass, "1.0", sizeof (ret->bclass));
|
||||
strncpy (ret->rclass, "fs", sizeof (ret->rclass)); // file.type
|
||||
strncpy (ret->os, "any", sizeof (ret->os));
|
||||
strncpy (ret->subsystem, "unknown", sizeof (ret->subsystem));
|
||||
strncpy (ret->machine, "any", sizeof (ret->machine));
|
||||
strncpy (ret->arch, fsname (arch), sizeof (ret->arch));
|
||||
strncpy (ret->file, arch->file, R_BIN_SIZEOF_STRINGS-1);
|
||||
strncpy (ret->rpath, "NONE", R_BIN_SIZEOF_STRINGS-1);
|
||||
strncpy (ret->type, "fs", sizeof (ret->type)-1); // asm.arch
|
||||
strncpy (ret->bclass, "1.0", sizeof (ret->bclass)-1);
|
||||
strncpy (ret->rclass, "fs", sizeof (ret->rclass)-1); // file.type
|
||||
strncpy (ret->os, "any", sizeof (ret->os)-1);
|
||||
strncpy (ret->subsystem, "unknown", sizeof (ret->subsystem)-1);
|
||||
strncpy (ret->machine, "any", sizeof (ret->machine)-1);
|
||||
strncpy (ret->arch, fsname (arch), sizeof (ret->arch)-1);
|
||||
ret->bits = 32;
|
||||
ret->big_endian = 0;
|
||||
ret->dbg_info = 0;
|
||||
|
|
|
@ -32,10 +32,10 @@ R_API int r_cmd_add_long(RCmd *cmd, const char *lcmd, const char *scmd, const ch
|
|||
RCmdLongItem *item = R_NEW (RCmdLongItem);
|
||||
if (item == NULL)
|
||||
return R_FALSE;
|
||||
strncpy (item->cmd, lcmd, sizeof (item->cmd));
|
||||
strncpy (item->cmd_short, scmd, sizeof (item->cmd_short));
|
||||
strncpy (item->cmd, lcmd, sizeof (item->cmd)-1);
|
||||
strncpy (item->cmd_short, scmd, sizeof (item->cmd_short)-1);
|
||||
item->cmd_len = strlen (lcmd);
|
||||
strncpy (item->desc, desc, sizeof (item->desc));
|
||||
strncpy (item->desc, desc, sizeof (item->desc)-1);
|
||||
list_add (&(item->list), &(cmd->lcmds));
|
||||
return R_TRUE;
|
||||
}
|
||||
|
@ -49,8 +49,8 @@ R_API int r_cmd_add(RCmd *c, const char *cmd, const char *desc, r_cmd_callback(c
|
|||
item = R_NEW (RCmdItem);
|
||||
c->cmds[idx] = item;
|
||||
}
|
||||
strncpy (item->cmd, cmd, sizeof (item->cmd));
|
||||
strncpy (item->desc, desc, sizeof (item->desc));
|
||||
strncpy (item->cmd, cmd, sizeof (item->cmd)-1);
|
||||
strncpy (item->desc, desc, sizeof (item->desc)-1);
|
||||
item->callback = cb;
|
||||
return R_TRUE;
|
||||
}
|
||||
|
|
|
@ -151,13 +151,13 @@ void config_visual_menu()
|
|||
cons_any_key();
|
||||
break;
|
||||
case ':':
|
||||
cons_set_raw(0);
|
||||
cons_set_raw (0);
|
||||
#if HAVE_LIB_READLINE
|
||||
char *ptr = readline(VISUAL_PROMPT);
|
||||
char *ptr = readline (VISUAL_PROMPT);
|
||||
if (ptr) {
|
||||
strncpy(cmd, ptr, sizeof(cmd));
|
||||
radare_cmd(cmd, 1);
|
||||
free(ptr);
|
||||
strncpy (cmd, ptr, sizeof (cmd)-1);
|
||||
radare_cmd (cmd, 1);
|
||||
free (ptr);
|
||||
}
|
||||
#else
|
||||
cmd[0]='\0';
|
||||
|
|
|
@ -27,7 +27,7 @@ R_API void r_cons_grep(const char *str) {
|
|||
str++;
|
||||
}
|
||||
|
||||
strncpy (buf, str, sizeof (buf));
|
||||
strncpy (buf, str, sizeof (buf)-1);
|
||||
ptr = buf;
|
||||
ptr3 = strchr (ptr, '['); // column number
|
||||
if (ptr3) {
|
||||
|
@ -57,10 +57,7 @@ R_API void r_cons_grep(const char *str) {
|
|||
do {
|
||||
optr = ptr;
|
||||
ptr = strchr (ptr, ','); // grep keywords
|
||||
if (ptr) {
|
||||
ptr[0] = '\0';
|
||||
ptr = ptr+1;
|
||||
}
|
||||
if (ptr) *ptr++ = '\0';
|
||||
// TODO: check if keyword > 64
|
||||
strncpy (cons->grep.strings[cons->grep.nstrings], optr, 63);
|
||||
cons->grep.nstrings++;
|
||||
|
|
|
@ -3900,23 +3900,23 @@ static int cmd_meta(void *data, const char *input) {
|
|||
p = strchr (t, ' ');
|
||||
if (p) {
|
||||
*p = '\0';
|
||||
strncpy (name, p+1, sizeof (name));
|
||||
strncpy (name, p+1, sizeof (name)-1);
|
||||
} else switch (type) {
|
||||
case 's':
|
||||
// TODO: filter \n and so on :)
|
||||
strncpy (name, t, sizeof (name));
|
||||
strncpy (name, t, sizeof (name)-1);
|
||||
r_core_read_at (core, addr, (ut8*)name, sizeof (name));
|
||||
break;
|
||||
default: {
|
||||
RFlagItem *fi = r_flag_get_i (core->flags, addr);
|
||||
if (fi) strncpy (name, fi->name, sizeof (name));
|
||||
if (fi) strncpy (name, fi->name, sizeof (name)-1);
|
||||
else sprintf (name, "ptr_%08"PFMT64x"", addr);
|
||||
}
|
||||
}
|
||||
n = atoi (input+1);
|
||||
} else {
|
||||
p = NULL;
|
||||
strncpy (name, t, sizeof (name));
|
||||
strncpy (name, t, sizeof (name)-1);
|
||||
}
|
||||
if (!n) n++;
|
||||
addr_end = addr + n;
|
||||
|
@ -3971,8 +3971,8 @@ static int cmd_meta(void *data, const char *input) {
|
|||
if (pattern && varsub)
|
||||
for (i = 0; i < R_ANAL_VARSUBS; i++)
|
||||
if (f->varsubs[i].pat[0] == '\0' || !strcmp (f->varsubs[i].pat, pattern)) {
|
||||
strncpy (f->varsubs[i].pat, pattern, 1024);
|
||||
strncpy (f->varsubs[i].sub, varsub, 1024);
|
||||
strncpy (f->varsubs[i].pat, pattern, 1023);
|
||||
strncpy (f->varsubs[i].sub, varsub, 1023);
|
||||
break;
|
||||
}
|
||||
} else eprintf ("Error: Function not found\n");
|
||||
|
|
|
@ -417,7 +417,7 @@ R_API void r_core_visual_config(RCore *core) {
|
|||
{
|
||||
char *ptr = readline(VISUAL_PROMPT);
|
||||
if (ptr) {
|
||||
strncpy(cmd, ptr, sizeof (cmd));
|
||||
strncpy(cmd, ptr, sizeof (cmd)-1);
|
||||
r_core_cmd(core, cmd, 1);
|
||||
free(ptr);
|
||||
}
|
||||
|
@ -502,7 +502,7 @@ R_API void r_core_visual_mounts (RCore *core) {
|
|||
if (mode==2) {
|
||||
r_str_chop_path (path);
|
||||
str = path + strlen (path);
|
||||
strncat (path, "/", sizeof (path)-strlen (path));
|
||||
strncat (path, "/", sizeof (path)-strlen (path)-1);
|
||||
list = r_fs_dir (core->fs, path);
|
||||
file = r_list_get_n (list, dir);
|
||||
if (file && file->type != 'd')
|
||||
|
@ -540,7 +540,7 @@ R_API void r_core_visual_mounts (RCore *core) {
|
|||
if (root)
|
||||
free (root);
|
||||
root = strdup ("/root");
|
||||
strncpy (path, root, sizeof (path));
|
||||
strncpy (path, root, sizeof (path)-1);
|
||||
mode = 2;
|
||||
} else {
|
||||
r_cons_printf ("Cannot mount partition\n");
|
||||
|
@ -554,15 +554,15 @@ R_API void r_core_visual_mounts (RCore *core) {
|
|||
}
|
||||
} else if (mode == 2){
|
||||
r_str_chop_path (path);
|
||||
strncat (path, "/", sizeof (path)-strlen (path));
|
||||
strncat (path, "/", sizeof (path)-strlen (path)-1);
|
||||
list = r_fs_dir (core->fs, path);
|
||||
file = r_list_get_n (list, dir);
|
||||
if (file) {
|
||||
if (file->type == 'd') {
|
||||
strncat (path, file->name, sizeof (path)-strlen (path));
|
||||
strncat (path, file->name, sizeof (path)-strlen (path)-1);
|
||||
r_str_chop_path (path);
|
||||
if (memcmp (root, path, strlen (root)-1))
|
||||
strncpy (path, root, sizeof (path));
|
||||
strncpy (path, root, sizeof (path)-1);
|
||||
} else {
|
||||
r_core_cmdf (core, "s 0x%"PFMT64x, file->off);
|
||||
r_fs_umount (core->fs, root);
|
||||
|
@ -631,14 +631,14 @@ R_API void r_core_visual_mounts (RCore *core) {
|
|||
if (mode == 2){
|
||||
r_str_chop_path (path);
|
||||
str = path + strlen (path);
|
||||
strncat (path, "/", sizeof (path)-strlen (path));
|
||||
strncat (path, "/", sizeof (path)-strlen (path)-1);
|
||||
list = r_fs_dir (core->fs, path);
|
||||
file = r_list_get_n (list, dir);
|
||||
if (file) {
|
||||
strncat (path, file->name, sizeof (path)-strlen (path));
|
||||
strncat (path, file->name, sizeof (path)-strlen (path)-1);
|
||||
r_str_chop_path (path);
|
||||
if (memcmp (root, path, strlen (root)-1))
|
||||
strncpy (path, root, sizeof (path));
|
||||
strncpy (path, root, sizeof (path)-1);
|
||||
file = r_fs_open (core->fs, path);
|
||||
if (file) {
|
||||
r_fs_read (core->fs, file, 0, file->size);
|
||||
|
@ -1007,7 +1007,7 @@ R_API void r_core_visual_define (RCore *core) {
|
|||
char *name;
|
||||
int n = r_str_nlen ((const char*)p+ntotal, plen-ntotal)+1;
|
||||
name = malloc (n+10);
|
||||
strcpy(name, "str.");
|
||||
strcpy (name, "str.");
|
||||
strncpy (name+4, (const char *)p+ntotal, n);
|
||||
r_flag_set (core->flags, name, off, n, 0);
|
||||
r_meta_add (core->anal->meta, R_META_TYPE_STRING,
|
||||
|
@ -1022,7 +1022,7 @@ R_API void r_core_visual_define (RCore *core) {
|
|||
char *name;
|
||||
int n = r_str_nlen ((const char*)p, plen)+1;
|
||||
name = malloc (n+10);
|
||||
strcpy(name, "str.");
|
||||
strcpy (name, "str.");
|
||||
strncpy (name+4, (const char *)p, n);
|
||||
r_flag_set (core->flags, name, off, n, 0);
|
||||
r_meta_add (core->anal->meta, R_META_TYPE_STRING, off, off+n, (const char *)p);
|
||||
|
|
|
@ -32,8 +32,7 @@ static const uchar Rcon[30] =
|
|||
//Expand a user-supplied key material into a session key.
|
||||
// key - The 128/192/256-bit user-key to use.
|
||||
|
||||
void aes_expkey(uchar *key, unsigned expkey[2][Nr+1][Nb])
|
||||
{
|
||||
void aes_expkey(uchar *key, unsigned expkey[2][Nr+1][Nb]) {
|
||||
unsigned tk[Nk], tt;
|
||||
int idx = 0, t = 0;
|
||||
int i, j, r;
|
||||
|
@ -289,15 +288,13 @@ uchar out[16];
|
|||
|
||||
typedef unsigned long long __int64;
|
||||
|
||||
unsigned long long rd_clock ()
|
||||
{
|
||||
unsigned long long rd_clock () {
|
||||
unsigned long long dwBoth;
|
||||
__asm__ volatile(".byte 0x0f, 0x31" : "=A"(dwBoth));
|
||||
return dwBoth;
|
||||
}
|
||||
|
||||
void certify ()
|
||||
{
|
||||
void certify () {
|
||||
unsigned expkey[2][Nr + 1][Nb], idx, diff;
|
||||
__int64 start, stop;
|
||||
|
||||
|
@ -330,13 +327,12 @@ void certify ()
|
|||
printf ("\n");
|
||||
}
|
||||
|
||||
void decrypt (char *mykey, char *name)
|
||||
{
|
||||
void decrypt (char *mykey, char *name) {
|
||||
unsigned expkey[2][Nr + 1][Nb];
|
||||
FILE *fd = fopen (name, "rb");
|
||||
int ch, idx = 0;
|
||||
|
||||
strncpy (key, mykey, sizeof(key));
|
||||
strncpy (key, mykey, sizeof (key)-1);
|
||||
aes_expkey (key, expkey);
|
||||
|
||||
while( ch = getc(fd), ch != EOF ) {
|
||||
|
@ -358,7 +354,7 @@ void encrypt (char *mykey, char *name)
|
|||
FILE *fd = fopen (name, "rb");
|
||||
int ch, idx = 0;
|
||||
|
||||
strncpy (key, mykey, sizeof(key));
|
||||
strncpy (key, mykey, sizeof (key)-1);
|
||||
aes_expkey (key, expkey);
|
||||
|
||||
while( ch = getc(fd), ch != EOF ) {
|
||||
|
|
|
@ -1542,7 +1542,7 @@ static RList *r_debug_native_map_get(RDebug *dbg) {
|
|||
|
||||
pos_c[-1] = (char)'0';
|
||||
pos_c[ 0] = (char)'x';
|
||||
strncpy (region2, pos_c-1, sizeof (region2));
|
||||
strncpy (region2, pos_c-1, sizeof (region2)-1);
|
||||
#endif // __KFBSD__
|
||||
region[0] = region2[0] = '0';
|
||||
region[1] = region2[1] = 'x';
|
||||
|
@ -1905,8 +1905,8 @@ static RList *r_debug_desc_native_list (int pid) {
|
|||
while((de = (struct dirent *)readdir(dd))) {
|
||||
if (de->d_name[0]=='.')
|
||||
continue;
|
||||
strncpy (file, path, sizeof (file));
|
||||
strncat (file, de->d_name, sizeof (file));
|
||||
strncpy (file, path, sizeof (file)-1);
|
||||
strncat (file, de->d_name, sizeof (file)-1);
|
||||
memset (buf, 0, sizeof (buf));
|
||||
readlink(file, buf, sizeof (buf));
|
||||
type = perm = 0;
|
||||
|
|
|
@ -532,7 +532,7 @@ R_API int r_fs_prompt (RFS *fs, char *root) {
|
|||
eprintf ("%s\n", path);
|
||||
} else if (!memcmp (buf, "cd ", 3)) {
|
||||
char opath[4096];
|
||||
strncpy (opath, path, sizeof (opath));
|
||||
strncpy (opath, path, sizeof (opath)-1);
|
||||
input = buf+3;
|
||||
while (*input == ' ')
|
||||
input++;
|
||||
|
|
|
@ -37,7 +37,7 @@ R_API void r_io_section_add(RIO *io, ut64 offset, ut64 vaddr, ut64 size, ut64 vs
|
|||
s->vsize = vsize;
|
||||
s->rwx = rwx;
|
||||
if (!update) {
|
||||
if (name) strncpy (s->name, name, sizeof (s->name));
|
||||
if (name) strncpy (s->name, name, sizeof (s->name)-1);
|
||||
else *s->name = '\0';
|
||||
//r_list_append (io->sections, s);
|
||||
r_list_add_sorted (io->sections, s, cmpaddr);
|
||||
|
|
|
@ -283,7 +283,7 @@ R_API int r_lib_add_handler(RLib *lib,
|
|||
handler->type = type;
|
||||
r_list_append (lib->handlers, handler);
|
||||
}
|
||||
strncpy (handler->desc, desc, sizeof (handler->desc));
|
||||
strncpy (handler->desc, desc, sizeof (handler->desc)-1);
|
||||
handler->user = user;
|
||||
handler->constructor = cb;
|
||||
handler->destructor = dt;
|
||||
|
|
|
@ -222,7 +222,7 @@ int file_pipe2file(RMagic *ms, int fd, const void *startbuf, size_t nbytes) {
|
|||
char buf[4096];
|
||||
int r, tfd;
|
||||
|
||||
strncpy (buf, "/tmp/file.XXXXXX", sizeof (buf));
|
||||
strncpy (buf, "/tmp/file.XXXXXX", sizeof (buf)-1);
|
||||
tfd = mkstemp (buf);
|
||||
r = errno;
|
||||
(void)unlink(buf);
|
||||
|
|
|
@ -238,10 +238,10 @@ int file_fsmagic(struct r_magic_set *ms, const char *fn, struct stat *sb) {
|
|||
return 1;
|
||||
}
|
||||
//(void)strlcpy(buf2, fn, sizeof buf2); /* take dir part */
|
||||
strncpy (buf2, fn, sizeof (buf2));
|
||||
strncpy (buf2, fn, sizeof (buf2)-1);
|
||||
buf2[tmp - fn + 1] = '\0';
|
||||
//(void)strlcat(buf2, buf, sizeof buf2); /* plus (rel) link */
|
||||
strncpy (buf2, buf, sizeof (buf2));
|
||||
strncpy (buf2, buf, sizeof (buf2)-1);
|
||||
tmp = buf2;
|
||||
}
|
||||
if (stat (tmp, &tstatbuf) < 0)
|
||||
|
|
|
@ -34,7 +34,7 @@ static int r_socket_unix_connect(RSocket *s, const char *file) {
|
|||
}
|
||||
// TODO: set socket options
|
||||
addr.sun_family = AF_UNIX;
|
||||
strncpy (addr.sun_path, file, sizeof(addr.sun_path));
|
||||
strncpy (addr.sun_path, file, sizeof (addr.sun_path)-1);
|
||||
|
||||
if (connect (sock, (struct sockaddr *)&addr, sizeof(addr))==-1) {
|
||||
close (sock);
|
||||
|
@ -53,7 +53,7 @@ R_API int r_socket_unix_listen (RSocket *s, const char *file) {
|
|||
return R_FALSE;
|
||||
// TODO: set socket options
|
||||
unix_name.sun_family = AF_UNIX;
|
||||
strncpy (unix_name.sun_path, file, sizeof(unix_name.sun_path));
|
||||
strncpy (unix_name.sun_path, file, sizeof (unix_name.sun_path)-1);
|
||||
|
||||
/* just to make sure there is no other socket file */
|
||||
unlink (unix_name.sun_path);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* radare - LGPL - Copyright 2008-2010 pancake<nopcode.org> */
|
||||
/* radare - LGPL - Copyright 2008-2011 pancake<nopcode.org> */
|
||||
|
||||
#include "r_vm.h"
|
||||
|
||||
|
@ -6,8 +6,8 @@ R_API int r_vm_op_add(struct r_vm_t *vm, const char *op, const char *str) {
|
|||
RVmOp *o = R_NEW (RVmOp);
|
||||
if (o == NULL)
|
||||
return -1;
|
||||
strncpy(o->opcode, op, sizeof(o->opcode));
|
||||
strncpy(o->code, str, sizeof(o->code));
|
||||
strncpy (o->opcode, op, sizeof (o->opcode)-1);
|
||||
strncpy (o->code, str, sizeof (o->code)-1);
|
||||
list_add_tail(&(o->list), &vm->ops);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue