Changeset 4848:0b3d312d4253 in roaraudio


Ignore:
Timestamp:
04/08/11 19:53:31 (13 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

updated add_driver() to check the args and fix segfauls if user gave incorrect parameters

File:
1 edited

Legend:

Unmodified
Added
Removed
  • roard/roard.c

    r4846 r4848  
    982982 int ret; 
    983983 int _alive; 
     984 char * _opts; 
    984985 
    985986 if ( drv != NULL ) 
     
    994995  _alive = alive; // save global alive setting 
    995996 
    996   ret = add_output(drvs[i], dev, opts, prim, count); 
     997  if ( opts == NULL ) { 
     998   _opts = NULL; 
     999  } else { 
     1000   _opts = roar_mm_strdup(opts); 
     1001  } 
     1002 
     1003  ret = add_output(drvs[i], dev, _opts, prim, count); 
     1004 
     1005  if ( _opts != NULL ) 
     1006   roar_mm_free(_opts); 
     1007 
    9971008  if ( ret != -1 ) 
    9981009   return ret; 
     
    10051016} 
    10061017#endif 
     1018 
     1019#define _CKPARAM(n) if ( n (v == NULL) ) { \ 
     1020                     ROAR_WARN("add_output(drv='%s', dev='%s', opts=..., prim=%i, count=%i): " \ 
     1021                               "Parameter '%s' expects %s parameter.", \ 
     1022                               drv, dev, prim, count, k, (n 1) ? "a" : "no"); \ 
     1023                     error++; \ 
     1024                    } else 
    10071025 
    10081026int add_output (char * drv, char * dev, char * opts, int prim, int count) { 
     
    10921110  ROAR_DBG("add_output(*): opts: k='%s', v='%s'", k, v); 
    10931111  if ( strcmp(k, "rate") == 0 ) { 
    1094    s->info.rate = atoi(v); 
     1112   _CKPARAM() 
     1113    s->info.rate = atoi(v); 
    10951114  } else if ( strcmp(k, "channels") == 0 ) { 
    1096    s->info.channels = atoi(v); 
     1115   _CKPARAM() 
     1116    s->info.channels = atoi(v); 
    10971117  } else if ( strcmp(k, "bits") == 0 ) { 
    1098    s->info.bits = atoi(v); 
     1118   _CKPARAM() 
     1119    s->info.bits = atoi(v); 
    10991120  } else if ( strcmp(k, "codec") == 0 ) { 
    1100    if ( (s->info.codec = roar_str2codec(v)) == -1 ) { 
    1101     ROAR_ERR("add_output(*): unknown codec '%s'", v); 
    1102     error++; 
    1103    } 
     1121   _CKPARAM() 
     1122    if ( (s->info.codec = roar_str2codec(v)) == -1 ) { 
     1123     ROAR_ERR("add_output(*): unknown codec '%s'", v); 
     1124     error++; 
     1125    } 
    11041126  } else if ( strcmp(k, "q") == 0 ) { 
    1105    q = atof(v); 
     1127   _CKPARAM() 
     1128    q = atof(v); 
    11061129  } else if ( strcmp(k, "blocks") == 0 ) { 
    1107    blocks = atoi(v); 
     1130   _CKPARAM() 
     1131    blocks = atoi(v); 
    11081132  } else if ( strcmp(k, "blocksize") == 0 ) { 
    1109    blocksize = atoi(v); 
     1133   _CKPARAM() 
     1134    blocksize = atoi(v); 
    11101135  } else if ( strcmp(k, "mmap") == 0 ) { 
    1111    f_mmap = 1; 
     1136   _CKPARAM(!) 
     1137    f_mmap = 1; 
    11121138  } else if ( strcmp(k, "subsystem") == 0 ) { 
    1113    if ( !strcasecmp(v, "wave") || !strcasecmp(v, "waveform") ) { 
    1114     dir = ROAR_DIR_OUTPUT; 
     1139   _CKPARAM() { 
     1140    if ( !strcasecmp(v, "wave") || !strcasecmp(v, "waveform") ) { 
     1141     dir = ROAR_DIR_OUTPUT; 
    11151142#ifndef ROAR_WITHOUT_DCOMP_MIDI 
    1116    } else if ( !strcasecmp(v, "midi") ) { 
    1117     dir = ROAR_DIR_MIDI_OUT; 
     1143    } else if ( !strcasecmp(v, "midi") ) { 
     1144     dir = ROAR_DIR_MIDI_OUT; 
    11181145#endif 
    11191146#ifndef ROAR_WITHOUT_DCOMP_LIGHT 
    1120    } else if ( !strcasecmp(v, "light") ) { 
    1121     dir = ROAR_DIR_LIGHT_OUT; 
     1147    } else if ( !strcasecmp(v, "light") ) { 
     1148     dir = ROAR_DIR_LIGHT_OUT; 
    11221149#endif 
    11231150#ifndef ROAR_WITHOUT_DCOMP_RAW 
    1124    } else if ( !strcasecmp(v, "raw") ) { 
    1125     dir = ROAR_DIR_RAW_OUT; 
    1126 #endif 
    1127    } else if ( !strcasecmp(v, "complex") ) { 
    1128     dir = ROAR_DIR_COMPLEX_OUT; 
    1129    } else { 
    1130     ROAR_ERR("add_output(*): unknown/unsupported subsystem '%s'", k); 
    1131     error++; 
     1151    } else if ( !strcasecmp(v, "raw") ) { 
     1152     dir = ROAR_DIR_RAW_OUT; 
     1153#endif 
     1154    } else if ( !strcasecmp(v, "complex") ) { 
     1155     dir = ROAR_DIR_COMPLEX_OUT; 
     1156    } else { 
     1157     ROAR_ERR("add_output(*): unknown/unsupported subsystem '%s'", k); 
     1158     error++; 
     1159    } 
    11321160   } 
    11331161  // DMX: 
    11341162  } else if ( strcmp(k, "channel") == 0 ) { 
    1135    channel  = atoi(v); 
    1136    if ( channel < 0 || channel > 65535 ) { 
    1137     ROAR_ERR("add_output(*): Invalide channel (not within 0..65535): %i", channel); 
    1138     channel = -1; 
    1139     error++; 
     1163   _CKPARAM() { 
     1164    channel  = atoi(v); 
     1165    if ( channel < 0 || channel > 65535 ) { 
     1166     ROAR_ERR("add_output(*): Invalide channel (not within 0..65535): %i", channel); 
     1167     channel = -1; 
     1168     error++; 
     1169    } 
    11401170   } 
    11411171  } else if ( strcmp(k, "universe") == 0 ) { 
    1142    universe = atoi(v); 
    1143    if ( universe < 0 || universe > 255 ) { 
    1144     ROAR_ERR("add_output(*): Invalide universe (not within 0..255): %i", universe); 
    1145     universe = -1; 
    1146     error++; 
     1172   _CKPARAM() { 
     1173    universe = atoi(v); 
     1174    if ( universe < 0 || universe > 255 ) { 
     1175     ROAR_ERR("add_output(*): Invalide universe (not within 0..255): %i", universe); 
     1176     universe = -1; 
     1177     error++; 
     1178    } 
    11471179   } 
    11481180 
    11491181  } else if ( strcmp(k, "name") == 0 ) { 
    1150    if ( streams_set_name(stream, v) == -1 ) { 
    1151     ROAR_ERR("add_output(*): Can not set Stream name"); 
    1152     error++; 
     1182   _CKPARAM() { 
     1183    if ( streams_set_name(stream, v) == -1 ) { 
     1184     ROAR_ERR("add_output(*): Can not set Stream name"); 
     1185     error++; 
     1186    } 
    11531187   } 
    11541188 
    11551189  } else if ( strcmp(k, "meta") == 0 ) { 
    1156    streams_set_flag(stream, ROAR_FLAG_META); 
     1190   _CKPARAM(!) 
     1191    streams_set_flag(stream, ROAR_FLAG_META); 
    11571192  } else if ( strcmp(k, "sync") == 0 ) { 
    1158    sync = 1; 
     1193   _CKPARAM(!) 
     1194    sync = 1; 
    11591195  } else if ( strcmp(k, "primary") == 0 ) { 
    1160    prim = 1; 
     1196   _CKPARAM(!) 
     1197    prim = 1; 
    11611198 
    11621199  } else if ( strcmp(k, "cleanmeta") == 0 ) { 
    1163    streams_set_flag(stream, ROAR_FLAG_CLEANMETA); 
     1200   _CKPARAM(!) 
     1201    streams_set_flag(stream, ROAR_FLAG_CLEANMETA); 
    11641202  } else if ( strcmp(k, "autoconf") == 0 ) { 
    1165    streams_set_flag(stream, ROAR_FLAG_AUTOCONF); 
     1203   _CKPARAM(!) 
     1204    streams_set_flag(stream, ROAR_FLAG_AUTOCONF); 
    11661205  } else if ( strcmp(k, "recsource") == 0 ) { 
    1167    streams_set_flag(stream, ROAR_FLAG_RECSOURCE); 
     1206   _CKPARAM(!) 
     1207    streams_set_flag(stream, ROAR_FLAG_RECSOURCE); 
    11681208  } else if ( strcmp(k, "passmixer") == 0 ) { 
    1169    streams_set_flag(stream, ROAR_FLAG_PASSMIXER); 
     1209   _CKPARAM(!) 
     1210    streams_set_flag(stream, ROAR_FLAG_PASSMIXER); 
    11701211  } else if ( strcmp(k, "recsource") == 0 ) { 
    1171    streams_set_flag(stream, ROAR_FLAG_RECSOURCE); 
     1212   _CKPARAM(!) 
     1213    streams_set_flag(stream, ROAR_FLAG_RECSOURCE); 
    11721214  } else { 
    11731215   ROAR_ERR("add_output(*): unknown option '%s'", k); 
     
    26092651#endif 
    26102652 
    2611  add_default_output(o_drv, o_dev, o_opts, o_prim, o_count); 
     2653 if ( add_default_output(o_drv, o_dev, o_opts, o_prim, o_count) == -1 ) { 
     2654  ROAR_ERR("Can not initialize default driver"); 
     2655  return 1; 
     2656 } 
    26122657 
    26132658 ROAR_INFO("Server config: rate=%i, bits=%i, chans=%i", ROAR_DBG_INFO_NOTICE, sa.rate, sa.bits, sa.channels); 
Note: See TracChangeset for help on using the changeset viewer.