Commit 59724dc1 authored by Jonathan Wilkes's avatar Jonathan Wilkes
Browse files

more fixes for warnings, mainly string truncation problems with snprintf et al

parent f3d19054
...@@ -117,7 +117,7 @@ static int sys_do_load_lib(t_canvas *canvas, const char *objectname, ...@@ -117,7 +117,7 @@ static int sys_do_load_lib(t_canvas *canvas, const char *objectname,
const char *path) const char *path)
{ {
char symname[MAXPDSTRING], filename[MAXPDSTRING], dirbuf[MAXPDSTRING], char symname[MAXPDSTRING], filename[MAXPDSTRING], dirbuf[MAXPDSTRING],
*nameptr, altsymname[MAXPDSTRING]; *nameptr;
const char *classname, *cnameptr; const char *classname, *cnameptr;
void *dlobj; void *dlobj;
t_xxx makeout = NULL; t_xxx makeout = NULL;
...@@ -159,7 +159,7 @@ static int sys_do_load_lib(t_canvas *canvas, const char *objectname, ...@@ -159,7 +159,7 @@ static int sys_do_load_lib(t_canvas *canvas, const char *objectname,
if (hexmunge) if (hexmunge)
{ {
memmove(symname+6, symname, strlen(symname)+1); memmove(symname+6, symname, strlen(symname)+1);
strncpy(symname, "setup_", 6); memcpy(symname, "setup_", 6);
} }
else strcat(symname, "_setup"); else strcat(symname, "_setup");
......
...@@ -368,7 +368,11 @@ int sys_main(int argc, char **argv) ...@@ -368,7 +368,11 @@ int sys_main(int argc, char **argv)
if (getuid() != geteuid()) if (getuid() != geteuid())
{ {
fprintf(stderr, "warning: canceling setuid privilege\n"); fprintf(stderr, "warning: canceling setuid privilege\n");
setuid(getuid()); if (setuid(getuid()) < 0)
{
fprintf(stderr, "error: couldn't cancel setuid privilege");
exit(1);
}
} }
#endif /* _WIN32 */ #endif /* _WIN32 */
pd_init(); /* start the message system */ pd_init(); /* start the message system */
...@@ -640,7 +644,7 @@ void sys_findprogdir(char *progname) ...@@ -640,7 +644,7 @@ void sys_findprogdir(char *progname)
/* complicated layout: lib dir is the one we just stat-ed above */ /* complicated layout: lib dir is the one we just stat-ed above */
sys_libdir = gensym(sbuf2); sys_libdir = gensym(sbuf2);
/* gui lives in .../lib/pd-l2ork/bin */ /* gui lives in .../lib/pd-l2ork/bin */
strncpy(sbuf2, sbuf, FILENAME_MAX-30); strncpy(sbuf2, sbuf, FILENAME_MAX);
sbuf[FILENAME_MAX-30] = 0; sbuf[FILENAME_MAX-30] = 0;
strcat(sbuf2, "/lib/pd-l2ork/bin"); strcat(sbuf2, "/lib/pd-l2ork/bin");
sys_guidir = gensym(sbuf2); sys_guidir = gensym(sbuf2);
...@@ -649,8 +653,8 @@ void sys_findprogdir(char *progname) ...@@ -649,8 +653,8 @@ void sys_findprogdir(char *progname)
{ {
/* simple layout: lib dir is the parent */ /* simple layout: lib dir is the parent */
/* gui lives in .../bin */ /* gui lives in .../bin */
strncpy(sbuf2, sbuf, FILENAME_MAX-30); strncpy(sbuf2, sbuf, FILENAME_MAX);
strncpy(appbuf, sbuf, FILENAME_MAX-30); strncpy(appbuf, sbuf, FILENAME_MAX);
sbuf[FILENAME_MAX-30] = 0; sbuf[FILENAME_MAX-30] = 0;
sys_libdir = gensym(sbuf); sys_libdir = gensym(sbuf);
strcat(sbuf2, "/bin"); strcat(sbuf2, "/bin");
......
...@@ -822,7 +822,9 @@ void glob_midi_dialog(t_pd *dummy, t_symbol *s, int argc, t_atom *argv) ...@@ -822,7 +822,9 @@ void glob_midi_dialog(t_pd *dummy, t_symbol *s, int argc, t_atom *argv)
{ {
int i, nindev, noutdev; int i, nindev, noutdev;
int newmidiindev[10], newmidioutdev[10]; int newmidiindev[10], newmidioutdev[10];
#ifdef USEAPI_ALSA
int alsadevin, alsadevout; int alsadevin, alsadevout;
#endif
for (i = 0; i < 10; i++) for (i = 0; i < 10; i++)
{ {
...@@ -846,10 +848,9 @@ void glob_midi_dialog(t_pd *dummy, t_symbol *s, int argc, t_atom *argv) ...@@ -846,10 +848,9 @@ void glob_midi_dialog(t_pd *dummy, t_symbol *s, int argc, t_atom *argv)
noutdev++; noutdev++;
} }
} }
#ifdef USEAPI_ALSA
alsadevin = atom_getintarg(20, argc, argv); alsadevin = atom_getintarg(20, argc, argv);
alsadevout = atom_getintarg(21, argc, argv); alsadevout = atom_getintarg(21, argc, argv);
#ifdef USEAPI_ALSA
/* invent a story so that saving/recalling "settings" will /* invent a story so that saving/recalling "settings" will
be able to restore the number of devices. ALSA MIDI handling be able to restore the number of devices. ALSA MIDI handling
uses its own set of variables. LATER figure out how to get uses its own set of variables. LATER figure out how to get
......
...@@ -77,13 +77,23 @@ static void doerror(const void *object, const char *s) ...@@ -77,13 +77,23 @@ static void doerror(const void *object, const char *s)
static void dologpost(const void *object, const int level, const char *s) static void dologpost(const void *object, const int level, const char *s)
{ {
char upbuf[MAXPDSTRING]; /* 1. s is at most MAXPDSTRING, but we're prepending a stupid header
upbuf[MAXPDSTRING-1]=0; below. So for sanity, we first overallocate here to ensure the stupid
header doesn't end up overflowing the buffer. */
char upbuf[MAXPDSTRING * 2];
// what about sys_printhook_verbose ? // what about sys_printhook_verbose ?
if (sys_printhook) if (sys_printhook)
{ {
snprintf(upbuf, MAXPDSTRING-1, "verbose(%d): %s", level, s); /* 2. The "n" in snprintf stands for "evil": we have to subtract one
from total size so the null doesn't get truncated */
snprintf(upbuf, MAXPDSTRING * 2 - 1, "verbose(%d): %s", level, s);
/* 3. Finally, we add a null at MAXPDSTRING-1 so that we end up with
a string that fits inside MAXPDSTRING for use with t_symbol, etc.
If anyone knows how I was *supposed* to do this safely within the
constraints of C's stupid stdlib, please teach me... */
upbuf[MAXPDSTRING-1]=0;
(*sys_printhook)(upbuf); (*sys_printhook)(upbuf);
} }
else if (sys_printtostderr) else if (sys_printtostderr)
......
...@@ -80,10 +80,15 @@ int u8_utf8toucs2(uint16_t *dest, int sz, char *src, int srcsz) ...@@ -80,10 +80,15 @@ int u8_utf8toucs2(uint16_t *dest, int sz, char *src, int srcsz)
} }
ch = 0; ch = 0;
switch (nb) { switch (nb) {
/* these fall through deliberately */ /* these fall through deliberately, but commenting each explicitly
seems to quiet the compiler. If that's not future proof we
can just use copy/pasta and add the break statements */
case 3: ch += (unsigned char)*src++; ch <<= 6; case 3: ch += (unsigned char)*src++; ch <<= 6;
/* fall through */
case 2: ch += (unsigned char)*src++; ch <<= 6; case 2: ch += (unsigned char)*src++; ch <<= 6;
/* fall through */
case 1: ch += (unsigned char)*src++; ch <<= 6; case 1: ch += (unsigned char)*src++; ch <<= 6;
/* fall through */
case 0: ch += (unsigned char)*src++; case 0: ch += (unsigned char)*src++;
} }
ch -= offsetsFromUTF8[nb]; ch -= offsetsFromUTF8[nb];
......
...@@ -1655,10 +1655,10 @@ void *abinfo_new(void) ...@@ -1655,10 +1655,10 @@ void *abinfo_new(void)
if(!abframe) if(!abframe)
{ {
error("abinfo: only instantiable inside an ab object"); error("abinfo: only instantiable inside an ab object");
x = 0; return (0);
} }
else else
x = pd_new(text_class); return pd_new(text_class);
} }
return (x); return (x);
} }
......
...@@ -303,7 +303,7 @@ static int netsend_dosend(t_netsend *x, int sockfd, ...@@ -303,7 +303,7 @@ static int netsend_dosend(t_netsend *x, int sockfd,
bp += res; bp += res;
} }
} }
done: /* done: */
if (!x->x_bin) if (!x->x_bin)
{ {
t_freebytes(buf, length); t_freebytes(buf, length);
......
...@@ -348,6 +348,7 @@ t_binbuf *pointertobinbuf(t_pd *x, t_gpointer *gp, t_symbol *s, ...@@ -348,6 +348,7 @@ t_binbuf *pointertobinbuf(t_pd *x, t_gpointer *gp, t_symbol *s,
/* these are unused; they copy text from this object to and from a text /* these are unused; they copy text from this object to and from a text
field in a scalar. */ field in a scalar. */
/*
static void text_define_frompointer(t_text_define *x, t_gpointer *gp, static void text_define_frompointer(t_text_define *x, t_gpointer *gp,
t_symbol *s) t_symbol *s)
{ {
...@@ -359,7 +360,10 @@ static void text_define_frompointer(t_text_define *x, t_gpointer *gp, ...@@ -359,7 +360,10 @@ static void text_define_frompointer(t_text_define *x, t_gpointer *gp,
binbuf_add(x->x_textbuf.b_binbuf, binbuf_getnatom(b), binbuf_getvec(b)); binbuf_add(x->x_textbuf.b_binbuf, binbuf_getnatom(b), binbuf_getvec(b));
} }
} }
*/
/* This doesn't seem to be used, either... */
/*
static void text_define_topointer(t_text_define *x, t_gpointer *gp, t_symbol *s) static void text_define_topointer(t_text_define *x, t_gpointer *gp, t_symbol *s)
{ {
t_binbuf *b = pointertobinbuf(&x->x_textbuf.b_ob.ob_pd, t_binbuf *b = pointertobinbuf(&x->x_textbuf.b_ob.ob_pd,
...@@ -382,6 +386,7 @@ static void text_define_topointer(t_text_define *x, t_gpointer *gp, t_symbol *s) ...@@ -382,6 +386,7 @@ static void text_define_topointer(t_text_define *x, t_gpointer *gp, t_symbol *s)
} }
} }
} }
*/
/* bang: output a pointer to a struct containing this text */ /* bang: output a pointer to a struct containing this text */
void text_define_bang(t_text_define *x) void text_define_bang(t_text_define *x)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment