1. 06 Jan, 2011 3 commits
  2. 05 Jan, 2011 1 commit
  3. 03 Jan, 2011 2 commits
  4. 01 Jan, 2011 10 commits
    • Moe Jette's avatar
      c5911e61
    • Moe Jette's avatar
      Patch from Gerrit: 09_hostlist__hostlist_deranged_string.diff · 8274e453
      Moe Jette authored
      hostlist_deranged_string(): test for overflow
      			    
      This builds upon the preceding patch, exploiting that hostrange_to_string()
       * returns >= 0 when it has terminated the string with '\0', where  either 
         - n == 0 and it has not written anything or
         - it has written at most n > 0 characters, indicated by returning  n-1 >= 0;
       * returns a negative value to indicate truncation.
      
      Hence hostrange_deranged_string() changed as follows:
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       * added 'len < n' as loop condition, to catch the case 'n == 0'
         (also exploiting that NUL-termination is only needed on error);
       * separator now is inserted after all non-first elements
         (to avoid having to undo the last separator);
       * as in preceding patch, replaced 'truncated' variable by a jump label.
      8274e453
    • Moe Jette's avatar
      patch from Gerrit: 08_hostlist__hostrange_to_string.diff · e2bc04b5
      Moe Jette authored
      hostrange_to_string(): truncation checks
      
       * turned 'truncated' variable into jump label;
       * loop changes so that the pre-condition is always len < n:
         - if len >= n inside the loop, the a jump to 'truncated' follows,
         - hence loop post-condition is also len < n, so that buf[len] = '\0' works;
       * consistently check ret=snprintf() for "ret < 0 || (len += ret) >= n",
         - if dims > 1, also tests to ensure that len + dims < n,
         - further overflow test after incrementing len for  separator;
       * moved separator test up (inserted when i > hr->lo)
         (to avoid having to undo the last separator).
      e2bc04b5
    • Moe Jette's avatar
      patch from Gerrit: 07_hostlist__hostrange_pop__hostrange_shift.diff · a9f9ff68
      Moe Jette authored
      hostrange_pop()/hostrange_shift(): test for overflow
      
      hostrange_pop():				   
       * retrofitted out_of_memory() test after strdup;
       * tested for negative length/overflow before the while-loop,
         making sure that 'dims' characters also fit in;
       * second snprintf is not tested.
      
      hostrange_shift(): 
       * analogous changes (second snprintf also not tested). 
      a9f9ff68
    • Moe Jette's avatar
      Patch from Gerrit: 06_hostlist__host_prefix_end.diff · c5918ee9
      Moe Jette authored
      host_prefix_end(): save variable, factor out common expressions
      
      This saves one variable and factors out the condition common
      to the if/else branches.06_hostlist__host_prefix_end.diff
      
       * return type of strlen is unsigned (size_t), hence strlen(hostname) >= 0;
       * both while-loops require idx >= 0, hence -1 is returned
         if strlen(hostname) == 0.
      c5918ee9
    • Moe Jette's avatar
      Patch from Gerrit: 05_hostlist__get_bracketed_list.diff · 951861bb
      Moe Jette authored
      _get_bracketed_list(): simplify and look for overflow conditions
      		       
       * initial test requires that len + 4 < n,
         - this ensures enough space for '[', ']', one digit and '\0',
         - simplifies many subsequent tests (e.g. for bracket_needed);
       * loop has been reorganized:
         - pre-condition:       len + 3 < n
         - loop run-condition:  len < n-1
         - post-condition:      len < n-1 (otherwise, it returns n);
       * therefore len < n after adding ']'
       * and thus len < n when calling buf[len] = '\0'.
      951861bb
    • Moe Jette's avatar
      Patch from Gerrit: 04_hostlist__hostrange_numstr.diff · ae7ce172
      Moe Jette authored
      hostrange_numstr(): overflow cases
      
      This checks hostrange_numstr() for overflow cases:		    
       * requires n > dims (if dims=1, min 1 digit, else dim + '\0' digits);
         - this precondition simplifies many subsequent checks and
         - addresses if (len == n) then len++ means buf[len] = buf[n];
       * also checks return value of the snprintfs.
      ae7ce172
    • Moe Jette's avatar
      Patch from Gerrit: hostlist___hostrange_string__hostlist_next.diff · ba60b6a0
      Moe Jette authored
      _hostrange_string()/hostlist_next(): test for overrun
      
      This lets the two functions _hostrange_string/hostlist_next return NULL in case
      there is an overflow condition.
      
      Two possible overflow conditions were analyzed:
       * if len <= MAXHOSTNAMELEN + 15 and the '=' is the case, then len++ means
         that buf[len] = '\0' is the same as buf[MAXHOSTNAMELEN + 16], which would
         cause a segmentation violation - fixed by checking length beforehand;
       * also checks the return value of the snprintfs,
       * and requires 'dims' as minimum suffix length.
      ba60b6a0
    • Moe Jette's avatar
      Patch from Gerrit: 02_hostlist_get_base_depends_on_dims.diff · c029193b
      Moe Jette authored
      hostlist: let hostlist_get_base() depend on current dimensions
      
      This patch saves one call to slurmdb_setup_cluster_dims(): exploiting
      that the dimensions for which hostlist_get_base() is called are known
      in all contexts in which the function is used.
      c029193b
    • Moe Jette's avatar
      patch from Gerrit: 01_hostlist_parse_int_into_array.diff · 5d19de3b
      Moe Jette authored
      hostlist: shorter conversion
      
      This replaces the hostlist_parse_int_to_array() routine with a simpler and 
      equivalent routine. I was wondering what the algorithm does, when suddenly
      the flow became simpler.
      
      Problem: we want to create an array 'out' of 'dims' dimensions where
               out[i], 0 <= i < dims, has the coefficients a_j of the polynomial
      
      	 a_(dims-1) * B^(dims-1) + ... + a_1 * B + a_0
      
      	 where B is the base of the polynomial 'in' and
      	    a_0        = out[dims - 1]
      	    a_1        = out[dims - 2]
      	    ...
      	    a_(dims-1) = a[0]
      
      Using the Horner Scheme, 'in' is represented as
       * dims = 1:                                   a_0 = out[0]
       * dims = 2:                        a_1  * B + a_0 = out[0] * B + out[1]
       * dims = 3:            (a_2  * B + a_1) * B + a_0 
       * dims = 4: ((a_3 * B + a_2) * B + a_1) * B + a_0
         ...
       * dims = n: ((a_(n-1) * B + a_(n-2)) * B ... + a_1) * B + a_0
      
      We can get a_0 = out[dims-1] as "in % B" and then derive a_1, a_2, ... by
      first dividing by B, and then repeating the process.
      
      If in is 0, all 'dims' coefficients are 0, if it is negative, all coefficients
      are negative.
      5d19de3b
  5. 29 Dec, 2010 7 commits
  6. 28 Dec, 2010 15 commits
  7. 27 Dec, 2010 2 commits