Example #1
0
    def _parse_rtn_paths(self, func, rtn, rtn_paths):
        for rtn_path in rtn_paths:
            if (not rtn_path.get_conds()) or (not rtn_path.get_calls()):
                continue

            for call in rtn_path.get_calls():
                callee = call.get_feature()
                if not self._is_valid(callee, func):
                    continue

                # get full func now
                callee = call.callname()
                rtn = errno_to_str(rtn)
                key = "%s on %s path" % (callee, rtn)
                api = self.apis.get(key, ExternAPI(callee, rtn))
                has_cond = False
                for cond in rtn_path.get_conds():
                    feature = cond.get_feature()
                    if feature.find(callee) != -1:
                        vrange = self._parse_ranges(cond.get_ranges())
                        api.add(func, vrange)
                        has_cond = True
                        break
                if not has_cond:
                    api.add(func, "")
                self.apis[key] = api
Example #2
0
    def _parse_rtn_paths(self, func, rtn, rtn_paths):
        for rtn_path in rtn_paths:
            if (not rtn_path.get_conds()) or (not rtn_path.get_calls()):
                continue

            for call in rtn_path.get_calls():
                callee = call.get_feature()
                if not self._is_valid(callee, func):
                    continue

                # get full func now
                callee = call.callname()
                rtn = errno_to_str(rtn)
                key = "%s on %s path" % (callee, rtn)
                api = self.apis.get(key, ExternAPI(callee, rtn))
                has_cond = False
                for cond in rtn_path.get_conds():
                    feature = cond.get_feature()
                    if feature.find(callee) != -1:
                        vrange = self._parse_ranges(cond.get_ranges())
                        api.add(func, vrange)
                        has_cond = True
                        break
                if not has_cond:
                    api.add(func, "")
                self.apis[key] = api
Example #3
0
    def _add_rtn_values(self, func, arg_list, current_paths, rtn_paths):
        # if the return value is a function
        # 1. find possible return values of this function
        # 2. append current RetPath to the list of all poosible return values
        # 3. append new RetPath to the current list
        #
        if func == "ERR_PTR":
            self._add_rtn_value(arg_list, current_paths, rtn_paths)
            return True

        new_rtn_paths = self.get_rtn_paths(func)
        if new_rtn_paths == None:
            sys.stderr.write("_expand_rtn_value: cannot find return paths for function: %s\n" % func)
            return False

        for rtn_value, new_paths in new_rtn_paths.iteritems():
            sys.stderr.write("_expand_rtn_value: expand return value (%s) from %s\n" % (rtn_value, func))
            # add current path
            rtn_value = errno_to_str(rtn_value)
            paths_list = rtn_paths.get(rtn_value, list())
            paths_list.extend(current_paths)
            rtn_paths[rtn_value] = paths_list
            # add new paths
            self._add_rtn_value(rtn_value, new_paths, rtn_paths)
        return True
Example #4
0
    def _add_rtn_values(self, func, arg_list, current_paths, rtn_paths):
        # if the return value is a function
        # 1. find possible return values of this function
        # 2. append current RetPath to the list of all poosible return values
        # 3. append new RetPath to the current list
        #
        if func == "ERR_PTR":
            self._add_rtn_value(arg_list, current_paths, rtn_paths)
            return True

        new_rtn_paths = self.get_rtn_paths(func)
        if new_rtn_paths == None:
            sys.stderr.write(
                "_expand_rtn_value: cannot find return paths for function: %s\n"
                % func)
            return False

        for rtn_value, new_paths in new_rtn_paths.iteritems():
            sys.stderr.write(
                "_expand_rtn_value: expand return value (%s) from %s\n" %
                (rtn_value, func))
            # add current path
            rtn_value = errno_to_str(rtn_value)
            paths_list = rtn_paths.get(rtn_value, list())
            paths_list.extend(current_paths)
            rtn_paths[rtn_value] = paths_list
            # add new paths
            self._add_rtn_value(rtn_value, new_paths, rtn_paths)
        return True
Example #5
0
    def _add_rtn_value(self, rtn_value, paths, rtn_paths):
        # normalize errno
        rtn_value = errno_to_str(rtn_value)

        # expand function invocation if possible
        paren_index = rtn_value.find('(')
        if paren_index > 1:
            rtn_func = rtn_value[0:paren_index]
            arg_list = rtn_value[paren_index+1:-1]
            if self._add_rtn_values(rtn_func, arg_list, paths, rtn_paths):
                return
        # if not a function or expand fails
        paths_list = rtn_paths.get(rtn_value, list())
        paths_list.extend(paths)
        rtn_paths[rtn_value] = paths_list
Example #6
0
    def _add_rtn_value(self, rtn_value, paths, rtn_paths):
        # normalize errno
        rtn_value = errno_to_str(rtn_value)

        # expand function invocation if possible
        paren_index = rtn_value.find('(')
        if paren_index > 1:
            rtn_func = rtn_value[0:paren_index]
            arg_list = rtn_value[paren_index + 1:-1]
            if self._add_rtn_values(rtn_func, arg_list, paths, rtn_paths):
                return
        # if not a function or expand fails
        paths_list = rtn_paths.get(rtn_value, list())
        paths_list.extend(paths)
        rtn_paths[rtn_value] = paths_list
Example #7
0
 def report(self, report_all = True):
     print("%s[C] [%7s] [%.6s] [%23s] [%s]%s"% \
           (Color.HEADER,\
            "Ranking", "Distance", "Funtion", "Missing Conditions", \
            Color.ENDC))
     for (ranking, result) in enumerate(self.results):
         distance = result[0]
         cv = result[1]
         if not report_all and distance <= self.avg_distance:
             break
         (cc, ac, l) = self._get_color_code(result)
         delta = distance - self.avg_distance
         print("%s[%s]  %7s   %.6s   %23s   %s%s"% \
               (cc, ac, \
                ranking+1, delta, \
                ''.join((cv.get_func_name(), \
                         ':', \
                         errno_to_str(cv.get_rtn()))), \
                Color.ENDC, \
                cv.get_missing_conditions(delta * 0.7)))
     print("")
Example #8
0
 def get_rtn_values(self):
     rtn_values = []
     for rv in self.rtn_dic.keys():
         rtn_values.append( errno_to_str(rv) )
     return rtn_values